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

syslinux/iso2exe: read isolinux.cfg
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 12 07:47:12 2021 +0000 (2021-01-12)
parents a946c1651082
children bc4b94310a29
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 p8086
11 group DGROUP _TEXT,_DATA,_BSS
12 assume cs:DGROUP,ds:DGROUP
14 segment _TEXT byte public use16 'CODE'
15 ends _TEXT
17 segment _DATA byte public use16 'DATA'
18 ;global _data_start:byte
19 label _data_start byte
20 ifndef NO386
21 msg_badcpu db "I need 386+ CPU in real mode w/o paging"
22 db " or "
23 msg_badmapping db "under VCPI 4.0+ manager with low 640k 1:1 mapping"
24 global _vcpi:byte
25 _vcpi db 0
26 endif
28 ends _DATA
30 segment _BSS byte public use16 'BSS'
32 ifdef BIG_CMDLINE
33 extrn _big_cmdline:byte
34 db 254 dup(?)
35 endif
36 ;global _bss_start:byte
37 label _bss_start byte
38 global stktop:byte
39 ifdef NO386
40 global _cpu386:byte
41 _cpu386 db ?
42 org $-1
43 endif
44 global _cpu_features:dword
45 _cpu_features dd ?
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 macro cpuid
51 db 0fh,0A2h
52 endm
54 org 100h
55 ;global _text_start:byte
56 label _text_start byte
58 ;***************************************************************
59 ; clear bss
60 ;***************************************************************
61 mov sp,offset stktop
62 mov bx, 0F000h ; cld ; cli & empty string
63 org $-4-2
64 global _himem_buf:dword
65 _himem_buf dd ?
66 global _buf_cmdline:word
67 _buf_cmdline dw ? ; 128 bytes, must start with 00
68 mov si,offset _bss_start
69 clearbss:
70 mov [si],bl ; clear bss + heap
71 inc si
72 jne clearbss
74 ;***************************************************************
75 ; check CPU
76 ;***************************************************************
78 ; Check for oldies
79 push bx ; < 286 : flags[12..15] are forced 1
80 popf ; = 286 : flags[12..15] are forced 0
81 pushf ; > 286 : only flags[15] is forced 0
82 pop dx
83 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
84 ifndef NO386
85 mov bx,offset msg_badcpu
86 js godie ;it is not a 386+, die
87 else
88 js endcpu86 ;it is not a 386+, try ELKS & co
89 endif
90 p386
91 mov edx,cs
92 shl edx,4 ; edx for prepare_vcpi
93 extrn gdt_base_memcpy:word ; gdt_base for memcpy32
94 add [dword gdt_base_memcpy],edx
95 ; Check for vm
96 smsw ax ;SMSW cannot be trapped! :-)
97 and al,1 ;MSW_PE
98 ; We're in vm
99 jnz check_vcpi
101 check_rm_paging:
102 ; It's a 386 in real mode, chk for paging (crazy but possible)
103 mov eax,cr0
104 inc eax ;CR0_PG to S
105 jns endcpu386
106 ifndef NO386
107 p8086
108 extrn die:near
109 godie:
110 call near die
111 else
112 jmp endcpu86
113 endif
116 ;***************************************************************
117 ; checks for vcpi
118 ;***************************************************************
119 label check_vcpi near
120 p386
121 push ds
122 ; Check whether it is safe to call 67h (we trust only known EMM managers)
123 push si
124 pop ds
125 mov ax,[word 67h*4]
126 or ax,[word 67h*4+2]
127 pop ds
128 je no_vcpi
129 mov ax,0DE00h ; check for vcpi present
130 int 67h
131 or ah,ah
132 jnz no_vcpi
133 is386vcpi:
134 extrn prepare_vcpi:near
135 call prepare_vcpi
136 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
137 ;extrn _get_vcpi_interface:near
138 ;call _get_vcpi_interface
139 ifndef NO386
140 mov bx,offset msg_badmapping
141 jnz no_vcpi
142 dec [byte bx+_vcpi-msg_badmapping]
143 else
144 jnz no_vcpi
145 extrn _vcpi:byte
146 dec [byte _vcpi]
147 endif
148 no_vcpi:
149 endcpu386:
150 pushfd
151 pop dx
152 pop ax
153 mov bl,al
154 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
155 push ax ; (toggle AC: bit 18 => 486+)
156 push dx
157 popfd
158 pushfd
159 pop dx ; dx.1=flags.1=1
160 pop ax
161 xor al,bl ; clear C
162 je @@no_cpuid ; CPUID feature bit changed ?
163 mov eax,80000001h ; Extended Processor Info and Feature Bits
164 cpuid
165 mov dl,-1 ; set 386 flag (assume cpuid => fpu:bit0=1 ?)
166 ifdef NO386
167 db 66h ; mov [_cpu_features],edx
168 @@no_cpuid:
169 mov [word _cpu_features],dx ; dl != 0
170 else
171 mov [_cpu_features],edx
172 @@no_cpuid:
173 endif
174 endcpu86:
175 p8086
177 ;***************************************************************
178 ; build argv & argc
179 ;***************************************************************
180 extrn _bss_end:word
181 mov di,offset _bss_end
182 global _heap_top
183 org $-2
184 _heap_top dw ?
185 mov si,80h
186 ifdef BIG_CMDLINE
187 mov bx,offset _big_cmdline
188 cmp [byte si],2
189 jnb @@user_args
190 call @set_cmdline$qpxzc
191 @@user_args:
192 endif
193 lodsb ; size 0..127
194 cbw
195 ifdef BIG_CMDLINE
196 inc ax
197 jnz short_cmdline
198 mov si,bx
199 lodsb ; size 0..254
200 short_cmdline:
201 dec ax
202 endif
203 xchg ax,bx
204 mov [bx+si],bh ; set eos
205 ;xor dx,dx
206 ;push dx ; envp (already cleared)
207 ;mov [word di],dx ; argv[0] = 0 (idem)
208 argbuild:
209 mov bx,2 ; argc * 2
210 argeos:
211 mov cx,1 ; look for a start of string
212 mov [byte si-1],bh ; mark eos
213 mov ah,20h ; space will be eos
214 arglp:
215 lodsb
216 cmp al,0h
217 je argdone
218 cmp al,20h
219 jb argeos
220 cmp al,ah
221 je argeos
222 cmp al,27h
223 je isargstr
224 cmp al,22h
225 je isargstr
226 jcxz arglp ; not start of string
227 dec si
228 ;jmp newarg
229 db 0BAh ; mov dx,im opcode
230 isargstr:
231 mov ah,al ; expected eos
232 newarg:
233 mov [word bx+di],si ; argv[argc++] = si
234 inc bx
235 inc bx
236 dec cx
237 jmp arglp
238 argdone:
239 ;mov [word bx+di],0 ; argv[argc] = 0
240 lea ax,[bx+di+2]
241 mov [_heap_top],ax
242 push di ; argv
243 shr bx,1
244 push bx ; argc
245 ifndef filearg
246 mov bx,[di+2] ; argv[1]
247 extrn openargs:near
248 call near openargs
249 jc argend
250 pop bx ; trash argc, argv >> 1Kb !
251 pop cx ; sizemax=argv
252 read_cmdline:
253 mov dx,di
254 push dx
255 xchg ax,bx
256 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
257 call near @read$cxdxbx
258 pop si ; si=buffer=argv
259 add di,ax
260 ifndef NO_CLOSE
261 extrn close:near
262 call near close
263 endif
264 jmp argbuild
265 argend:
266 endif
268 ;***************************************************************
269 extrn _main:near
270 call _main
271 ;never return
273 ;***************************************************************
276 ;***************************************************************
277 ;_fastcall void set_cmdline(bx:const char *filename);
278 ;***************************************************************
279 global @set_cmdline$qpxzc:near
280 proc @set_cmdline$qpxzc near
281 extrn openargs:near
282 call openargs
283 jc @ret
284 mov ch,15 ; cx<4096
285 mov di,[_heap_top]
286 jmp read_cmdline ; read_cmdline(ax,di,cx)
288 endp @set_cmdline$qpxzc
290 ifdef NO386
291 ;***************************************************************
292 ;u16 topseg();
293 ;***************************************************************
294 global _topseg:near
295 proc _topseg near
297 int 12h
298 jnc @@max640k
299 mov ax,640 ; 9000
300 @@max640k:
301 dec ax
302 and al,0C0h
303 mov cl,6
304 shl ax,cl
305 @ret:
306 ret
308 endp _topseg
309 endif
311 ends _TEXT
314 end _text_start
316 ;###### END OF FILE ############################################