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

linld: fix vcpi case
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Dec 26 17:19:46 2021 +0000 (2021-12-26)
parents 530dacfd6585
children c11594098e34
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
11 include "himem.inc"
12 include "isostate.inc"
14 CMDNUMCNT = 5
15 ifdef CPUTYPE
16 CMDNUMCNT = CMDNUMCNT+1
17 endif
18 ifdef QUICK_BOOT
19 CMDNUMCNT = CMDNUMCNT+2
20 endif
22 macro alloc_isostate
23 public _isostate
24 _isostate isostate <?>
25 org $-ISOSTATE_OVERLAP
26 endm
28 macro alloc_image
29 rm_size dw ? ; _imgs-4
30 rm_buf dw ? ; _imgs-2
31 global _imgs:byte
32 label _imgs byte
33 img_kernel image_himem ?
34 img_initrd image_himem ?
35 endm
37 macro alloc_cmdnum
38 global _cmdnum:word
39 label _cmdnum word
40 dd CMDNUMCNT dup(?)
41 endm
43 p8086
45 group DGROUP _TEXT,_DATA,_BSS
46 assume cs:DGROUP,ds:DGROUP
48 segment _TEXT byte public use16 'CODE'
49 ends _TEXT
51 segment _DATA byte public use16 'DATA'
52 ;global _data_start:byte
53 label _data_start byte
54 ifndef NO386
55 msg_badcpu db "I need a 386+ in real mode w/o paging"
56 ifdef VCPI
57 db " or "
58 msg_badmapping db "under VCPI 4.0+ manager with low 640k 1:1 mapping"
59 global _vcpi:byte
60 endif
61 _vcpi db 0
62 endif
64 ends _DATA
66 segment _BSS byte public use16 'BSS'
68 ifdef ISO9660
69 ifndef VCPI
70 alloc_isotate
71 else
72 room_for_isostate = 1
73 endif
74 endif
76 ifdef ISOHOOK
77 extrn _big_cmdline:byte
78 db 254 dup(?)
79 endif
80 ;global _bss_start:byte
81 label _bss_start byte
82 global stktop:byte
83 ifdef CPUTYPE
84 global _cputype:word
85 _cputype dw ?
86 endif
87 global _cpu386:byte
88 _cpu386 db ?
89 ifdef CPU64
90 org $-1
91 global _cpu_features:dword
92 _cpu_features dd ?
93 room_for_image = 1
94 else
95 alloc_image
96 endif
98 ;BSS_OVERLAP_BOOT = 1
100 ifndef BSS_OVERLAP_BOOT
102 ifdef room_for_isostate
103 alloc_isostate
104 endif
106 ifdef room_for_image
107 alloc_image
108 endif
110 alloc_cmdnum
112 endif
114 ends _BSS
116 segment _TEXT byte public use16 'CODE'
118 macro cpuid
119 db 0fh,0A2h
120 endm
122 org 100h
123 ;global _text_start:byte
124 label _text_start byte
126 ;***************************************************************
127 ; clear bss
128 ;***************************************************************
129 mov sp,offset stktop
130 mov bx, 0F000h ; cld ; cli & empty string
131 mov si,offset _bss_start
132 clearbss:
133 mov [si],bl ; clear bss + heap
134 inc si
135 jne clearbss
137 ;***************************************************************
138 ; check CPU
139 ;***************************************************************
141 ; Check for oldies
142 ifdef CPUTYPE
143 mov ax,bx
144 mov cl,32+7 ; 186+ masks with 31
145 shr ah,cl
146 endif
147 push bx ; < 286 : flags[12..15] are forced 1
148 popf ; = 286 : flags[12..15] are forced 0, cld, cli
149 pushf ; > 286 : only flags[15] is forced 0
150 pop dx
151 add dh,bh ; 160:NS=386+, 0F0:NC=286, 1E0:PO=86/186
152 ifndef NO386
153 mov bx,offset msg_badcpu
154 js godie ;it is not a 386+, die
155 else
156 ifdef CPUTYPE
157 jc not286
158 mov ah,2
159 not286:
160 js jmp_endcpu86 ;it is not a 386+, try ELKS & co
161 else
162 js endcpu86 ;it is not a 386+, try ELKS & co
163 endif
164 endif
165 p386
166 ifdef VCPI
167 mov edx,cs
168 shl edx,4 ; edx for prepare_vcpi (edx[31-20]=0) [1]
169 else
170 ifndef LARGE_ZIMAGE
171 mov edx,cs
172 shl edx,4 ; edx for memcpy32 (edx[31-20]=0) [1]
173 endif
174 endif
175 ifndef LARGE_ZIMAGE
176 extrn gdt_base_memcpy:word ; gdt_base for memcpy32
177 add [dword gdt_base_memcpy],edx
178 endif
180 ; Check for vm
181 smsw bx ;SMSW cannot be trapped! :-)
182 shr bx,1 ;MSW_PE
183 ; We're in vm
184 jc check_vcpi
186 check_rm_paging:
187 ; It's a 386 in real mode, chk for paging (crazy but possible)
188 mov ebx,cr0
189 inc ebx ;CR0_PG to S
190 jns endcpu386
191 ifndef NO386
192 p8086
193 extrn die:near
194 godie:
195 call near die
196 else
197 jmp_endcpu86:
198 jmp endcpu86 ;386+ rm will fake 186+
199 endif
202 ;***************************************************************
203 ; checks for vcpi
204 ;***************************************************************
205 label check_vcpi near
206 p386
207 ifdef VCPI
208 mov ah,0DEh ; check for vcpi present
209 int 67h
210 or ah,ah
211 jnz no_vcpi
212 is386vcpi:
213 extrn prepare_vcpi:near
214 call prepare_vcpi ; assume ES = DS
215 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
216 ;extrn _get_vcpi_interface:near
217 ;call _get_vcpi_interface
218 ifndef NO386
219 mov bx,offset msg_badmapping
220 jnz no_vcpi
221 dec [byte bx+_vcpi-msg_badmapping]
222 else
223 jnz no_vcpi
224 extrn _vcpi:byte
225 dec [byte _vcpi]
226 endif
227 endif
228 no_vcpi:
229 endcpu386:
230 ifdef CPU64
231 pushfd
232 pop dx
233 pop ax
234 ifdef CPUTYPE
235 xor al,24h ; toggle CPUID feature bit & AC bit
236 else
237 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
238 endif
239 push ax ; (toggle AC: bit 18 => 486+)
240 push dx
241 popfd
242 pushfd
243 pop dx
244 pop dx
245 xor al,dl ; clear C; 00=P5+=PE+Z 20=486=PO 24=386=PE
246 ifdef CPUTYPE
247 ifndef VCPI
248 ifdef LARGE_ZIMAGE
249 cdq ; 386 and 486 are not 64 bits
250 endif
251 endif
252 mov ax,0400h
253 jpo is486
254 mov ah,3
255 is486:
256 jne set_cputype ; edx[31-20]=0 see [1]; edx.26=lm=0
257 xchg ax,si ; si=0300h
258 basicCPUID:
259 xor eax,eax
260 inc ax
261 cpuid ; Basic cpuid (late 486 or Pentium)
262 inc si
263 jpo basicCPUID ; again cause of Nasty EMM386s
264 push eax
265 shr edx,1+26 ; test bit 26 (sse2), clear bit 29 (avoid tm/lm confusion)
266 jnc baseInfo
267 else
268 jne @@no_cpuid ; CPUID feature bit changed ?
269 endif
270 mov eax,80000001h ; Extended Processor Info and Feature Bits (Pentium 4 or newer)
271 cpuid ; Extended cpuid (Pentium 4)
272 ifdef CPUTYPE
273 baseInfo:
274 pop ax ; base FamilyID[11-8] & base ModelID[7-4]
275 pop bx ; extended FamilyID[11-4] & extended ModelID[3-0]
276 mov cx,0F04h
277 and ah,ch
278 and bh,ch
279 rol bx,cl ; extended FamilyID in bh, extended ModelID in bl[7-4]
280 shr al,cl ; set base ModelID
281 cmp ah,ch
282 jz SetModelID
283 cmp ah,06h
284 jnz ModelIDset
285 mov bh,0 ; remove extended FamilyID
286 SetModelID:
287 add ax,bx ; use extended FamilyID & extended ModelID
288 ModelIDset:
289 set_cputype:
290 endif
291 mov dl,-1 ; set 386 flag
292 ifdef NO386
293 db 66h ; mov [_cpu_features],edx
294 @@no_cpuid:
295 mov [word _cpu_features],dx ; dl != 0
296 else
297 mov [_cpu_features],edx
298 @@no_cpuid:
299 endif
300 else
301 dec [_cpu386]
302 endif
303 endcpu86:
304 ifdef CPUTYPE
305 mov [_cputype],ax ; _cputype: FFMM or 0[1-4]00=80[1-4]86 or 0000=8086/8088
306 endif
307 p8086
309 ;***************************************************************
310 ; build argv & argc
311 ;***************************************************************
312 mov si,80h
313 ifdef ISOHOOK
314 mov bx,offset _big_cmdline
315 cmp [byte si],2
316 jnb @@user_args
317 call @set_cmdline$qpxzc
318 @@user_args:
319 endif
320 lodsb ; size 0..127
321 cbw
322 ifdef ISOHOOK
323 inc ax
324 jnz short_cmdline
325 mov si,bx
326 lodsb ; size 0..254
327 short_cmdline:
328 dec ax
329 endif
330 xchg ax,bx
331 mov [bx+si],bh ; set eos
333 ;***************************************************************
335 ifdef BSS_OVERLAP_BOOT
336 mov di,offset clean-100h
338 org $-(CMDNUMCNT*4) ; alloc_cmdnum
340 ifdef room_for_image
341 org $-2-2-(2*size image_himem) ; alloc_image
342 endif
344 ifdef room_for_isostate
345 org $+ISOSTATE_OVERLAP-size isostate
346 alloc_isostate
347 endif
349 ifdef room_for_image
350 alloc_image
351 endif
353 alloc_cmdnum
354 clean:
355 mov [di+0FFh],bh
356 dec di
357 jnz clean
358 endif
360 org $-4 ; _himem_buf
361 global _himem_buf:dword
362 _himem_buf dd ?
364 ;***************************************************************
365 extrn _bss_end:word
366 mov di,offset _bss_end
367 global _heap_top
368 org $-2
369 _heap_top dw ?
370 ;xor dx,dx
371 ;push dx ; envp (already cleared)
372 ;mov [word di],dx ; argv[0] = 0 (idem)
373 argbuild:
374 mov bx,2 ; argc * 2
375 argeos:
376 mov cx,1 ; look for a start of string
377 mov [byte si-1],bh ; mark eos
378 mov ah,20h ; space will be eos
379 arglp:
380 lodsb
381 cmp al,0h
382 je argdone
383 cmp al,20h
384 jb argeos
385 cmp al,ah
386 je argeos
387 cmp al,27h
388 je isargstr
389 cmp al,22h
390 je isargstr
391 jcxz arglp ; not start of string
392 dec si
393 ;jmp newarg
394 db 0BAh ; mov dx,im opcode
395 isargstr:
396 mov ah,al ; expected eos
397 newarg:
398 mov [word bx+di],si ; argv[argc++] = si
399 inc bx
400 inc bx
401 dec cx
402 jmp arglp
404 ;***************************************************************
405 ;_fastcall void set_cmdline(bx:const char *filename);
406 ;***************************************************************
407 global @set_cmdline$qpxzc:near
408 proc @set_cmdline$qpxzc near
409 extrn openargs:near
410 call openargs
411 jc @ret
412 mov ch,15 ; cx<4096
413 mov di,[_heap_top]
414 jmp read_cmdline ; read_cmdline(ax,di,cx)
416 endp @set_cmdline$qpxzc
418 ifdef NO386
419 ;***************************************************************
420 ;u16 topseg();
421 ;***************************************************************
422 global _topseg:near
423 proc _topseg near
425 int 12h
426 jnc @@max640k
427 mov ax,640 ; 640k => 9000h
428 @@max640k:
429 dec ax
430 and al,0C0h
431 mov cl,6
432 shl ax,cl
433 @ret:
434 ret
436 endp _topseg
437 else
438 @ret:
439 ret
440 endif
442 ;***************************************************************
443 argdone:
444 ;mov [word bx+di],0 ; argv[argc] = 0
445 lea ax,[bx+di+2]
446 mov [_heap_top],ax
447 ;push di ; argv
448 ;shr bx,1
449 ;push bx ; argc
450 ifndef filearg
451 mov bx,[di+2] ; argv[1]
452 extrn openargs:near
453 call near openargs
454 jc argend
455 ;pop bx ; trash argc, argv >> 1Kb !
456 ;pop cx ; sizemax=argv
457 dec cx ; sizemax=0ffffh
458 read_cmdline:
459 mov dx,di
460 push dx
461 xchg ax,bx
462 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
463 call near @read$cxdxbx
464 pop si ; si=buffer=argv
465 add di,ax
466 ifndef NO_CLOSE
467 extrn close:near
468 call near close
469 endif
470 jmp argbuild
471 argend:
472 endif
474 ;***************************************************************
475 ; extrn _main:near
476 ; call _main
477 ;never return
479 ;***************************************************************
482 ends _TEXT
485 end _text_start
487 ;###### END OF FILE ############################################