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

Add some current_version
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 08 09:18:48 2021 +0000 (2021-07-08)
parents 06547d8cf241
children ffa068512f60
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 ifndef NO386
143 ifdef CPUTYPE
144 mov ax,100h
145 mov cl,32 ; 186+ masks with 31
146 shr ax,cl
147 endif
148 endif
149 push bx ; < 286 : flags[12..15] are forced 1
150 popf ; = 286 : flags[12..15] are forced 0, cld, cli
151 pushf ; > 286 : only flags[15] is forced 0
152 pop dx
153 add dh,bh ; 160:NS=386+, 0F0:NC=286, 1E0:NP=86/186
154 ifndef NO386
155 mov bx,offset msg_badcpu
156 js godie ;it is not a 386+, die
157 else
158 ifdef CPUTYPE
159 jc not286
160 mov ah,2
161 not286:
162 js jmp_endcpu86 ;it is not a 386+, try ELKS & co
163 else
164 js endcpu86 ;it is not a 386+, try ELKS & co
165 endif
166 endif
167 p386
168 ifdef VCPI
169 mov edx,cs
170 shl edx,4 ; edx for prepare_vcpi (edx[31-20]=0)
171 else
172 ifndef LARGE_ZIMAGE
173 mov edx,cs
174 shl edx,4 ; edx for memcpy32 (edx[31-20]=0)
175 endif
176 endif
177 ifndef LARGE_ZIMAGE
178 extrn gdt_base_memcpy:word ; gdt_base for memcpy32
179 add [dword gdt_base_memcpy],edx
180 endif
182 ; Check for vm
183 smsw bx ;SMSW cannot be trapped! :-)
184 shr bx,1 ;MSW_PE
185 ; We're in vm
186 jnc check_vcpi
188 check_rm_paging:
189 ; It's a 386 in real mode, chk for paging (crazy but possible)
190 mov ebx,cr0
191 inc ebx ;CR0_PG to S
192 jns endcpu386
193 ifndef NO386
194 p8086
195 extrn die:near
196 godie:
197 call near die
198 else
199 jmp_endcpu86:
200 jmp endcpu86
201 endif
204 ;***************************************************************
205 ; checks for vcpi
206 ;***************************************************************
207 label check_vcpi near
208 p386
209 ifdef VCPI
210 ; Check whether it is safe to call 67h
211 xor eax,eax
212 push ds
213 mov ds,ax
214 cmp [dword 67h*4],eax
215 pop ds
216 je no_vcpi
217 mov ah,0DEh ; check for vcpi present
218 int 67h
219 or ah,ah
220 jnz no_vcpi
221 is386vcpi:
222 extrn prepare_vcpi:near
223 call prepare_vcpi
224 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
225 ;extrn _get_vcpi_interface:near
226 ;call _get_vcpi_interface
227 ifndef NO386
228 mov bx,offset msg_badmapping
229 jnz no_vcpi
230 dec [byte bx+_vcpi-msg_badmapping]
231 else
232 jnz no_vcpi
233 extrn _vcpi:byte
234 dec [byte _vcpi]
235 endif
236 endif
237 no_vcpi:
238 endcpu386:
239 ifdef CPU64
240 pushfd
241 pop dx
242 pop ax
243 ifdef CPUTYPE
244 xor al,24h ; toggle CPUID feature bit & AC bit
245 else
246 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
247 endif
248 push ax ; (toggle AC: bit 18 => 486+)
249 push dx
250 popfd
251 pushfd
252 pop dx
253 pop dx
254 xor al,dl ; clear C
255 ifdef CPUTYPE
256 ifndef VCPI
257 ifdef LARGE_ZIMAGE
258 cdq ; 386 and 486 are not 64 bits
259 endif
260 endif
261 cmp al,20h
262 mov ax,0400h
263 je is486
264 mov ah,3
265 is486:
266 jae set_cputype
267 xor eax,eax
268 inc ax
269 cpuid ; Basic cpuid (late 486 or Pentium)
270 xor eax,eax
271 inc ax
272 cpuid ; again cause of Nasty EMM386s
273 push eax
274 bt edx,26 ; sse2 bit
275 jnc baseInfo
276 else
277 jne @@no_cpuid ; CPUID feature bit changed ?
278 endif
279 mov eax,80000001h ; Extended Processor Info and Feature Bits (Pentium 4 or newer)
280 cpuid ; Extended cpuid (Pentium 4)
281 ifdef CPUTYPE
282 baseInfo:
283 pop ax ; base IDs
284 and ax,0FF0h ; keep FamilyID & ModelID
285 pop cx ; extended IDs
286 mov bx,cx
287 shr bx,4 ; extended FamilyID in bl
288 shr al,4 ; set base ModelID
289 cmp ah,0Fh
290 jz SetModelID
291 cmp ah,06h
292 jnz ModelIDset
293 db 3Dh ; cmp ax,0DC00h
294 SetModelID:
295 add ah,bl ; use extended FamilyID
296 shl cl,4
297 or al,cl ; use extended ModelID
298 ModelIDset:
299 set_cputype:
300 endif
301 mov dl,-1 ; set 386 flag
302 ifdef NO386
303 db 66h ; mov [_cpu_features],edx
304 @@no_cpuid:
305 mov [word _cpu_features],dx ; dl != 0
306 else
307 mov [_cpu_features],edx
308 @@no_cpuid:
309 endif
310 else
311 dec [_cpu386]
312 endif
313 endcpu86:
314 ifdef CPUTYPE
315 mov [_cputype],ax ; _cputype: FFMM or 0[1-4]00=80[1-4]86 or 0000=8086/8088
316 endif
317 p8086
319 ;***************************************************************
320 ; build argv & argc
321 ;***************************************************************
322 mov si,80h
323 ifdef ISOHOOK
324 mov bx,offset _big_cmdline
325 cmp [byte si],2
326 jnb @@user_args
327 call @set_cmdline$qpxzc
328 @@user_args:
329 endif
330 lodsb ; size 0..127
331 cbw
332 ifdef ISOHOOK
333 inc ax
334 jnz short_cmdline
335 mov si,bx
336 lodsb ; size 0..254
337 short_cmdline:
338 dec ax
339 endif
340 xchg ax,bx
341 mov [bx+si],bh ; set eos
343 ;***************************************************************
345 ifdef BSS_OVERLAP_BOOT
346 mov di,offset clean-100h
348 org $-(CMDNUMCNT*4) ; alloc_cmdnum
350 ifdef room_for_image
351 org $-2-2-(2*size image_himem) ; alloc_image
352 endif
354 ifdef room_for_isostate
355 org $+ISOSTATE_OVERLAP-size isostate
356 alloc_isostate
357 endif
359 ifdef room_for_image
360 alloc_image
361 endif
363 alloc_cmdnum
364 clean:
365 mov [di+0FFh],bh
366 dec di
367 jnz clean
368 endif
370 org $-4 ; _himem_buf
371 global _himem_buf:dword
372 _himem_buf dd ?
374 ;***************************************************************
375 extrn _bss_end:word
376 mov di,offset _bss_end
377 global _heap_top
378 org $-2
379 _heap_top dw ?
380 ;xor dx,dx
381 ;push dx ; envp (already cleared)
382 ;mov [word di],dx ; argv[0] = 0 (idem)
383 argbuild:
384 mov bx,2 ; argc * 2
385 argeos:
386 mov cx,1 ; look for a start of string
387 mov [byte si-1],bh ; mark eos
388 mov ah,20h ; space will be eos
389 arglp:
390 lodsb
391 cmp al,0h
392 je argdone
393 cmp al,20h
394 jb argeos
395 cmp al,ah
396 je argeos
397 cmp al,27h
398 je isargstr
399 cmp al,22h
400 je isargstr
401 jcxz arglp ; not start of string
402 dec si
403 ;jmp newarg
404 db 0BAh ; mov dx,im opcode
405 isargstr:
406 mov ah,al ; expected eos
407 newarg:
408 mov [word bx+di],si ; argv[argc++] = si
409 inc bx
410 inc bx
411 dec cx
412 jmp arglp
414 ;***************************************************************
415 ;_fastcall void set_cmdline(bx:const char *filename);
416 ;***************************************************************
417 global @set_cmdline$qpxzc:near
418 proc @set_cmdline$qpxzc near
419 extrn openargs:near
420 call openargs
421 jc @ret
422 mov ch,15 ; cx<4096
423 mov di,[_heap_top]
424 jmp read_cmdline ; read_cmdline(ax,di,cx)
426 endp @set_cmdline$qpxzc
428 ifdef NO386
429 ;***************************************************************
430 ;u16 topseg();
431 ;***************************************************************
432 global _topseg:near
433 proc _topseg near
435 int 12h
436 jnc @@max640k
437 mov ax,640 ; 9000
438 @@max640k:
439 dec ax
440 and al,0C0h
441 mov cl,6
442 shl ax,cl
443 @ret:
444 ret
446 endp _topseg
447 else
448 @ret:
449 ret
450 endif
452 ;***************************************************************
453 argdone:
454 ;mov [word bx+di],0 ; argv[argc] = 0
455 lea ax,[bx+di+2]
456 mov [_heap_top],ax
457 ;push di ; argv
458 ;shr bx,1
459 ;push bx ; argc
460 ifndef filearg
461 mov bx,[di+2] ; argv[1]
462 extrn openargs:near
463 call near openargs
464 jc argend
465 ;pop bx ; trash argc, argv >> 1Kb !
466 ;pop cx ; sizemax=argv
467 dec cx ; sizemax=0ffffh
468 read_cmdline:
469 mov dx,di
470 push dx
471 xchg ax,bx
472 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
473 call near @read$cxdxbx
474 pop si ; si=buffer=argv
475 add di,ax
476 ifndef NO_CLOSE
477 extrn close:near
478 call near close
479 endif
480 jmp argbuild
481 argend:
482 endif
484 ;***************************************************************
485 ; extrn _main:near
486 ; call _main
487 ;never return
489 ;***************************************************************
492 ends _TEXT
495 end _text_start
497 ;###### END OF FILE ############################################