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