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

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