wok view linld/stuff/src/_BEG.ASM @ rev 19825
linld/tazboot: can boot memtest & ipxe
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Mar 05 13:22:08 2017 +0100 (2017-03-05) |
parents | 76087975885f |
children | 7c4116e3377f |
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 pushf
39 mov bh, 0F0h
40 push bx ; < 286 : flags[12..15] are forced 1
41 popf ; = 286 : flags[12..15] are forced 0
42 pushf ; > 286 : only flags[15] is forced 0
43 pop dx
44 popf
45 add dh,bh ; NS=386+, NC=286
46 mov bx,offset msg_badcpu
47 ifndef NO386
48 js no_vcpi ;it is a 86/186/286, not a 386+
49 else
50 js endcpu
51 endif
52 p386
53 ifdef EXTRA
54 pushfd
55 pop dx
56 pop ax
57 mov bl,al
58 xor al,20h ; toggle CPUID feature bit 21
59 push ax
60 push dx
61 popfd
62 pushfd
63 pop dx
64 pop ax
65 xor al,bl ; clear C
66 je @@check_vm ; CPUID feature bit changed ?
67 mov eax,80000001h ; Extended Processor Info and Feature Bits
68 cpuid
69 mov [_cpu_features],edx
70 @@check_vm:
71 endif
72 ; Check for vm
73 smsw ax ;SMSW cannot be trapped! :-)
74 and al,1 ;MSW_PE
75 ; We're in vm
76 jz check_rm_paging
78 ;***************************************************************
79 ; checks for vcpi
80 ;***************************************************************
81 label check_vcpi near
82 push ds
83 ; Check whether it is safe to call 67h (we trust only known EMM managers)
84 xor bx,bx
85 push bx
86 pop ds
87 mov ds,[word 67h*4+2]
88 cmp [dword bx+10+4],'0XXX'
89 jne skip
90 ;mov eax,'XMME'
91 ;xor eax,[dword bx+10]
92 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
93 ;shl eax,8
94 mov ax,'ME'
95 xor ax,[word bx+10]
96 skip:
97 pop ds
98 jne no_vcpi
100 ; Check emm manager status and version
101 ;mov ah,40h ; get status
102 ;int 67h
103 ;test ah,ah
104 ;jnz no_vcpi
105 mov ah,46h ; get version
106 int 67h
107 test ah,ah
108 jnz no_vcpi
109 cmp al,40h ; version must be >= 4.0
110 jb no_vcpi
111 ; Check vcpi manager status
112 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
113 ;;mov bx,4
114 ;;int 67h
115 ;;test ah,ah
116 ;;jnz no_vcpi
117 ;;push dx ;$ save handle
118 mov ax,0DE00h ; check for vcpi present
119 int 67h
120 test ah,ah
121 jnz no_vcpi
122 is386vcpi:
123 inc [_vcpi]
124 extrn prepare_vcpi:near
125 call prepare_vcpi
126 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
127 ;extrn _get_vcpi_interface:near
128 ;call _get_vcpi_interface
129 mov bx,offset msg_badmapping
130 jz endcpu
131 no_vcpi:
132 p8086
133 ;;pop dx ;$ handle
134 ;;mov ax,4500h ; DEALLOCATE PAGES
135 ;;int 67h
136 extrn die:near
137 godie:
138 jmp near die
139 check_rm_paging:
140 ; It's a 386 in real mode, chk for paging (crazy but possible)
141 p386
142 mov edx,cr0
143 shl edx,1 ;CR0_PG to CF
144 jc no_vcpi
145 endcpu:
146 p8086
148 ;***************************************************************
149 ; build argv & argc
150 ;***************************************************************
151 extrn _heap_top:word
152 mov di,[_heap_top]
153 ;xor ax,ax
154 ;push ax ; envp (already cleared)
155 ;mov [word di],ax ; argv[0] = 0 (idem)
156 mov si,80h
157 lodsb
158 cmp al,7Eh
159 jbe alok
160 mov al,7Eh
161 alok:
162 cbw
163 xchg ax,bx
164 mov [bx+si],bh ; set eos
165 argbuild:
166 mov bx,2 ; argc * 2
167 argeos:
168 mov dl,1 ; look for a start of string
169 mov [byte si-1],bh ; mark eos
170 mov ah,20h ; space will be eos
171 arglp:
172 lodsb
173 cmp al,0h
174 je argdone
175 cmp al,20h
176 jb argeos
177 cmp al,ah
178 je argeos
179 cmp al,27h
180 je isargstr
181 cmp al,22h
182 je isargstr
183 or dl,dl
184 je arglp ; not start of string
185 dec si
186 jmp newarg
187 isargstr:
188 mov ah,al ; expected eos
189 newarg:
190 mov [word bx+di],si ; argv[argc++] = si
191 inc bx
192 inc bx
193 dec dx
194 jmp arglp
195 argdone:
196 ;mov [word bx+di],0 ; argv[argc] = 0
197 lea ax,[bx+di+2]
198 mov [_heap_top],ax
199 push di ; argv
200 shr bx,1
201 push bx ; argc
202 ifndef filearg
203 mov bx,[di+2] ; argv[1]
204 cmp [byte bx],'@'
205 jne argend
206 inc bx
207 extrn open:near
208 call near open
209 jc argend
210 pop bx ; trash argc, argv >> 1Kb !
211 global read_cmdline:near
212 read_cmdline:
213 push di
214 push ax
215 extrn _read:near
216 call near _read
217 pop bx ; fd for close
218 pop si ; si=buffer=argv
219 add di,ax
220 pop ax ; trash sizemax=argv
221 extrn close:near
222 call near close
223 jmp argbuild
224 argend:
225 endif
227 ;***************************************************************
228 extrn _main:near
229 call _main
231 ;***************************************************************
232 global exit:near
233 exit:
234 mov ah,4Ch
235 int 21h
236 ends _TEXT
238 segment _DATA byte public use16 'DATA'
239 global _data_start:byte
240 label _data_start byte
241 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
242 global _vcpi:byte
243 _vcpi db 0
244 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
246 ends _DATA
248 segment _BSS byte public use16 'BSS'
249 global _bss_start:byte
250 label _bss_start byte
251 ifdef EXTRA
252 global _cpu_features:dword
253 _cpu_features dd ?
254 endif
255 ends _BSS
257 end _text_start
259 ;###### END OF FILE ############################################