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

linld: add isoboot (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun May 24 16:43:25 2020 +0000 (2020-05-24)
parents a31ec0e0df8e
children d964f766faa5
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 global _bss_start:byte
33 label _bss_start byte
34 global stktop:byte
35 ifdef NO386
36 global _cpu386:byte
37 _cpu386 db ?
38 org $-1
39 endif
40 global _cpu_features:dword
41 _cpu_features dd ?
42 ends _BSS
44 segment _TEXT byte public use16 'CODE'
46 macro cpuid
47 db 0fh,0A2h
48 endm
50 org 100h
51 global _text_start:byte
52 label _text_start byte
54 ;***************************************************************
55 ; clear bss
56 ;***************************************************************
57 mov sp,offset stktop
58 mov si,offset _bss_start
59 mov bx, 0F000h ; cld ; cli & empty string
60 clearbss:
61 mov [si],bl ; clear bss + heap
62 inc si
63 ifdef ISOHOOK
64 cmp si,bx
65 endif
66 jne clearbss
68 ;***************************************************************
69 ; check CPU
70 ;***************************************************************
72 ; Check for oldies
73 push bx ; < 286 : flags[12..15] are forced 1
74 popf ; = 286 : flags[12..15] are forced 0
75 pushf ; > 286 : only flags[15] is forced 0
76 pop dx
77 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
78 ifndef NO386
79 mov bx,offset msg_badcpu
80 js godie ;it is not a 386+, die
81 else
82 js endcpu86 ;it is not a 386+, try ELKS & co
83 endif
84 p386
85 ; Check for vm
86 smsw ax ;SMSW cannot be trapped! :-)
87 and al,1 ;MSW_PE
88 ; We're in vm
89 jnz check_vcpi
91 check_rm_paging:
92 ; It's a 386 in real mode, chk for paging (crazy but possible)
93 mov eax,cr0
94 inc eax ;CR0_PG to S
95 jns endcpu386
96 ifndef NO386
97 p8086
98 extrn die:near
99 godie:
100 no_vcpi:
101 call near die
102 else
103 jmp endcpu86
104 endif
106 ifdef ISOHOOK
107 extrn @ret:near
108 global iso_open_hack
109 iso_open_hack dw @ret
110 global iso_read_hack
111 iso_read_hack dw @ret
112 global iso_lseek_hack
113 iso_lseek_hack dw @ret
114 global iso_close_hack
115 iso_close_hack dw @ret
116 global iso_cleanup_hack
117 iso_cleanup_hack dw @ret
118 dw _cpu_features+3
119 endif
121 ;***************************************************************
122 ; checks for vcpi
123 ;***************************************************************
124 label check_vcpi near
125 p386
126 push ds
127 ; Check whether it is safe to call 67h (we trust only known EMM managers)
128 push si
129 pop ds
130 mov ds,[word 67h*4+2]
131 cmp [dword si+10+4],'0XXX'
132 jne skip
133 ;mov eax,'XMME'
134 ;xor eax,[dword si+10]
135 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
136 ;shl eax,8
137 mov ax,'ME'
138 xor ax,[word si+10]
139 skip:
140 pop ds
141 jne no_vcpi
143 ; Check emm manager status and version
144 ;mov ah,40h ; get status
145 ;int 67h
146 ;inc ax
147 ;js no_vcpi
148 mov ah,46h ; get version
149 int 67h
150 cmp ax,40h ; version must be >= 4.0
151 jl no_vcpi ; btw check ax.15
152 ; Check vcpi manager status
153 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
154 ;;mov bx,4
155 ;;int 67h
156 ;;inc ax
157 ;;js no_vcpi
158 ;;push dx ;$ save handle
159 mov ax,0DE00h ; check for vcpi present
160 int 67h
161 test ah,ah
162 jnz no_vcpi
163 is386vcpi:
164 extrn prepare_vcpi:near
165 call prepare_vcpi
166 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
167 ;extrn _get_vcpi_interface:near
168 ;call _get_vcpi_interface
169 ifndef NO386
170 mov bx,offset msg_badmapping
171 jnz no_vcpi
172 dec [byte bx+_vcpi-msg_badmapping]
173 else
174 jnz no_vcpi
175 extrn _vcpi:byte
176 dec [byte _vcpi]
177 endif
178 endcpu386:
179 pushfd
180 pop dx
181 pop ax
182 mov bl,al
183 xor al,20h ; toggle CPUID feature bit 21
184 push ax
185 push dx
186 popfd
187 pushfd
188 pop dx ; dx.1=flags.1=1
189 pop ax
190 xor al,bl ; clear C
191 je @@no_cpuid ; CPUID feature bit changed ?
192 mov eax,80000001h ; Extended Processor Info and Feature Bits
193 cpuid
194 ifdef NO386
195 mov dl,-1 ; set 386 flag
196 db 66h ; mov [_cpu_features],edx
197 @@no_cpuid:
198 mov [word _cpu_features],dx ; dl != 0
199 no_vcpi:
200 else
201 mov [_cpu_features],edx
202 @@no_cpuid:
203 endif
204 endcpu86:
205 p8086
207 ;***************************************************************
208 ; build argv & argc
209 ;***************************************************************
210 extrn _bss_end:word
211 mov di,offset _bss_end
212 global _heap_top
213 org $-2
214 _heap_top dw ?
215 ;xor ax,ax
216 ;push ax ; envp (already cleared)
217 ;mov [word di],ax ; argv[0] = 0 (idem)
218 mov si,80h
219 lodsb
220 cmp al,7Eh
221 jbe alok
222 mov al,7Eh
223 alok:
224 cbw
225 xchg ax,bx
226 mov [bx+si],bh ; set eos
227 argbuild:
228 ifdef DEBUG
229 p386
230 pusha
231 mov bx,si
232 extrn puts:near
233 call puts
234 popa
235 endif
236 mov bx,2 ; argc * 2
237 argeos:
238 mov cx,1 ; look for a start of string
239 mov [byte si-1],bh ; mark eos
240 mov ah,20h ; space will be eos
241 arglp:
242 lodsb
243 cmp al,0h
244 je argdone
245 cmp al,20h
246 jb argeos
247 cmp al,ah
248 je argeos
249 cmp al,27h
250 je isargstr
251 cmp al,22h
252 je isargstr
253 jcxz arglp ; not start of string
254 dec si
255 ;jmp newarg
256 db 0BAh ; mov dx,im opcode
257 isargstr:
258 mov ah,al ; expected eos
259 newarg:
260 mov [word bx+di],si ; argv[argc++] = si
261 inc bx
262 inc bx
263 dec cx
264 jmp arglp
265 argdone:
266 ;mov [word bx+di],0 ; argv[argc] = 0
267 lea ax,[bx+di+2]
268 mov [_heap_top],ax
269 push di ; argv
270 shr bx,1
271 push bx ; argc
272 ifndef filearg
273 mov bx,[di+2] ; argv[1]
274 extrn openargs:near
275 call near openargs
276 jc argend
277 pop bx ; trash argc, argv >> 1Kb !
278 global read_cmdline:near
279 pop cx ; sizemax=argv
280 read_cmdline:
281 mov dx,di
282 push dx
283 push ax
284 xchg ax,bx
285 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
286 call near @read$cxdxbx
287 pop bx ; fd for close
288 pop si ; si=buffer=argv
289 add di,ax
290 extrn close:near
291 call near close
292 jmp argbuild
293 argend:
294 endif
296 ;***************************************************************
297 extrn _main:near
298 call _main
299 ;never return
301 ;***************************************************************
303 ends _TEXT
306 end _text_start
308 ;###### END OF FILE ############################################