wok-6.x view linld/stuff/src/_BEG.ASM @ rev 24019

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