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

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