wok-current view linld/stuff/src/_BEG.ASM @ rev 20119
slitaz-base-files (333), slitaz-boot-scripts (445), slitaz-configs (313), slitaz-tools (1025), tazbug (152), tazinst (93), tazirc (22), tazlito (469), tazpanel (617), tazweb (208): revision of german messages
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Oct 14 10:45:51 2017 +0200 (2017-10-14) |
parents | 766a40e6c5e0 |
children | 04feaffdc0d9 |
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 db 0B9h ; mov cx,im opcode
200 isargstr:
201 mov ah,al ; expected eos
202 newarg:
203 mov [word bx+di],si ; argv[argc++] = si
204 inc bx
205 inc bx
206 dec dx
207 jmp arglp
208 argdone:
209 ;mov [word bx+di],0 ; argv[argc] = 0
210 lea ax,[bx+di+2]
211 mov [_heap_top],ax
212 push di ; argv
213 shr bx,1
214 push bx ; argc
215 ifndef filearg
216 mov bx,[di+2] ; argv[1]
217 cmp [byte bx],'@'
218 jne argend
219 inc bx
220 extrn open:near
221 call near open
222 jc argend
223 pop bx ; trash argc, argv >> 1Kb !
224 global read_cmdline:near
225 read_cmdline:
226 push di
227 push ax
228 extrn _read:near
229 call near _read
230 pop bx ; fd for close
231 pop si ; si=buffer=argv
232 add di,ax
233 pop ax ; trash sizemax=argv
234 extrn close:near
235 call near close
236 jmp argbuild
237 argend:
238 endif
240 ;***************************************************************
241 extrn _main:near
242 call _main
244 ;***************************************************************
245 global exit:near
246 exit:
247 mov ah,4Ch
248 int 21h
249 ends _TEXT
251 segment _DATA byte public use16 'DATA'
252 global _data_start:byte
253 label _data_start byte
254 ifndef NO386
255 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
256 endif
257 global _vcpi:byte
258 _vcpi db 0
259 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
261 ends _DATA
263 segment _BSS byte public use16 'BSS'
264 global _bss_start:byte
265 label _bss_start byte
266 ifdef EXTRA
267 global _cpu_features:dword
268 _cpu_features dd ?
269 endif
270 ends _BSS
272 end _text_start
274 ;###### END OF FILE ############################################