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

Add veracrypt
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon May 24 11:24:29 2021 +0000 (2021-05-24)
parents c1a1d1f23e07
children 06547d8cf241
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 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
223 push ax ; (toggle AC: bit 18 => 486+)
224 push dx
225 popfd
226 pushfd
227 pop dx
228 pop dx
229 xor al,dl ; clear C
230 jne @@no_cpuid ; CPUID feature bit changed ?
231 mov eax,80000001h ; Extended Processor Info and Feature Bits
232 cpuid
233 mov dl,-1 ; set 386 flag
234 ifdef NO386
235 db 66h ; mov [_cpu_features],edx
236 @@no_cpuid:
237 mov [word _cpu_features],dx ; dl != 0
238 else
239 mov [_cpu_features],edx
240 @@no_cpuid:
241 endif
242 else
243 dec [_cpu386]
244 endif
245 endcpu86:
246 p8086
248 ;***************************************************************
249 ; build argv & argc
250 ;***************************************************************
251 mov si,80h
252 ifdef ISOHOOK
253 mov bx,offset _big_cmdline
254 cmp [byte si],2
255 jnb @@user_args
256 call @set_cmdline$qpxzc
257 @@user_args:
258 endif
259 lodsb ; size 0..127
260 cbw
261 ifdef ISOHOOK
262 inc ax
263 jnz short_cmdline
264 mov si,bx
265 lodsb ; size 0..254
266 short_cmdline:
267 dec ax
268 endif
269 xchg ax,bx
270 mov [bx+si],bh ; set eos
272 ;***************************************************************
274 ifdef BSS_OVERLAP_BOOT
275 mov di,offset clean-100h
277 org $-(CMDNUMCNT*4) ; alloc_cmdnum
279 ifdef room_for_image
280 org $-2-2-(2*size image_himem) ; alloc_image
281 endif
283 ifdef room_for_isostate
284 org $+ISOSTATE_OVERLAP-size isostate
285 alloc_isostate
286 endif
288 ifdef room_for_image
289 alloc_image
290 endif
292 alloc_cmdnum
293 clean:
294 mov [di+0FFh],bh
295 dec di
296 jnz clean
297 endif
299 org $-4 ; _himem_buf
300 global _himem_buf:dword
301 _himem_buf dd ?
303 ;***************************************************************
304 extrn _bss_end:word
305 mov di,offset _bss_end
306 global _heap_top
307 org $-2
308 _heap_top dw ?
309 ;xor dx,dx
310 ;push dx ; envp (already cleared)
311 ;mov [word di],dx ; argv[0] = 0 (idem)
312 argbuild:
313 mov bx,2 ; argc * 2
314 argeos:
315 mov cx,1 ; look for a start of string
316 mov [byte si-1],bh ; mark eos
317 mov ah,20h ; space will be eos
318 arglp:
319 lodsb
320 cmp al,0h
321 je argdone
322 cmp al,20h
323 jb argeos
324 cmp al,ah
325 je argeos
326 cmp al,27h
327 je isargstr
328 cmp al,22h
329 je isargstr
330 jcxz arglp ; not start of string
331 dec si
332 ;jmp newarg
333 db 0BAh ; mov dx,im opcode
334 isargstr:
335 mov ah,al ; expected eos
336 newarg:
337 mov [word bx+di],si ; argv[argc++] = si
338 inc bx
339 inc bx
340 dec cx
341 jmp arglp
343 ;***************************************************************
344 ;_fastcall void set_cmdline(bx:const char *filename);
345 ;***************************************************************
346 global @set_cmdline$qpxzc:near
347 proc @set_cmdline$qpxzc near
348 extrn openargs:near
349 call openargs
350 jc @ret
351 mov ch,15 ; cx<4096
352 mov di,[_heap_top]
353 jmp read_cmdline ; read_cmdline(ax,di,cx)
355 endp @set_cmdline$qpxzc
357 ifdef NO386
358 ;***************************************************************
359 ;u16 topseg();
360 ;***************************************************************
361 global _topseg:near
362 proc _topseg near
364 int 12h
365 jnc @@max640k
366 mov ax,640 ; 9000
367 @@max640k:
368 dec ax
369 and al,0C0h
370 mov cl,6
371 shl ax,cl
372 @ret:
373 ret
375 endp _topseg
376 else
377 @ret:
378 ret
379 endif
381 ;***************************************************************
382 argdone:
383 ;mov [word bx+di],0 ; argv[argc] = 0
384 lea ax,[bx+di+2]
385 mov [_heap_top],ax
386 ;push di ; argv
387 ;shr bx,1
388 ;push bx ; argc
389 ifndef filearg
390 mov bx,[di+2] ; argv[1]
391 extrn openargs:near
392 call near openargs
393 jc argend
394 ;pop bx ; trash argc, argv >> 1Kb !
395 ;pop cx ; sizemax=argv
396 dec cx ; sizemax=0ffffh
397 read_cmdline:
398 mov dx,di
399 push dx
400 xchg ax,bx
401 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
402 call near @read$cxdxbx
403 pop si ; si=buffer=argv
404 add di,ax
405 ifndef NO_CLOSE
406 extrn close:near
407 call near close
408 endif
409 jmp argbuild
410 argend:
411 endif
413 ;***************************************************************
414 ; extrn _main:near
415 ; call _main
416 ;never return
418 ;***************************************************************
421 ends _TEXT
424 end _text_start
426 ;###### END OF FILE ############################################