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

updated dialog (1.3_20190211 -> 1.3_20210324)
author Hans-G?nter Theisgen
date Tue Apr 06 13:52:57 2021 +0100 (2021-04-06)
parents 217c02cbbe8d
children 6b6d14c9f7e9
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_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 ifndef BSS_OVERLAP_BOOT
94 ifdef room_for_isostate
95 alloc_isostate
96 endif
98 ifdef room_for_image
99 alloc_image
100 endif
102 alloc_cmdnum
104 endif
106 ends _BSS
108 segment _TEXT byte public use16 'CODE'
110 macro cpuid
111 db 0fh,0A2h
112 endm
114 org 100h
115 ;global _text_start:byte
116 label _text_start byte
118 ;***************************************************************
119 ; clear bss
120 ;***************************************************************
121 mov sp,offset stktop
122 mov bx, 0F000h ; cld ; cli & empty string
123 mov si,offset _bss_start
124 clearbss:
125 mov [si],bl ; clear bss + heap
126 inc si
127 jne clearbss
129 ;***************************************************************
130 ; check CPU
131 ;***************************************************************
133 ; Check for oldies
134 push bx ; < 286 : flags[12..15] are forced 1
135 popf ; = 286 : flags[12..15] are forced 0, cld
136 pushf ; > 286 : only flags[15] is forced 0
137 pop dx
138 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
139 ifndef NO386
140 mov bx,offset msg_badcpu
141 js godie ;it is not a 386+, die
142 else
143 js endcpu86 ;it is not a 386+, try ELKS & co
144 endif
145 p386
146 mov edx,cs
147 shl edx,4 ; edx for prepare_vcpi
148 extrn gdt_base_memcpy:word ; gdt_base for memcpy32
149 add [dword gdt_base_memcpy],edx
150 ; Check for vm
151 smsw ax ;SMSW cannot be trapped! :-)
152 and al,1 ;MSW_PE
153 ; We're in vm
154 jnz check_vcpi
156 check_rm_paging:
157 ; It's a 386 in real mode, chk for paging (crazy but possible)
158 mov eax,cr0
159 inc eax ;CR0_PG to S
160 jns endcpu386
161 ifndef NO386
162 p8086
163 extrn die:near
164 godie:
165 call near die
166 else
167 jmp endcpu86
168 endif
171 ;***************************************************************
172 ; checks for vcpi
173 ;***************************************************************
174 label check_vcpi near
175 p386
176 ifdef VCPI
177 ; Check whether it is safe to call 67h
178 xor eax,eax
179 push ds
180 mov ds,ax
181 cmp [dword 67h*4],eax
182 pop ds
183 je no_vcpi
184 mov ah,0DEh ; check for vcpi present
185 int 67h
186 or ah,ah
187 jnz no_vcpi
188 is386vcpi:
189 extrn prepare_vcpi:near
190 call prepare_vcpi
191 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
192 ;extrn _get_vcpi_interface:near
193 ;call _get_vcpi_interface
194 ifndef NO386
195 mov bx,offset msg_badmapping
196 jnz no_vcpi
197 dec [byte bx+_vcpi-msg_badmapping]
198 else
199 jnz no_vcpi
200 extrn _vcpi:byte
201 dec [byte _vcpi]
202 endif
203 endif
204 no_vcpi:
205 endcpu386:
206 ifdef CPU64
207 pushfd
208 pop dx
209 pop ax
210 mov bl,al
211 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
212 push ax ; (toggle AC: bit 18 => 486+)
213 push dx
214 popfd
215 pushfd
216 pop dx ; dx.1=flags.1=1
217 pop ax
218 xor al,bl ; clear C
219 je @@no_cpuid ; CPUID feature bit changed ?
220 mov eax,80000001h ; Extended Processor Info and Feature Bits
221 cpuid
222 mov dl,-1 ; set 386 flag (assume cpuid => fpu:bit0=1 ?)
223 ifdef NO386
224 db 66h ; mov [_cpu_features],edx
225 @@no_cpuid:
226 mov [word _cpu_features],dx ; dl != 0
227 else
228 mov [_cpu_features],edx
229 @@no_cpuid:
230 endif
231 else
232 dec [_cpu386]
233 endif
234 endcpu86:
235 p8086
237 ;***************************************************************
238 ; build argv & argc
239 ;***************************************************************
240 mov si,80h
241 ifdef ISOHOOK
242 mov bx,offset _big_cmdline
243 cmp [byte si],2
244 jnb @@user_args
245 call @set_cmdline$qpxzc
246 @@user_args:
247 endif
248 lodsb ; size 0..127
249 cbw
250 ifdef ISOHOOK
251 inc ax
252 jnz short_cmdline
253 mov si,bx
254 lodsb ; size 0..254
255 short_cmdline:
256 dec ax
257 endif
258 xchg ax,bx
259 mov [bx+si],bh ; set eos
261 ;***************************************************************
263 org $-4 ; _himem_buf
265 ifdef BSS_OVERLAP_BOOT
266 mov al,0
267 mov di,100h
268 mov cx,offset clean-100h
270 org $-(CMDNUMCNT*4) ; alloc_cmdnum
272 ifdef room_for_image
273 org $-2-2-(2*size image_himem) ; alloc_image
274 endif
276 ifdef room_for_isostate
277 org $+ISOSTATE_OVERLAP-size isostate
278 alloc_isostate
279 endif
281 ifdef room_for_image
282 alloc_image
283 endif
285 alloc_cmdnum
286 endif
288 global _himem_buf:dword
289 _himem_buf dd ?
291 ifdef BSS_OVERLAP_BOOT
292 clean:
293 rep
294 stosb
295 endif
297 ;***************************************************************
298 extrn _bss_end:word
299 mov di,offset _bss_end
300 global _heap_top
301 org $-2
302 _heap_top dw ?
303 ;xor dx,dx
304 ;push dx ; envp (already cleared)
305 ;mov [word di],dx ; argv[0] = 0 (idem)
306 argbuild:
307 mov bx,2 ; argc * 2
308 argeos:
309 mov cx,1 ; look for a start of string
310 mov [byte si-1],bh ; mark eos
311 mov ah,20h ; space will be eos
312 arglp:
313 lodsb
314 cmp al,0h
315 je argdone
316 cmp al,20h
317 jb argeos
318 cmp al,ah
319 je argeos
320 cmp al,27h
321 je isargstr
322 cmp al,22h
323 je isargstr
324 jcxz arglp ; not start of string
325 dec si
326 ;jmp newarg
327 db 0BAh ; mov dx,im opcode
328 isargstr:
329 mov ah,al ; expected eos
330 newarg:
331 mov [word bx+di],si ; argv[argc++] = si
332 inc bx
333 inc bx
334 dec cx
335 jmp arglp
337 ;***************************************************************
338 ;_fastcall void set_cmdline(bx:const char *filename);
339 ;***************************************************************
340 global @set_cmdline$qpxzc:near
341 proc @set_cmdline$qpxzc near
342 extrn openargs:near
343 call openargs
344 jc @ret
345 mov ch,15 ; cx<4096
346 mov di,[_heap_top]
347 jmp read_cmdline ; read_cmdline(ax,di,cx)
349 endp @set_cmdline$qpxzc
351 ifdef NO386
352 ;***************************************************************
353 ;u16 topseg();
354 ;***************************************************************
355 global _topseg:near
356 proc _topseg near
358 int 12h
359 jnc @@max640k
360 mov ax,640 ; 9000
361 @@max640k:
362 dec ax
363 and al,0C0h
364 mov cl,6
365 shl ax,cl
366 @ret:
367 ret
369 endp _topseg
370 else
371 @ret:
372 ret
373 endif
375 ;***************************************************************
376 argdone:
377 ;mov [word bx+di],0 ; argv[argc] = 0
378 lea ax,[bx+di+2]
379 mov [_heap_top],ax
380 ;push di ; argv
381 ;shr bx,1
382 ;push bx ; argc
383 ifndef filearg
384 mov bx,[di+2] ; argv[1]
385 extrn openargs:near
386 call near openargs
387 jc argend
388 ;pop bx ; trash argc, argv >> 1Kb !
389 ;pop cx ; sizemax=argv
390 dec cx ; sizemax=0ffffh
391 read_cmdline:
392 mov dx,di
393 push dx
394 xchg ax,bx
395 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
396 call near @read$cxdxbx
397 pop si ; si=buffer=argv
398 add di,ax
399 ifndef NO_CLOSE
400 extrn close:near
401 call near close
402 endif
403 jmp argbuild
404 argend:
405 endif
407 ;***************************************************************
408 ; extrn _main:near
409 ; call _main
410 ;never return
412 ;***************************************************************
415 ends _TEXT
418 end _text_start
420 ;###### END OF FILE ############################################