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

Add python-click python-itsdangerous & python-flask
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Sep 29 15:27:00 2018 +0200 (2018-09-29)
parents f4bc280fe3c4
children 46b511e941a7
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"
25 global _topmem:dword
26 _topmem dd 10000000h ; max 256m
28 ends _DATA
30 segment _BSS byte public use16 'BSS'
31 global _bss_start:byte
32 label _bss_start byte
33 ifdef EXTRA
34 global _cpu_features:dword
35 _cpu_features dd ?
36 endif
37 ends _BSS
39 segment _TEXT byte public use16 'CODE'
41 macro cpuid
42 db 0fh,0A2h
43 endm
45 org 100h
46 global _text_start:byte
47 label _text_start byte
49 ;***************************************************************
50 ; clear bss
51 ;***************************************************************
52 mov si,offset _bss_start
53 mov bx, 0F000h ; cld ; cli
54 clearbss:
55 mov [si],bl ; clear bss + heap + sp
56 inc si
57 jne clearbss
59 ;***************************************************************
60 ; check CPU
61 ;***************************************************************
63 ; Check for oldies
64 push bx ; < 286 : flags[12..15] are forced 1
65 popf ; = 286 : flags[12..15] are forced 0
66 pushf ; > 286 : only flags[15] is forced 0
67 pop dx
68 add dh,bh ; NS=386+, S+NC=286, S+C=86/186
69 ifndef NO386
70 mov bx,offset msg_badcpu
71 js no_vcpi ;it is not a 386+
72 else
73 js endcpu ;it is not a 386+
74 endif
75 p386
76 ifdef EXTRA
77 pushfd
78 pop dx
79 pop ax
80 mov bl,al
81 xor al,20h ; toggle CPUID feature bit 21
82 push ax
83 push dx
84 popfd
85 pushfd
86 pop dx
87 pop ax
88 xor al,bl ; clear C
89 je @@check_vm ; CPUID feature bit changed ?
90 mov eax,80000001h ; Extended Processor Info and Feature Bits
91 cpuid
92 mov [_cpu_features],edx
93 @@check_vm:
94 endif
95 ; Check for vm
96 smsw ax ;SMSW cannot be trapped! :-)
97 and al,1 ;MSW_PE
98 ; We're in vm
99 jz check_rm_paging
101 ;***************************************************************
102 ; checks for vcpi
103 ;***************************************************************
104 label check_vcpi near
105 push ds
106 ; Check whether it is safe to call 67h (we trust only known EMM managers)
107 push si
108 pop ds
109 mov ds,[word 67h*4+2]
110 cmp [dword si+10+4],'0XXX'
111 jne skip
112 ;mov eax,'XMME'
113 ;xor eax,[dword si+10]
114 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
115 ;shl eax,8
116 mov ax,'ME'
117 xor ax,[word si+10]
118 skip:
119 pop ds
120 jne no_vcpi
122 ; Check emm manager status and version
123 ;mov ah,40h ; get status
124 ;int 67h
125 ;test ah,ah
126 ;jnz no_vcpi
127 mov ah,46h ; get version
128 int 67h
129 test ah,ah
130 jnz no_vcpi
131 cmp al,40h ; version must be >= 4.0
132 jb no_vcpi
133 ; Check vcpi manager status
134 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
135 ;;mov bx,4
136 ;;int 67h
137 ;;test ah,ah
138 ;;jnz no_vcpi
139 ;;push dx ;$ save handle
140 mov ax,0DE00h ; check for vcpi present
141 int 67h
142 test ah,ah
143 jnz no_vcpi
144 is386vcpi:
145 extrn prepare_vcpi:near
146 call prepare_vcpi
147 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
148 ;extrn _get_vcpi_interface:near
149 ;call _get_vcpi_interface
150 mov bx,offset msg_badmapping
151 jz endcpu
152 inc [byte bx+_vcpi-msg_badmapping]
153 no_vcpi:
154 p8086
155 ;;pop dx ;$ handle
156 ;;mov ax,4500h ; DEALLOCATE PAGES
157 ;;int 67h
158 extrn die:near
159 godie:
160 call near die
161 check_rm_paging:
162 ; It's a 386 in real mode, chk for paging (crazy but possible)
163 p386
164 mov eax,cr0
165 inc eax ;CR0_PG to S
166 js no_vcpi
167 endcpu:
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 cmp [byte bx],'@'
235 jne argend
236 inc bx
237 extrn open:near
238 call near open
239 jc argend
240 pop bx ; trash argc, argv >> 1Kb !
241 global read_cmdline:near
242 read_cmdline:
243 push di
244 push ax
245 extrn _read:near
246 call near _read
247 pop bx ; fd for close
248 pop si ; si=buffer=argv
249 add di,ax
250 pop ax ; trash sizemax=argv
251 extrn close:near
252 call near close
253 jmp argbuild
254 argend:
255 endif
257 ;***************************************************************
258 extrn _main:near
259 call _main
261 ;***************************************************************
262 global exit:near
263 exit:
264 mov ah,4Ch
265 int 21h
266 ends _TEXT
269 end _text_start
271 ;###### END OF FILE ############################################