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

linld: check asm instructions again processor type
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 20 09:55:25 2017 +0100 (2017-01-20)
parents 38eb1fe036b4
children 6f494adb2c71
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 org 100h
16 global _text_start:byte
17 label _text_start byte
19 ;***************************************************************
20 ; clear bss
21 ;***************************************************************
22 mov bx,offset _bss_start
23 clearbss:
24 mov [byte bx],0 ; clear bss + heap + sp
25 inc bx
26 jne clearbss
27 cld
29 ;***************************************************************
30 ; check CPU
31 ;***************************************************************
33 ; Check for oldies
34 pushf
35 mov bh, 0F0h
36 push bx ; < 286 : flags[12..15] are forced 1
37 popf ; = 286 : flags[12..15] are forced 0
38 pushf ; > 286 : only flags[15] is forced 0
39 pop dx
40 popf
41 add dh,bh ; NS=386+, NC=286
42 mov bx,offset msg_badcpu
43 ifndef NO386
44 js no_vcpi ;it is a 86/186/286, not a 386+
45 else
46 js endcpu
47 endif
48 p386
49 ; Check for vm
50 smsw ax ;SMSW cannot be trapped! :-)
51 and al,1 ;MSW_PE
52 ; We're in vm
53 jz check_rm_paging
55 ;***************************************************************
56 ; checks for vcpi
57 ;***************************************************************
58 label check_vcpi near
59 push ds
60 ; Check whether it is safe to call 67h (we trust only known EMM managers)
61 push 0
62 pop ds
63 mov ds,[word 67h*4+2]
64 cmp [dword 10+4],'0XXX'
65 jne skip
66 mov eax,'XMME'
67 xor eax,[dword 10]
68 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
69 shl eax,8
70 skip:
71 pop ds
72 jne no_vcpi
74 ; Check emm manager status and version
75 ;mov ah,40h ; get status
76 ;int 67h
77 ;test ah,ah
78 ;jnz no_vcpi
79 mov ah,46h ; get version
80 int 67h
81 test ah,ah
82 jnz no_vcpi
83 cmp al,40h ; version must be >= 4.0
84 jb no_vcpi
85 ; Check vcpi manager status
86 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
87 ;;mov bx,4
88 ;;int 67h
89 ;;test ah,ah
90 ;;jnz no_vcpi
91 ;;push dx ;$ save handle
92 mov ax,0DE00h ; check for vcpi present
93 int 67h
94 test ah,ah
95 jnz no_vcpi
96 is386vcpi:
97 inc [_vcpi]
98 extrn prepare_vcpi:near
99 call prepare_vcpi
100 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
101 ;extrn _get_vcpi_interface:near
102 ;call _get_vcpi_interface
103 mov bx,offset msg_badmapping
104 jz endcpu
105 no_vcpi:
106 p8086
107 ;;pop dx ;$ handle
108 ;;mov ax,4500h ; DEALLOCATE PAGES
109 ;;int 67h
110 extrn die:near
111 godie:
112 jmp near die
113 check_rm_paging:
114 ; It's a 386 in real mode, chk for paging (crazy but possible)
115 p386
116 mov edx,cr0
117 shl edx,1 ;CR0_PG to CF
118 jc no_vcpi
119 endcpu:
120 p8086
122 ;***************************************************************
123 ; build argv & argc
124 ;***************************************************************
125 extrn _heap_top:word
126 mov di,[_heap_top]
127 ;xor ax,ax
128 ;push ax ; envp (already cleared)
129 ;mov [word di],ax ; argv[0] = 0 (idem)
130 mov si,80h
131 lodsb
132 cmp al,7Eh
133 jbe alok
134 mov al,7Eh
135 alok:
136 cbw
137 xchg ax,bx
138 mov [bx+si],bh ; set eos
139 argbuild:
140 mov bx,2 ; argc * 2
141 argeos:
142 mov dl,1 ; look for a start of string
143 mov [byte si-1],bh ; mark eos
144 mov ah,20h ; space will be eos
145 arglp:
146 lodsb
147 cmp al,0h
148 je argdone
149 cmp al,20h
150 jb argeos
151 cmp al,ah
152 je argeos
153 cmp al,27h
154 je isargstr
155 cmp al,22h
156 je isargstr
157 or dl,dl
158 je arglp ; not start of string
159 dec si
160 jmp newarg
161 isargstr:
162 mov ah,al ; expected eos
163 newarg:
164 mov [word bx+di],si ; argv[argc++] = si
165 inc bx
166 inc bx
167 dec dx
168 jmp arglp
169 argdone:
170 ;mov [word bx+di],0 ; argv[argc] = 0
171 lea ax,[bx+di+2]
172 mov [_heap_top],ax
173 push di ; argv
174 shr bx,1
175 push bx ; argc
176 ifndef filearg
177 mov bx,[di+2] ; argv[1]
178 cmp [byte bx],'@'
179 jne argend
180 inc bx
181 extrn open:near
182 call near open
183 jc argend
184 pop bx ; trash argc, argv >> 1Kb !
185 global read_cmdline:near
186 read_cmdline:
187 push di
188 push ax
189 extrn _read:near
190 call near _read
191 pop bx ; fd for close
192 pop si ; si=buffer=argv
193 add di,ax
194 pop ax ; trash sizemax=argv
195 extrn close:near
196 call near close
197 jmp argbuild
198 argend:
199 endif
201 ;***************************************************************
202 extrn _main:near
203 call _main
205 ;***************************************************************
206 global exit:near
207 exit:
208 mov ah,4Ch
209 int 21h
210 ends _TEXT
212 segment _DATA byte public use16 'DATA'
213 global _data_start:byte
214 label _data_start byte
215 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
216 global _vcpi:byte
217 _vcpi db 0
218 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
220 ends _DATA
222 segment _BSS byte public use16 'BSS'
223 global _bss_start:byte
224 label _bss_start byte
225 ends _BSS
227 end _text_start
229 ;###### END OF FILE ############################################