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

Up ipxe (1.21.1), rsync (3.2.3)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon May 10 19:33:04 2021 +0000 (2021-05-10)
parents 6b6d14c9f7e9
children 324b3fa82b76
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 ifdef QUICK_BOOT
15 CMDNUMCNT = 7
16 else
17 CMDNUMCNT = 5
18 endif
20 macro alloc_isostate
21 public _isostate
22 _isostate isostate <?>
23 org $-ISOSTATE_OVERLAP
24 endm
26 macro alloc_image
27 rm_size dw ? ; _imgs-4
28 rm_buf dw ? ; _imgs-2
29 global _imgs:byte
30 label _imgs byte
31 img_kernel image_himem ?
32 img_initrd image_himem ?
33 endm
35 macro alloc_cmdnum
36 global _cmdnum:word
37 label _cmdnum word
38 dd CMDNUMCNT dup(?)
39 endm
41 p8086
43 group DGROUP _TEXT,_DATA,_BSS
44 assume cs:DGROUP,ds:DGROUP
46 segment _TEXT byte public use16 'CODE'
47 ends _TEXT
49 segment _DATA byte public use16 'DATA'
50 ;global _data_start:byte
51 label _data_start byte
52 ifndef NO386
53 msg_badcpu db "I need a 386+ in real mode w/o paging"
54 ifdef VCPI
55 db " or "
56 msg_badmapping db "under VCPI 4.0+ manager with low 640k 1:1 mapping"
57 global _vcpi:byte
58 endif
59 _vcpi db 0
60 endif
62 ends _DATA
64 segment _BSS byte public use16 'BSS'
66 ifdef ISO9660
67 ifndef VCPI
68 alloc_isotate
69 else
70 room_for_isostate = 1
71 endif
72 endif
74 ifdef ISOHOOK
75 extrn _big_cmdline:byte
76 db 254 dup(?)
77 endif
78 ;global _bss_start:byte
79 label _bss_start byte
80 global stktop:byte
81 global _cpu386:byte
82 _cpu386 db ?
83 ifdef CPU64
84 org $-1
85 global _cpu_features:dword
86 _cpu_features dd ?
87 room_for_image = 1
88 else
89 alloc_image
90 endif
92 ;BSS_OVERLAP_BOOT = 1
94 ifndef BSS_OVERLAP_BOOT
96 ifdef room_for_isostate
97 alloc_isostate
98 endif
100 ifdef room_for_image
101 alloc_image
102 endif
104 alloc_cmdnum
106 endif
108 ends _BSS
110 segment _TEXT byte public use16 'CODE'
112 macro cpuid
113 db 0fh,0A2h
114 endm
116 org 100h
117 ;global _text_start:byte
118 label _text_start byte
120 ;***************************************************************
121 ; clear bss
122 ;***************************************************************
123 mov sp,offset stktop
124 mov bx, 0F000h ; cld ; cli & empty string
125 mov si,offset _bss_start
126 clearbss:
127 mov [si],bl ; clear bss + heap
128 inc si
129 jne clearbss
131 ;***************************************************************
132 ; check CPU
133 ;***************************************************************
135 ; Check for oldies
136 push bx ; < 286 : flags[12..15] are forced 1
137 popf ; = 286 : flags[12..15] are forced 0, cld, cli
138 pushf ; > 286 : only flags[15] is forced 0
139 pop dx
140 add dh,bh ; 160:NS=386+, 0F0:NC=286, 1E0:NP=86/186
141 ifndef NO386
142 mov bx,offset msg_badcpu
143 js godie ;it is not a 386+, die
144 else
145 js endcpu86 ;it is not a 386+, try ELKS & co
146 endif
147 p386
148 ifdef VCPI
149 mov edx,cs
150 shl edx,4 ; edx for prepare_vcpi
151 else
152 ifndef LARGE_ZIMAGE
153 mov edx,cs
154 shl edx,4 ; edx for memcpy32
155 endif
156 endif
157 ifndef LARGE_ZIMAGE
158 extrn gdt_base_memcpy:word ; gdt_base for memcpy32
159 add [dword gdt_base_memcpy],edx
160 endif
162 ; Check for vm
163 smsw ax ;SMSW cannot be trapped! :-)
164 and al,1 ;MSW_PE
165 ; We're in vm
166 jnz check_vcpi
168 check_rm_paging:
169 ; It's a 386 in real mode, chk for paging (crazy but possible)
170 mov eax,cr0
171 inc eax ;CR0_PG to S
172 jns endcpu386
173 ifndef NO386
174 p8086
175 extrn die:near
176 godie:
177 call near die
178 else
179 jmp endcpu86
180 endif
183 ;***************************************************************
184 ; checks for vcpi
185 ;***************************************************************
186 label check_vcpi near
187 p386
188 ifdef VCPI
189 ; Check whether it is safe to call 67h
190 xor eax,eax
191 push ds
192 mov ds,ax
193 cmp [dword 67h*4],eax
194 pop ds
195 je no_vcpi
196 mov ah,0DEh ; check for vcpi present
197 int 67h
198 or ah,ah
199 jnz no_vcpi
200 is386vcpi:
201 extrn prepare_vcpi:near
202 call prepare_vcpi
203 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
204 ;extrn _get_vcpi_interface:near
205 ;call _get_vcpi_interface
206 ifndef NO386
207 mov bx,offset msg_badmapping
208 jnz no_vcpi
209 dec [byte bx+_vcpi-msg_badmapping]
210 else
211 jnz no_vcpi
212 extrn _vcpi:byte
213 dec [byte _vcpi]
214 endif
215 endif
216 no_vcpi:
217 endcpu386:
218 ifdef CPU64
219 pushfd
220 pop dx
221 pop ax
222 mov bl,al
223 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
224 push ax ; (toggle AC: bit 18 => 486+)
225 push dx
226 popfd
227 pushfd
228 pop dx ; dx.1=flags.1=1
229 pop ax
230 xor al,bl ; clear C
231 je @@no_cpuid ; CPUID feature bit changed ?
232 mov eax,80000001h ; Extended Processor Info and Feature Bits
233 cpuid
234 mov dl,-1 ; set 386 flag (assume cpuid => fpu:bit0=1 ?)
235 ifdef NO386
236 db 66h ; mov [_cpu_features],edx
237 @@no_cpuid:
238 mov [word _cpu_features],dx ; dl != 0
239 else
240 mov [_cpu_features],edx
241 @@no_cpuid:
242 endif
243 else
244 dec [_cpu386]
245 endif
246 endcpu86:
247 p8086
249 ;***************************************************************
250 ; build argv & argc
251 ;***************************************************************
252 mov si,80h
253 ifdef ISOHOOK
254 mov bx,offset _big_cmdline
255 cmp [byte si],2
256 jnb @@user_args
257 call @set_cmdline$qpxzc
258 @@user_args:
259 endif
260 lodsb ; size 0..127
261 cbw
262 ifdef ISOHOOK
263 inc ax
264 jnz short_cmdline
265 mov si,bx
266 lodsb ; size 0..254
267 short_cmdline:
268 dec ax
269 endif
270 xchg ax,bx
271 mov [bx+si],bh ; set eos
273 ;***************************************************************
275 ifdef BSS_OVERLAP_BOOT
276 mov di,offset clean-100h
278 org $-(CMDNUMCNT*4) ; alloc_cmdnum
280 ifdef room_for_image
281 org $-2-2-(2*size image_himem) ; alloc_image
282 endif
284 ifdef room_for_isostate
285 org $+ISOSTATE_OVERLAP-size isostate
286 alloc_isostate
287 endif
289 ifdef room_for_image
290 alloc_image
291 endif
293 alloc_cmdnum
294 clean:
295 mov [di+0FFh],bh
296 dec di
297 jnz clean
298 endif
300 org $-4 ; _himem_buf
301 global _himem_buf:dword
302 _himem_buf dd ?
304 ;***************************************************************
305 extrn _bss_end:word
306 mov di,offset _bss_end
307 global _heap_top
308 org $-2
309 _heap_top dw ?
310 ;xor dx,dx
311 ;push dx ; envp (already cleared)
312 ;mov [word di],dx ; argv[0] = 0 (idem)
313 argbuild:
314 mov bx,2 ; argc * 2
315 argeos:
316 mov cx,1 ; look for a start of string
317 mov [byte si-1],bh ; mark eos
318 mov ah,20h ; space will be eos
319 arglp:
320 lodsb
321 cmp al,0h
322 je argdone
323 cmp al,20h
324 jb argeos
325 cmp al,ah
326 je argeos
327 cmp al,27h
328 je isargstr
329 cmp al,22h
330 je isargstr
331 jcxz arglp ; not start of string
332 dec si
333 ;jmp newarg
334 db 0BAh ; mov dx,im opcode
335 isargstr:
336 mov ah,al ; expected eos
337 newarg:
338 mov [word bx+di],si ; argv[argc++] = si
339 inc bx
340 inc bx
341 dec cx
342 jmp arglp
344 ;***************************************************************
345 ;_fastcall void set_cmdline(bx:const char *filename);
346 ;***************************************************************
347 global @set_cmdline$qpxzc:near
348 proc @set_cmdline$qpxzc near
349 extrn openargs:near
350 call openargs
351 jc @ret
352 mov ch,15 ; cx<4096
353 mov di,[_heap_top]
354 jmp read_cmdline ; read_cmdline(ax,di,cx)
356 endp @set_cmdline$qpxzc
358 ifdef NO386
359 ;***************************************************************
360 ;u16 topseg();
361 ;***************************************************************
362 global _topseg:near
363 proc _topseg near
365 int 12h
366 jnc @@max640k
367 mov ax,640 ; 9000
368 @@max640k:
369 dec ax
370 and al,0C0h
371 mov cl,6
372 shl ax,cl
373 @ret:
374 ret
376 endp _topseg
377 else
378 @ret:
379 ret
380 endif
382 ;***************************************************************
383 argdone:
384 ;mov [word bx+di],0 ; argv[argc] = 0
385 lea ax,[bx+di+2]
386 mov [_heap_top],ax
387 ;push di ; argv
388 ;shr bx,1
389 ;push bx ; argc
390 ifndef filearg
391 mov bx,[di+2] ; argv[1]
392 extrn openargs:near
393 call near openargs
394 jc argend
395 ;pop bx ; trash argc, argv >> 1Kb !
396 ;pop cx ; sizemax=argv
397 dec cx ; sizemax=0ffffh
398 read_cmdline:
399 mov dx,di
400 push dx
401 xchg ax,bx
402 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
403 call near @read$cxdxbx
404 pop si ; si=buffer=argv
405 add di,ax
406 ifndef NO_CLOSE
407 extrn close:near
408 call near close
409 endif
410 jmp argbuild
411 argend:
412 endif
414 ;***************************************************************
415 ; extrn _main:near
416 ; call _main
417 ;never return
419 ;***************************************************************
422 ends _TEXT
425 end _text_start
427 ;###### END OF FILE ############################################