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

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