wok view syslinux/stuff/iso2exe/bootiso.S @ rev 13972

syslinux/iso2exe: add win32 stub
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 05 23:32:17 2013 +0100 (2013-02-05)
parents 3d4df3952952
children e487d594117f
line source
1 .text
2 .code16
3 .org 0
5 CODESZ = 0x8000 // 16 sectors = 32Kb
6 #define EXEADRS(x) x+0xC0
7 #define EXESTR(x) x-0x40
9 .globl _start
10 _start:
11 decw %bp // Magic number: MZ
12 popw %dx
13 jmp start0 // Bytes on last page of file
14 .word (CODESZ+511)/512 // Pages in file
15 .word 0 // Relocations
16 .word (end_header-_start)/16 // Size of header in paragraphs
17 .word 4064-(CODESZ/16) // Minimum extra paragraphs needed
18 .word 4064-(CODESZ/16) // Maximum extra paragraphs needed
19 .word 0xFFF0 // Initial (relative) SS value
20 .word 0xFFFE // Initial SP value
21 .word 0 // Checksum
22 .word EXEADRS(exestart) // Initial IP value
23 .word 0xFFF0 // Initial (relative) CS value
24 initramfssize:
25 .word 0 // File address of relocation table
26 id:
27 .word 0 // Overlay number
29 /////////////////////// Master Boot Record code //////////////////////////////
31 start0: // File address of relocation table
32 pushw %dx // restore SP
33 incw %bp // restore %bp
34 pushw $0
35 popw %ds
36 movw $0x7C00, %bx
37 pushfw
38 pushw %ds
39 pushw %bx
40 pushaw
41 movw %sp, %bp
42 pushw %es
43 cld
44 pushw %ds
45 popw %es
46 call setreg
47 rep
48 movsw
49 movw $0x80, %dx
50 ljmp $0, $0x0600+start2
52 .org 60
53 .long 0 // PE header offset
54 end_header:
55 chksum:
56 .word 0
57 comstart:
58 .word 0
60 readsector2:
61 incw %cx
62 readsector1:
63 movw %cx, (%bx)
64 incw %cx
65 movw $0x201, %ax
66 int $0x13
67 setreg:
68 movw %bx, %si
69 movw $0x0600, %di
70 movw $0x0100, %cx
71 return:
72 ret
73 start2:
74 dxloop:
75 call readsector1
76 repe
77 cmpsw
78 je dxfound
79 next:
80 xorw %cx, %cx
81 xchgw %ax, %dx
82 addb $0x7D, %al // try every hard disk
83 andb $0x83, %al // and floppy disk
84 cmpb $0x80, %al
85 xchgw %ax, %dx
86 jnz dxloop
87 fail:
88 movw $0x0600+noloader, %si
89 call putslp
90 stop:
91 hlt
92 jmp stop
93 dxfound:
94 movw %dx, 10(%bp)
95 call readsector2
96 lodsw
97 shrw $1, %ax
98 jz fail // read fail or not isohydrid
99 popw %es
100 popa
101 iret
104 ////////////////////////////// DOS EXE code ///////////////////////////////////
106 help:
107 .ascii "SliTaz GNU/L" // SliTaz GNU/Linux boot loader
108 .byte EXESTR(iloader)
109 no386:
110 .ascii "No 386" // No 386+
111 .byte EXESTR(plus)
112 ERRvcpi:
113 .ascii "No EMM386/VCPI 4" // No EMM386/VCPI 4.0+
114 .byte EXESTR(dot0)
115 chkerr:
116 .ascii "Broken ISO image fil" // Broken ISO image file.
117 .byte EXESTR(eeol)
118 vm86modemsg:
119 .ascii "vm86" // vm86 mode.
120 .byte EXESTR(mode)
121 rmPaging:
122 .ascii "Invalid: paging + " // Invalid: paging + real mode.
123 realmodemsg:
124 .ascii "real" // real mode.
125 // --------------- Must be in 00C0 013F range ------------------------
126 mode:
127 .ascii " mod"
128 eeol:
129 .ascii "e"
130 .byte EXESTR(eol)
131 noloader:
132 .ascii "No isol" // No isolinux boot loader
133 iloader:
134 .ascii "inux boot loader"
135 eol:
136 .ascii "."
137 eol2:
138 .asciz "\r\n"
139 noDOS3:
140 .ascii "No DOS 3" // No DOS 3.0+
141 dot0:
142 .ascii ".0"
143 plus:
144 .ascii "+"
145 .byte EXESTR(eol2)
146 // -------------------------------------------------------------------
148 exestart:
149 cld
150 movw $0x100, %si
151 movw -127(%si), %ax
152 cwd // clear dx
153 pushw %dx // dos exit
154 cmpw $0x2F20, %ax
155 movw $0x1000+EXESTR(help), %ax
156 je abort
157 pushfw // save flags
158 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
159 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
160 // movb $0x10, %ah
161 pushw %ax
162 popfw // < 286 : flags[12..15] are forced 1
163 pushfw // = 286 : flags[12..15] are forced 0
164 popw %cx // > 286 : only flags[15] is forced 0
165 popfw // restore flags
166 addb %ah, %ch // test F0 and 00 cases
167 cmpb %ah, %ch
168 movb $EXESTR(no386), %al
169 jbe abort // C=8086/80186, Z=80286
170 #if 1
171 movw (%si), %cx
172 jcxz is386
173 #endif
174 movw $0x7FE0/2, %cx
175 chklp:
176 lodsw
177 addw %ax, %dx
178 loop chklp
179 movb $EXESTR(chkerr), %al
180 je is386 // dx == 0 ?
181 abort:
182 puts:
183 movb $1, %ah
184 xchgw %ax, %si
185 putslp:
186 lodsb
187 orb %al, %al
188 jz moveret
189 js puts
190 movw $7, %bx
191 movb $0xE, %ah
192 int $0x10
193 jmp putslp
195 is386:
196 movl %cr0, %eax
197 andb $1, %al
198 jne tstvcpi
199 shll $1, %eax
200 movb $EXESTR(rmPaging), %al
201 jc abort
202 movb $EXESTR(realmodemsg), %al
203 realmode:
204 call puts
205 movb $0x30, %ah
206 int $0x21
207 cmpb $3, %al
208 movb $EXESTR(noDOS3), %al
209 jb abort
210 movw EXEADRS(comstart), %ax // .com address
211 movw $moveend-move, %cx
212 movw $EXEADRS(move), %si
213 movw $0xC000, %di
214 jmp move2
215 move:
216 movb $0x80, %ch
217 xchgw %ax, %si
218 movw $0x0100, %di
219 move2:
220 pushw %di
221 rep
222 movsb
223 moveret:
224 ret
225 moveend:
227 VersionVCPI:
228 cmpb $0x40, %dl // >= 4.0 ?
229 jb NoVCPI
230 movb $EXESTR(vm86modemsg), %al
231 jmp realmode
232 tstvcpi:
233 pushw %ds
234 movw %cx, %ds // %cx = 0
235 movw 0x67*4+2, %ds
236 movw $10, %si
237 lodsw
238 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
239 xchgw %ax, %dx
240 lodsw // si += 2
241 lodsw
242 xorw $0x5858, %ax // XX
243 orw %ax, %dx
244 lodsw
245 popw %ds
246 xorw $0x3058, %ax // X0
247 orw %ax, %dx
248 movw $EXEADRS(CmdVCPI), %si
249 ChkVCPI:
250 NoVCPI:
251 xchgw %ax, %dx
252 movb $EXESTR(ERRvcpi), %al
253 jne abort
254 lodsb
255 shlw $8, %ax
256 je VersionVCPI
257 int $0x67
258 testb %ah, %ah
259 jmp ChkVCPI
260 CmdVCPI:
261 .byte 0x40 // status
262 .byte 0xDE // vcpi present ?
263 .byte 0x46 // version
264 .byte 0
266 .org 440
267 //////////////////////////// partition table //////////////////////////////////