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

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