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

syslinux/iso2exe: follow boot flag (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 09 09:54:22 2017 +0100 (2017-03-09)
parents e619bff66a02
children 658ada1dde7e
line source
1 .text
2 .code16
3 .arch i8086
4 .org 0
6 CODESZ = 0x8000 // 16 sectors = 32Kb
7 #define EXEADRS(x) x+0xC0
8 #define EXELOC(x) x-0x40
9 #define EXESTR(x) x-0x7F40
11 .globl _start
12 _start:
13 decw %bp // Magic number: MZ
14 popw %dx
15 jmp start0 // Bytes on last page of file
16 .word (CODESZ+511)/512 // Pages in file
17 .word 0 // Relocations
18 .word (end_header-_start)/16 // Size of header in paragraphs
19 .word 4064-(CODESZ/16) // Minimum extra paragraphs needed
20 .word 4064-(CODESZ/16) // Maximum extra paragraphs needed
21 .word 0xFFF0 // Initial (relative) SS value
22 .word 0xFFFE // Initial SP value
23 .word 0 // Checksum
24 .word EXEADRS(exestart) // Initial IP value
25 .word 0xFFF0 // Initial (relative) CS value
26 initramfssize:
27 .word 0 // File address of relocation table
28 fdcnt: // Overlay number
29 .byte 0 // Bootstrap floppy sector count
30 .ascii "slitaz"
32 /////////////////////// Master Boot Record code //////////////////////////////
34 moved = 0x8000
35 start0:
36 //pushw %dx // restore %sp
37 //incw %bp // restore %bp
38 xorw %bx, %bx
39 movw %bx, %ds
40 movb $0x7C, %bh
41 pushw %ds
42 popw %ss
43 movw %bx, %sp
44 pushw %bx // return address
45 pushw %di
46 pushw %es // save %es:%di
47 cld
48 sti
49 pushw %ds
50 popw %es
51 call setreg
52 rep
53 movsw
54 movw $0x80, %dx
55 ljmp $0, $moved+start2
56 .byte 0
57 // .org 60
58 // .long 0x0080 // PE header offset
59 .org 64
60 end_header:
61 comstart:
62 .word 0
64 .org 66
65 dxloop:
66 start2:
67 call readsector1 // look for the boot device
68 repe
69 cmpsw
70 je dxfound
71 movb $0, %cl // ch = 0
72 addb $0x7D, %dl // try every hard disk
73 jno dxloop
75 dxfound:
76 call readsectorX // read isolinux boot sector
77 cmpw (%bx), %cx
78 jnc puts // read fail or no isohydrid boot sector
79 movw $patch,%si
80 popw %es
81 popw %di // isolinux boot needs %es:%di and %dx
82 putsret:
83 ret
85 putstrlp:
86 movw $7, %bx
87 movb $0xE, %ah
88 int $0x10
89 error:
90 lodsb
91 cmp $1, %al
92 jg putstrlp
93 jz putsret
94 puts:
95 movb $0x80, %ah
96 xchgw %ax, %si
97 jnc error
98 halt:
99 hlt
100 jmp halt
101 nobsmsg:
102 .asciz "No isolinux."
104 .org 0x0080
105 ////////////////////////////// EXE/PE header //////////////////////////////////
107 .org 0x01A0
108 readsectorX: // read isolinux boot sector
109 movb $0xA5, %cl // patched by installer
110 readsector1:
111 andb $0x83, %dl // disk and floppy disk
112 movw %cx, (%bx)
113 incw %cx
114 movw $0x201, %ax
115 int $0x13
116 setreg:
117 movw %bx, %si
118 movw $moved, %di
119 movw $0x0100, %cx
120 movb $nobsmsg, %al
121 ret
122 .org 0x01B8
124 ////////////////////////// partition boot code ////////////////////////////////
125 // assume CS=DS=SS=0 AH=00 BX=7C00 CX=0100 DL=<drive> SI=7DBE
127 .org 0x7C00
128 jmp bootpartition
129 .org 0x7C03
130 .org 0x7DBE
131 table = moved+0x1BE
132 patch:
133 .byte 0,0,0 // head of original bs
134 partcode:
135 popw %di
136 movw $table,%si
137 call movepartition
138 movw $patch-16,%di
139 movb $4,%cl
140 movb $16,%al
141 next:
142 addw %ax,%di
143 cmpb %ch,(%di) // boot flag ?
144 loope next
145 pushw %ds
146 pushw %ds
147 pushw 10(%di)
148 pushw 8(%di)
149 pushw %ds
150 pushw %bx
151 movb $1,%cl
152 pushw %cx
153 pushw %ax
154 movw %sp,%si // assume %ds = %ss
155 pushw %bx
156 cmpw %ax,2(%di) // empty or isolinux partition ?
157 jbe default
158 movb $0x42,%ah
159 int $0x13
160 default:
161 ret
162 .org 0x7DF0
163 bootpartition:
164 pushw %ds
165 popw %es
166 pushw %si
167 movw %bx,%di
168 movsw
169 movsb
170 movw $0x7E00,%di
171 pushw %di
172 movepartition:
173 movb $66,%cl // 0142 and 0042
174 rep
175 movsb
176 ret
177 .org 0x7E00
179 .org 0x7F48
180 ////////////////////////////// DOS EXE code ///////////////////////////////////
182 exestart:
183 cld
184 movw $EXEADRS(puts), %bp
185 movw 129, %ax
186 cmpb $0x2F, %al
187 je ishelp
188 cmpw $0x2F20, %ax
189 ishelp:
190 movw $0x3000+EXESTR(help), %ax
191 cwd // clear dx
192 pushw %dx // dos exit()
193 je abort
194 int $0x21 // get DOS version
195 addb $-3, %al
196 movw $0xF000+EXESTR(noDOS3), %ax
197 movw $0x100, %di
198 jc tst386
199 abort:
200 jmp *%bp
202 tst386:
203 pushfw // save flags
204 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
205 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
206 // movb $0xF0, %ah
207 pushw %ax
208 popfw // < 286 : flags[12..15] are forced 1
209 pushfw // = 286 : flags[12..15] are forced 0
210 popw %bx // > 286 : only flags[15] is forced 0
211 popfw // restore flags (IOPL)
212 addb %ah, %bh // test F0 and 00 cases
213 js is86 // NS=386+, NC=286
214 .arch i486
215 is386:
216 smsww %ax // not privileged
217 andb $1, %al
218 movw $10, %si
219 jne tstvcpi
220 movl %cr0, %eax // privileged
221 incl %eax
222 movb $EXESTR(rmPaging), %al
223 js abort
224 inc %ax
225 //movb $EXESTR(realmodemsg), %al
226 realmode:
227 call *%bp
228 .arch i8086
229 is86:
230 movw comstart-end_header(%di), %si // .com address
231 pushw %di
232 movb $0x7C/2, %ch // 31K-31.5K, > com length
233 rep
234 movsw
235 ret
237 .arch i486
238 CallVCPI:
239 int $0x67
240 testb %ah, %ah
241 xchgw %ax, %cx
242 pushw %si
243 ScanVCPI:
244 popw %si
245 ChkVCPI:
246 NoVCPI:
247 movb $EXESTR(ERRvcpi), %al
248 jne abort
249 lodsb
250 shlw $8, %ax
251 jne CallVCPI
252 VersionVCPI:
253 xchgw %ax, %si // movb $EXESTR(vm86modemsg), %al
254 cmpb $0x40, %cl // EMM386 / VCPI 4.0 mini
255 jnc realmode // %si = 0
256 tstvcpi:
257 pushw %ds
258 movw %si, %ds // %si = 10
259 movw (0x67*4)+2-(16*10)-0x100(%di), %ds
260 lodsw
261 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
262 lodsw
263 lodsw
264 popw %ds
265 jne NoVCPI
266 xorw $0x5858, %ax // XX(X0)
267 call ScanVCPI
268 CmdVCPI:
269 .byte 0x40 // status
270 .byte 0xDE // vcpi present ?
271 .byte 0x46 // version
272 .byte 0
274 vm86modemsg:
275 // --------------- Must be in 7F40 7FFF range ------------------------
276 .ascii "86" // 86 mode
277 .byte EXESTR(mode)
278 ERRvcpi:
279 .ascii "VCPI4" // VCPI4?
280 .byte EXESTR(need)
281 rmPaging:
282 .ascii "X" // Xreal mode
283 realmodemsg:
284 .ascii "real" // real mode
285 // --------------- Must be in 7FC0 7FFF range ------------------------
286 mode:
287 .ascii " m"
288 ode:
289 .ascii "ode"
290 .byte EXESTR(eol)
291 noDOS3:
292 .ascii "DOS3" // DOS3?
293 need:
294 .ascii "?"
295 .byte EXESTR(eol)
296 help:
297 .ascii "SliTaz iso boot." // SliTaz iso boot.
298 eol:
299 .ascii "\r\n"
300 .byte 1 // puts will return
302 .space 16,0 // ISO md5
303 .org 0x8000
304 ////////////////////////// ISO9660 header /////////////////////////////////////