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

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