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