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

linld: fix puts
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 01 11:21:28 2018 +0100 (2018-01-01)
parents 04feaffdc0d9
children c0625ff5d49b
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 eax,cr0
155 inc eax ;CR0_PG to S
156 js 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 ifdef DEBUG
179 p386
180 pusha
181 mov bx,si
182 extrn puts:near
183 call puts
184 popa
185 endif
186 mov bx,2 ; argc * 2
187 argeos:
188 mov dl,1 ; look for a start of string
189 mov [byte si-1],bh ; mark eos
190 mov ah,20h ; space will be eos
191 arglp:
192 lodsb
193 cmp al,0h
194 je argdone
195 cmp al,20h
196 jb argeos
197 cmp al,ah
198 je argeos
199 cmp al,27h
200 je isargstr
201 cmp al,22h
202 je isargstr
203 or dl,dl
204 je arglp ; not start of string
205 dec si
206 ;jmp newarg
207 db 0B9h ; mov cx,im opcode
208 isargstr:
209 mov ah,al ; expected eos
210 newarg:
211 mov [word bx+di],si ; argv[argc++] = si
212 inc bx
213 inc bx
214 dec dx
215 jmp arglp
216 argdone:
217 ;mov [word bx+di],0 ; argv[argc] = 0
218 lea ax,[bx+di+2]
219 mov [_heap_top],ax
220 push di ; argv
221 shr bx,1
222 push bx ; argc
223 ifndef filearg
224 mov bx,[di+2] ; argv[1]
225 cmp [byte bx],'@'
226 jne argend
227 inc bx
228 extrn open:near
229 call near open
230 jc argend
231 pop bx ; trash argc, argv >> 1Kb !
232 global read_cmdline:near
233 read_cmdline:
234 push di
235 push ax
236 extrn _read:near
237 call near _read
238 pop bx ; fd for close
239 pop si ; si=buffer=argv
240 add di,ax
241 pop ax ; trash sizemax=argv
242 extrn close:near
243 call near close
244 jmp argbuild
245 argend:
246 endif
248 ;***************************************************************
249 extrn _main:near
250 call _main
252 ;***************************************************************
253 global exit:near
254 exit:
255 mov ah,4Ch
256 int 21h
257 ends _TEXT
259 segment _DATA byte public use16 'DATA'
260 global _data_start:byte
261 label _data_start byte
262 ifndef NO386
263 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
264 endif
265 global _vcpi:byte
266 _vcpi db 0
267 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
269 ends _DATA
271 segment _BSS byte public use16 'BSS'
272 global _bss_start:byte
273 label _bss_start byte
274 ifdef EXTRA
275 global _cpu_features:dword
276 _cpu_features dd ?
277 endif
278 ends _BSS
280 end _text_start
282 ;###### END OF FILE ############################################