wok view linld/stuff/src/_BEG.ASM @ rev 20427

linld: remove dead code
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 14 22:18:05 2018 +0200 (2018-08-14)
parents c0625ff5d49b
children bcdfc23ee041
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p8086
10 group DGROUP _TEXT,_DATA,_BSS
11 assume cs:DGROUP,ds:DGROUP
13 segment _TEXT byte public use16 'CODE'
15 macro cpuid
16 db 0fh,0A2h
17 endm
19 org 100h
20 global _text_start:byte
21 label _text_start byte
23 ;***************************************************************
24 ; clear bss
25 ;***************************************************************
26 mov si,offset _bss_start
27 clearbss:
28 mov [byte si],0 ; clear bss + heap + sp
29 inc si
30 jne clearbss
31 cld
33 ;***************************************************************
34 ; check CPU
35 ;***************************************************************
37 ; Check for oldies
38 ifndef EXTRA
39 push sp
40 pop ax
41 sub ax,sp
42 ifndef NO386
43 mov bx,offset msg_badcpu
44 jnz no_vcpi ;it is a 86/186 not a 286+
45 else
46 jnz endcpu ;it is a 86/186 not a 286+
47 endif
48 else
49 pushf
50 mov bh, 0F0h
51 push bx ; < 286 : flags[12..15] are forced 1
52 popf ; = 286 : flags[12..15] are forced 0
53 pushf ; > 286 : only flags[15] is forced 0
54 pop dx
55 popf
56 add dh,bh ; NS=386+, NC=286
57 ifndef NO386
58 mov bx,offset msg_badcpu
59 js no_vcpi ;it is not a 386+
60 else
61 js endcpu ;it is not a 386+
62 endif
63 endif
64 p386
65 ifdef EXTRA
66 pushfd
67 pop dx
68 pop ax
69 mov bl,al
70 xor al,20h ; toggle CPUID feature bit 21
71 push ax
72 push dx
73 popfd
74 pushfd
75 pop dx
76 pop ax
77 xor al,bl ; clear C
78 je @@check_vm ; CPUID feature bit changed ?
79 mov eax,80000001h ; Extended Processor Info and Feature Bits
80 cpuid
81 mov [_cpu_features],edx
82 @@check_vm:
83 endif
84 ; Check for vm
85 smsw ax ;SMSW cannot be trapped! :-)
86 and al,1 ;MSW_PE
87 ; We're in vm
88 jz check_rm_paging
90 ;***************************************************************
91 ; checks for vcpi
92 ;***************************************************************
93 label check_vcpi near
94 push ds
95 ; Check whether it is safe to call 67h (we trust only known EMM managers)
96 push si
97 pop ds
98 mov ds,[word 67h*4+2]
99 cmp [dword si+10+4],'0XXX'
100 jne skip
101 ;mov eax,'XMME'
102 ;xor eax,[dword si+10]
103 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
104 ;shl eax,8
105 mov ax,'ME'
106 xor ax,[word si+10]
107 skip:
108 pop ds
109 jne no_vcpi
111 ; Check emm manager status and version
112 ;mov ah,40h ; get status
113 ;int 67h
114 ;test ah,ah
115 ;jnz no_vcpi
116 mov ah,46h ; get version
117 int 67h
118 test ah,ah
119 jnz no_vcpi
120 cmp al,40h ; version must be >= 4.0
121 jb no_vcpi
122 ; Check vcpi manager status
123 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
124 ;;mov bx,4
125 ;;int 67h
126 ;;test ah,ah
127 ;;jnz no_vcpi
128 ;;push dx ;$ save handle
129 mov ax,0DE00h ; check for vcpi present
130 int 67h
131 test ah,ah
132 jnz no_vcpi
133 is386vcpi:
134 inc [_vcpi]
135 extrn prepare_vcpi:near
136 call prepare_vcpi
137 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
138 ;extrn _get_vcpi_interface:near
139 ;call _get_vcpi_interface
140 mov bx,offset msg_badmapping
141 jz endcpu
142 no_vcpi:
143 p8086
144 ;;pop dx ;$ handle
145 ;;mov ax,4500h ; DEALLOCATE PAGES
146 ;;int 67h
147 extrn die:near
148 godie:
149 call near die
150 check_rm_paging:
151 ; It's a 386 in real mode, chk for paging (crazy but possible)
152 p386
153 mov eax,cr0
154 inc eax ;CR0_PG to S
155 js no_vcpi
156 endcpu:
157 p8086
159 ;***************************************************************
160 ; build argv & argc
161 ;***************************************************************
162 extrn _heap_top:word
163 mov di,[_heap_top]
164 ;xor ax,ax
165 ;push ax ; envp (already cleared)
166 ;mov [word di],ax ; argv[0] = 0 (idem)
167 mov si,80h
168 lodsb
169 cmp al,7Eh
170 jbe alok
171 mov al,7Eh
172 alok:
173 cbw
174 xchg ax,bx
175 mov [bx+si],bh ; set eos
176 argbuild:
177 ifdef DEBUG
178 p386
179 pusha
180 mov bx,si
181 extrn puts:near
182 call puts
183 popa
184 endif
185 mov bx,2 ; argc * 2
186 argeos:
187 mov dl,1 ; look for a start of string
188 mov [byte si-1],bh ; mark eos
189 mov ah,20h ; space will be eos
190 arglp:
191 lodsb
192 cmp al,0h
193 je argdone
194 cmp al,20h
195 jb argeos
196 cmp al,ah
197 je argeos
198 cmp al,27h
199 je isargstr
200 cmp al,22h
201 je isargstr
202 or dl,dl
203 je arglp ; not start of string
204 dec si
205 ;jmp newarg
206 db 0B9h ; mov cx,im opcode
207 isargstr:
208 mov ah,al ; expected eos
209 newarg:
210 mov [word bx+di],si ; argv[argc++] = si
211 inc bx
212 inc bx
213 dec dx
214 jmp arglp
215 argdone:
216 ;mov [word bx+di],0 ; argv[argc] = 0
217 lea ax,[bx+di+2]
218 mov [_heap_top],ax
219 push di ; argv
220 shr bx,1
221 push bx ; argc
222 ifndef filearg
223 mov bx,[di+2] ; argv[1]
224 cmp [byte bx],'@'
225 jne argend
226 inc bx
227 extrn open:near
228 call near open
229 jc argend
230 pop bx ; trash argc, argv >> 1Kb !
231 global read_cmdline:near
232 read_cmdline:
233 push di
234 push ax
235 extrn _read:near
236 call near _read
237 pop bx ; fd for close
238 pop si ; si=buffer=argv
239 add di,ax
240 pop ax ; trash sizemax=argv
241 extrn close:near
242 call near close
243 jmp argbuild
244 argend:
245 endif
247 ;***************************************************************
248 extrn _main:near
249 call _main
251 ;***************************************************************
252 global exit:near
253 exit:
254 mov ah,4Ch
255 int 21h
256 ends _TEXT
258 segment _DATA byte public use16 'DATA'
259 global _data_start:byte
260 label _data_start byte
261 ifndef NO386
262 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
263 endif
264 global _vcpi:byte
265 _vcpi db 0
266 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
268 ends _DATA
270 segment _BSS byte public use16 'BSS'
271 global _bss_start:byte
272 label _bss_start byte
273 ifdef EXTRA
274 global _cpu_features:dword
275 _cpu_features dd ?
276 endif
277 ends _BSS
279 end _text_start
281 ;###### END OF FILE ############################################