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