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

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