wok-current view linld/stuff/src/_BEG.ASM @ rev 21758
Update icevm & obex-data-server websites
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Jun 26 17:24:54 2019 +0200 (2019-06-26) |
parents | 2373992ff751 |
children | 6e3d30b3031f |
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p8086
10 group DGROUP _TEXT,_DATA,_BSS
11 assume cs:DGROUP,ds:DGROUP
13 segment _TEXT byte public use16 'CODE'
14 ends _TEXT
16 segment _DATA byte public use16 'DATA'
17 global _data_start:byte
18 label _data_start byte
19 ifndef NO386
20 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
21 endif
22 global _vcpi:byte
23 _vcpi db 0
24 msg_badmapping db "VCPI: low 640k need 1:1 mapping",0
26 ends _DATA
28 segment _BSS byte public use16 'BSS'
30 STACK_SIZE = 1024
32 global _bss_start:byte
33 label _bss_start byte
34 db STACK_SIZE-2 dup(?)
35 stktop dw ?
36 ifdef EXTRA
37 global _cpu_features:dword
38 _cpu_features dd ?
39 endif
40 ends _BSS
42 segment _TEXT byte public use16 'CODE'
44 macro cpuid
45 db 0fh,0A2h
46 endm
48 org 100h
49 global _text_start:byte
50 label _text_start byte
52 ;***************************************************************
53 ; clear bss
54 ;***************************************************************
55 mov sp,offset stktop
56 mov si,sp
57 mov bx, 0F000h ; cld ; cli & empty string
58 clearbss:
59 mov [si],bl ; clear bss + heap + sp
60 inc si
61 jne clearbss
63 ;***************************************************************
64 ; check CPU
65 ;***************************************************************
67 ; Check for oldies
68 push bx ; < 286 : flags[12..15] are forced 1
69 popf ; = 286 : flags[12..15] are forced 0
70 pushf ; > 286 : only flags[15] is forced 0
71 pop dx
72 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
73 ifndef NO386
74 mov bx,offset msg_badcpu
75 js godie ;it is not a 386+
76 else
77 js endcpu86 ;it is not a 386+
78 endif
79 p386
80 ; Check for vm
81 smsw ax ;SMSW cannot be trapped! :-)
82 and al,1 ;MSW_PE
83 ; We're in vm
84 jnz check_vcpi
86 check_rm_paging:
87 ; It's a 386 in real mode, chk for paging (crazy but possible)
88 mov eax,cr0
89 inc eax ;CR0_PG to S
90 jns endcpu386
91 no_vcpi:
92 p8086
93 extrn die:near
94 godie:
95 call near die
97 ;***************************************************************
98 ; checks for vcpi
99 ;***************************************************************
100 label check_vcpi near
101 p386
102 push ds
103 ; Check whether it is safe to call 67h (we trust only known EMM managers)
104 push si
105 pop ds
106 mov ds,[word 67h*4+2]
107 cmp [dword si+10+4],'0XXX'
108 jne skip
109 ;mov eax,'XMME'
110 ;xor eax,[dword si+10]
111 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
112 ;shl eax,8
113 mov ax,'ME'
114 xor ax,[word si+10]
115 skip:
116 pop ds
117 jne no_vcpi
119 ; Check emm manager status and version
120 ;mov ah,40h ; get status
121 ;int 67h
122 ;test ah,ah
123 ;jnz no_vcpi
124 mov ah,46h ; get version
125 int 67h
126 test ah,ah
127 jnz no_vcpi
128 cmp al,40h ; version must be >= 4.0
129 jb no_vcpi
130 ; Check vcpi manager status
131 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
132 ;;mov bx,4
133 ;;int 67h
134 ;;test ah,ah
135 ;;jnz no_vcpi
136 ;;push dx ;$ save handle
137 mov ax,0DE00h ; check for vcpi present
138 int 67h
139 test ah,ah
140 jnz no_vcpi
141 is386vcpi:
142 extrn prepare_vcpi:near
143 call prepare_vcpi
144 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
145 ;extrn _get_vcpi_interface:near
146 ;call _get_vcpi_interface
147 mov bx,offset msg_badmapping
148 jnz no_vcpi
149 inc [byte bx+_vcpi-msg_badmapping]
150 endcpu386:
151 ifdef EXTRA
152 pushfd
153 pop dx
154 pop ax
155 mov bl,al
156 xor al,20h ; toggle CPUID feature bit 21
157 push ax
158 push dx
159 popfd
160 pushfd
161 pop dx
162 pop ax
163 xor al,bl ; clear C
164 je @@no_cpuid ; CPUID feature bit changed ?
165 mov eax,80000001h ; Extended Processor Info and Feature Bits
166 cpuid
167 mov [_cpu_features],edx
168 @@no_cpuid:
169 endif
170 endcpu86:
171 p8086
173 ;***************************************************************
174 ; build argv & argc
175 ;***************************************************************
176 extrn _heap_top:word
177 mov di,[_heap_top]
178 ;xor ax,ax
179 ;push ax ; envp (already cleared)
180 ;mov [word di],ax ; argv[0] = 0 (idem)
181 mov si,80h
182 lodsb
183 cmp al,7Eh
184 jbe alok
185 mov al,7Eh
186 alok:
187 cbw
188 xchg ax,bx
189 mov [bx+si],bh ; set eos
190 argbuild:
191 ifdef DEBUG
192 p386
193 pusha
194 mov bx,si
195 extrn puts:near
196 call puts
197 popa
198 endif
199 mov bx,2 ; argc * 2
200 argeos:
201 mov cx,1 ; look for a start of string
202 mov [byte si-1],bh ; mark eos
203 mov ah,20h ; space will be eos
204 arglp:
205 lodsb
206 cmp al,0h
207 je argdone
208 cmp al,20h
209 jb argeos
210 cmp al,ah
211 je argeos
212 cmp al,27h
213 je isargstr
214 cmp al,22h
215 je isargstr
216 jcxz arglp ; not start of string
217 dec si
218 ;jmp newarg
219 db 0BAh ; mov dx,im opcode
220 isargstr:
221 mov ah,al ; expected eos
222 newarg:
223 mov [word bx+di],si ; argv[argc++] = si
224 inc bx
225 inc bx
226 dec cx
227 jmp arglp
228 argdone:
229 ;mov [word bx+di],0 ; argv[argc] = 0
230 lea ax,[bx+di+2]
231 mov [_heap_top],ax
232 push di ; argv
233 shr bx,1
234 push bx ; argc
235 ifndef filearg
236 mov bx,[di+2] ; argv[1]
237 extrn openargs:near
238 call near openargs
239 jc argend
240 pop bx ; trash argc, argv >> 1Kb !
241 global read_cmdline:near
242 pop cx ; sizemax=argv
243 read_cmdline:
244 mov dx,di
245 push dx
246 push ax
247 xchg ax,bx
248 extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx)
249 call near @read$cxdxbx
250 pop bx ; fd for close
251 pop si ; si=buffer=argv
252 add di,ax
253 extrn close:near
254 call near close
255 jmp argbuild
256 argend:
257 endif
259 ;***************************************************************
260 extrn _main:near
261 call _main
262 ;never return
264 ;***************************************************************
266 ends _TEXT
269 end _text_start
271 ;###### END OF FILE ############################################