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

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