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

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