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

linld: add quick boot switch
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 18 08:56:43 2021 +0000 (2021-02-18)
parents 5c1ce90eb1d6
children 61df94a0fa43
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 ISOHOOK
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, cld
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 ; Check whether it is safe to call 67h
122 xor eax,eax
123 mov es,ax
124 cmp [dword es:67h*4],eax
125 je no_vcpi
126 mov ah,0DEh ; check for vcpi present
127 int 67h
128 or ah,ah
129 jnz no_vcpi
130 is386vcpi:
131 extrn prepare_vcpi:near
132 call prepare_vcpi
133 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
134 ;extrn _get_vcpi_interface:near
135 ;call _get_vcpi_interface
136 ifndef NO386
137 mov bx,offset msg_badmapping
138 jnz no_vcpi
139 dec [byte bx+_vcpi-msg_badmapping]
140 else
141 jnz no_vcpi
142 extrn _vcpi:byte
143 dec [byte _vcpi]
144 endif
145 no_vcpi:
146 endcpu386:
147 pushfd
148 pop dx
149 pop ax
150 mov bl,al
151 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+)
152 push ax ; (toggle AC: bit 18 => 486+)
153 push dx
154 popfd
155 pushfd
156 pop dx ; dx.1=flags.1=1
157 pop ax
158 xor al,bl ; clear C
159 je @@no_cpuid ; CPUID feature bit changed ?
160 mov eax,80000001h ; Extended Processor Info and Feature Bits
161 cpuid
162 mov dl,-1 ; set 386 flag (assume cpuid => fpu:bit0=1 ?)
163 ifdef NO386
164 db 66h ; mov [_cpu_features],edx
165 @@no_cpuid:
166 mov [word _cpu_features],dx ; dl != 0
167 else
168 mov [_cpu_features],edx
169 @@no_cpuid:
170 endif
171 endcpu86:
172 p8086
174 ;***************************************************************
175 ; build argv & argc
176 ;***************************************************************
177 extrn _bss_end:word
178 mov di,offset _bss_end
179 global _heap_top
180 org $-2
181 _heap_top dw ?
182 mov si,80h
183 ifdef ISOHOOK
184 mov bx,offset _big_cmdline
185 cmp [byte si],2
186 jnb @@user_args
187 call @set_cmdline$qpxzc
188 @@user_args:
189 endif
190 lodsb ; size 0..127
191 cbw
192 ifdef ISOHOOK
193 inc ax
194 jnz short_cmdline
195 mov si,bx
196 lodsb ; size 0..254
197 short_cmdline:
198 dec ax
199 endif
200 xchg ax,bx
201 mov [bx+si],bh ; set eos
202 ;xor dx,dx
203 ;push dx ; envp (already cleared)
204 ;mov [word di],dx ; argv[0] = 0 (idem)
205 argbuild:
206 mov bx,2 ; argc * 2
207 argeos:
208 mov cx,1 ; look for a start of string
209 mov [byte si-1],bh ; mark eos
210 mov ah,20h ; space will be eos
211 arglp:
212 lodsb
213 cmp al,0h
214 je argdone
215 cmp al,20h
216 jb argeos
217 cmp al,ah
218 je argeos
219 cmp al,27h
220 je isargstr
221 cmp al,22h
222 je isargstr
223 jcxz arglp ; not start of string
224 dec si
225 ;jmp newarg
226 db 0BAh ; mov dx,im opcode
227 isargstr:
228 mov ah,al ; expected eos
229 newarg:
230 mov [word bx+di],si ; argv[argc++] = si
231 inc bx
232 inc bx
233 dec cx
234 jmp arglp
236 ;***************************************************************
237 ;_fastcall void set_cmdline(bx:const char *filename);
238 ;***************************************************************
239 global @set_cmdline$qpxzc:near
240 proc @set_cmdline$qpxzc near
241 extrn openargs:near
242 call openargs
243 jc @ret
244 mov ch,15 ; cx<4096
245 mov di,[_heap_top]
246 jmp read_cmdline ; read_cmdline(ax,di,cx)
248 endp @set_cmdline$qpxzc
250 ifdef NO386
251 ;***************************************************************
252 ;u16 topseg();
253 ;***************************************************************
254 global _topseg:near
255 proc _topseg near
257 int 12h
258 jnc @@max640k
259 mov ax,640 ; 9000
260 @@max640k:
261 dec ax
262 and al,0C0h
263 mov cl,6
264 shl ax,cl
265 @ret:
266 ret
268 endp _topseg
269 endif
271 ;***************************************************************
272 argdone:
273 ;mov [word bx+di],0 ; argv[argc] = 0
274 lea ax,[bx+di+2]
275 mov [_heap_top],ax
276 ;push di ; argv
277 ;shr bx,1
278 ;push bx ; argc
279 ifndef filearg
280 mov bx,[di+2] ; argv[1]
281 extrn openargs:near
282 call near openargs
283 jc argend
284 ;pop bx ; trash argc, argv >> 1Kb !
285 ;pop cx ; sizemax=argv
286 dec cx ; sizemax=0ffffh
287 read_cmdline:
288 mov dx,di
289 push dx
290 xchg ax,bx
291 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
292 call near @read$cxdxbx
293 pop si ; si=buffer=argv
294 add di,ax
295 ifndef NO_CLOSE
296 extrn close:near
297 call near close
298 endif
299 jmp argbuild
300 argend:
301 endif
303 ;***************************************************************
304 ; extrn _main:near
305 ; call _main
306 ;never return
308 ;***************************************************************
311 ends _TEXT
314 end _text_start
316 ;###### END OF FILE ############################################