wok view linld/stuff/src/_BEG.ASM @ rev 23980
linld: fix isoboot/cpuhaslm
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Nov 20 11:26:49 2020 +0000 (2020-11-20) |
parents | 56ee356284c6 |
children | fc88d0826de4 |
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 p8086
11 group DGROUP _TEXT,_DATA,_BSS
12 assume cs:DGROUP,ds:DGROUP
14 segment _TEXT byte public use16 'CODE'
15 ends _TEXT
17 segment _DATA byte public use16 'DATA'
18 global _data_start:byte
19 label _data_start byte
20 ifndef NO386
21 msg_badcpu db "I need 386+ CPU in real mode w/o paging"
22 db " or "
23 msg_badmapping db "under VCPI 4.0+ manager with low 640k 1:1 mapping"
24 global _vcpi:byte
25 _vcpi db 0
26 endif
28 ends _DATA
30 segment _BSS byte public use16 'BSS'
32 global _bss_start:byte
33 label _bss_start byte
34 global stktop:byte
35 ifndef ISOHOOK
36 ifdef NO386
37 global _cpu386:byte
38 _cpu386 db ?
39 org $-1
40 endif
41 global _cpu_features:dword
42 _cpu_features dd ?
43 endif
44 ends _BSS
46 segment _TEXT byte public use16 'CODE'
48 macro cpuid
49 db 0fh,0A2h
50 endm
52 org 100h
53 global _text_start:byte
54 label _text_start byte
56 ;***************************************************************
57 ; clear bss
58 ;***************************************************************
59 mov sp,offset stktop
60 mov si,offset _bss_start
61 mov bx, 0F000h ; cld ; cli & empty string
62 clearbss:
63 mov [si],bl ; clear bss + heap
64 inc si
65 ifdef ISOHOOK
66 cmp si,bx
67 endif
68 jne clearbss
70 ;***************************************************************
71 ; check CPU
72 ;***************************************************************
74 ; Check for oldies
75 push bx ; < 286 : flags[12..15] are forced 1
76 popf ; = 286 : flags[12..15] are forced 0
77 pushf ; > 286 : only flags[15] is forced 0
78 pop dx
79 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
80 ifndef NO386
81 mov bx,offset msg_badcpu
82 js godie ;it is not a 386+, die
83 else
84 js endcpu86 ;it is not a 386+, try ELKS & co
85 endif
86 p386
87 ; Check for vm
88 smsw ax ;SMSW cannot be trapped! :-)
89 and al,1 ;MSW_PE
90 ; We're in vm
91 jnz check_vcpi
93 check_rm_paging:
94 ; It's a 386 in real mode, chk for paging (crazy but possible)
95 mov eax,cr0
96 inc eax ;CR0_PG to S
97 jns endcpu386
98 ifndef NO386
99 p8086
100 extrn die:near
101 godie:
102 no_vcpi:
103 call near die
104 else
105 jmp endcpu86
106 endif
108 ifdef ISOHOOK
109 extrn @ret:near
110 global iso_open_hack
111 iso_open_hack dw @ret
112 global iso_read_hack
113 iso_read_hack dw @ret
114 global iso_lseek_hack
115 iso_lseek_hack dw @ret
116 global iso_close_hack
117 iso_close_hack dw @ret
118 global iso_cleanup_hack
119 iso_cleanup_hack dw @ret
120 global _cpu_features:dword
121 _cpu_features dd ? ; default _cpu_features+3=1Fh/8Eh (bit5=0, not 64bits)
122 org $-4
123 ifdef NO386
124 global _cpu386:byte
125 _cpu386 db 0
126 endif
127 endif
129 ;***************************************************************
130 ; checks for vcpi
131 ;***************************************************************
132 label check_vcpi near
133 p386
134 push ds
135 ; Check whether it is safe to call 67h (we trust only known EMM managers)
136 push si
137 pop ds
138 mov ds,[word 67h*4+2]
139 cmp [dword si+10+4],'0XXX'
140 jne skip
141 ;mov eax,'XMME'
142 ;xor eax,[dword si+10]
143 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
144 ;shl eax,8
145 mov ax,'ME'
146 xor ax,[word si+10]
147 skip:
148 pop ds
149 jne no_vcpi
151 ; Check emm manager status and version
152 ;mov ah,40h ; get status
153 ;int 67h
154 ;inc ax
155 ;js no_vcpi
156 mov ah,46h ; get version
157 int 67h
158 cmp ax,40h ; version must be >= 4.0
159 jl no_vcpi ; btw check ax.15
160 ; Check vcpi manager status
161 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
162 ;;mov bx,4
163 ;;int 67h
164 ;;inc ax
165 ;;js no_vcpi
166 ;;push dx ;$ save handle
167 mov ax,0DE00h ; check for vcpi present
168 int 67h
169 test ah,ah
170 jnz no_vcpi
171 is386vcpi:
172 extrn prepare_vcpi:near
173 call prepare_vcpi
174 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
175 ;extrn _get_vcpi_interface:near
176 ;call _get_vcpi_interface
177 ifndef NO386
178 mov bx,offset msg_badmapping
179 jnz no_vcpi
180 dec [byte bx+_vcpi-msg_badmapping]
181 else
182 jnz no_vcpi
183 extrn _vcpi:byte
184 dec [byte _vcpi]
185 endif
186 endcpu386:
187 pushfd
188 pop dx
189 pop ax
190 mov bl,al
191 xor al,20h ; toggle CPUID feature bit 21
192 push ax
193 push dx
194 popfd
195 pushfd
196 pop dx ; dx.1=flags.1=1
197 pop ax
198 xor al,bl ; clear C
199 je @@no_cpuid ; CPUID feature bit changed ?
200 mov eax,80000001h ; Extended Processor Info and Feature Bits
201 cpuid
202 ifdef NO386
203 mov dl,-1 ; set 386 flag
204 db 66h ; mov [_cpu_features],edx
205 @@no_cpuid:
206 mov [word _cpu_features],dx ; dl != 0
207 no_vcpi:
208 else
209 mov [_cpu_features],edx
210 @@no_cpuid:
211 endif
212 endcpu86:
213 p8086
215 ;***************************************************************
216 ; build argv & argc
217 ;***************************************************************
218 extrn _bss_end:word
219 mov di,offset _bss_end
220 global _heap_top
221 org $-2
222 _heap_top dw ?
223 ;xor ax,ax
224 ;push ax ; envp (already cleared)
225 ;mov [word di],ax ; argv[0] = 0 (idem)
226 mov si,80h
227 lodsb
228 cmp al,7Eh
229 jbe alok
230 mov al,7Eh
231 alok:
232 cbw
233 xchg ax,bx
234 mov [bx+si],bh ; set eos
235 argbuild:
236 ifdef DEBUG
237 p386
238 pusha
239 mov bx,si
240 extrn puts:near
241 call puts
242 popa
243 endif
244 mov bx,2 ; argc * 2
245 argeos:
246 mov cx,1 ; look for a start of string
247 mov [byte si-1],bh ; mark eos
248 mov ah,20h ; space will be eos
249 arglp:
250 lodsb
251 cmp al,0h
252 je argdone
253 cmp al,20h
254 jb argeos
255 cmp al,ah
256 je argeos
257 cmp al,27h
258 je isargstr
259 cmp al,22h
260 je isargstr
261 jcxz arglp ; not start of string
262 dec si
263 ;jmp newarg
264 db 0BAh ; mov dx,im opcode
265 isargstr:
266 mov ah,al ; expected eos
267 newarg:
268 mov [word bx+di],si ; argv[argc++] = si
269 inc bx
270 inc bx
271 dec cx
272 jmp arglp
273 argdone:
274 ;mov [word bx+di],0 ; argv[argc] = 0
275 lea ax,[bx+di+2]
276 mov [_heap_top],ax
277 push di ; argv
278 shr bx,1
279 push bx ; argc
280 ifndef filearg
281 mov bx,[di+2] ; argv[1]
282 extrn openargs:near
283 call near openargs
284 jc argend
285 pop bx ; trash argc, argv >> 1Kb !
286 global read_cmdline:near
287 pop cx ; sizemax=argv
288 read_cmdline:
289 mov dx,di
290 push dx
291 push ax
292 xchg ax,bx
293 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
294 call near @read$cxdxbx
295 pop bx ; fd for close
296 pop si ; si=buffer=argv
297 add di,ax
298 extrn close:near
299 call near close
300 jmp argbuild
301 argend:
302 endif
304 ;***************************************************************
305 extrn _main:near
306 call _main
307 ;never return
309 ;***************************************************************
311 ends _TEXT
314 end _text_start
316 ;###### END OF FILE ############################################