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