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

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