wok view syslinux/stuff/iso2exe/bootiso.S @ rev 19842
gitso: update wget_url
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Mar 13 12:09:18 2017 +0100 (2017-03-13) |
parents | 658ada1dde7e |
children | 3378a0c35726 |
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 DS=SS BX=7C00 CH=01 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 %si
136 xchgw %si,%di
137 call movepartition
138 pushw %cx
139 pushw %cx
140 decw %di
141 decw %di
142 movb $4,%cl
143 movw $16,%ax
144 next:
145 subw %ax,%di
146 cmpb %ch,(%di) // boot flag ?
147 loope next
148 pushw 10(%di)
149 pushw 8(%di)
150 pushw %cs
151 pushw %bx
152 movb $1,%cl
153 pushw %cx
154 pushw %ax
155 movw %sp,%si // assume %ds = %ss
156 pushw %bx
157 cmpw $63,2(%di) // empty or isolinux partition ?
158 jbe default
159 movb $0x42,%ah
160 int $0x13
161 default:
162 ret
163 .org 0x7DF0
164 bootpartition:
165 pushw %ds
166 popw %es
167 pushw %si
168 movw %bx,%di
169 movsw
170 movsb
171 movw $table-0x142,%di
172 pushw %di
173 movepartition:
174 movb $66,%cl // 0142 and 0042
175 rep
176 movsb
177 ret
178 .org 0x7E00
180 .org 0x7F48
181 ////////////////////////////// DOS EXE code ///////////////////////////////////
183 exestart:
184 cld
185 movw $EXEADRS(puts), %bp
186 movw 129, %ax
187 cmpb $0x2F, %al
188 je ishelp
189 cmpw $0x2F20, %ax
190 ishelp:
191 movw $0x3000+EXESTR(help), %ax
192 cwd // clear dx
193 pushw %dx // dos exit()
194 je abort
195 int $0x21 // get DOS version
196 addb $-3, %al
197 movw $0xF000+EXESTR(noDOS3), %ax
198 movw $0x100, %di
199 jc tst386
200 abort:
201 jmp *%bp
203 tst386:
204 pushfw // save flags
205 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
206 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
207 // movb $0xF0, %ah
208 pushw %ax
209 popfw // < 286 : flags[12..15] are forced 1
210 pushfw // = 286 : flags[12..15] are forced 0
211 popw %bx // > 286 : only flags[15] is forced 0
212 popfw // restore flags (IOPL)
213 addb %ah, %bh // test F0 and 00 cases
214 js is86 // NS=386+, NC=286
215 .arch i486
216 is386:
217 smsww %ax // not privileged
218 andb $1, %al
219 movw $10, %si
220 jne tstvcpi
221 movl %cr0, %eax // privileged
222 incl %eax
223 movb $EXESTR(rmPaging), %al
224 js abort
225 inc %ax
226 //movb $EXESTR(realmodemsg), %al
227 realmode:
228 call *%bp
229 .arch i8086
230 is86:
231 movw comstart-end_header(%di), %si // .com address
232 pushw %di
233 movb $0x7C/2, %ch // 31K-31.5K, > com length
234 rep
235 movsw
236 ret
238 .arch i486
239 CallVCPI:
240 int $0x67
241 testb %ah, %ah
242 xchgw %ax, %cx
243 pushw %si
244 ScanVCPI:
245 popw %si
246 ChkVCPI:
247 NoVCPI:
248 movb $EXESTR(ERRvcpi), %al
249 jne abort
250 lodsb
251 shlw $8, %ax
252 jne CallVCPI
253 VersionVCPI:
254 xchgw %ax, %si // movb $EXESTR(vm86modemsg), %al
255 cmpb $0x40, %cl // EMM386 / VCPI 4.0 mini
256 jnc realmode // %si = 0
257 tstvcpi:
258 pushw %ds
259 movw %si, %ds // %si = 10
260 movw (0x67*4)+2-(16*10)-0x100(%di), %ds
261 lodsw
262 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
263 lodsw
264 lodsw
265 popw %ds
266 jne NoVCPI
267 xorw $0x5858, %ax // XX(X0)
268 call ScanVCPI
269 CmdVCPI:
270 .byte 0x40 // status
271 .byte 0xDE // vcpi present ?
272 .byte 0x46 // version
273 .byte 0
275 vm86modemsg:
276 // --------------- Must be in 7F40 7FFF range ------------------------
277 .ascii "86" // 86 mode
278 .byte EXESTR(mode)
279 ERRvcpi:
280 .ascii "VCPI4" // VCPI4?
281 .byte EXESTR(need)
282 rmPaging:
283 .ascii "X" // Xreal mode
284 realmodemsg:
285 .ascii "real" // real mode
286 // --------------- Must be in 7FC0 7FFF range ------------------------
287 mode:
288 .ascii " m"
289 ode:
290 .ascii "ode"
291 .byte EXESTR(eol)
292 noDOS3:
293 .ascii "DOS3" // DOS3?
294 need:
295 .ascii "?"
296 .byte EXESTR(eol)
297 help:
298 .ascii "SliTaz iso boot." // SliTaz iso boot.
299 eol:
300 .ascii "\r\n"
301 .byte 1 // puts will return
303 .space 16,0 // ISO md5
304 .org 0x8000
305 ////////////////////////// ISO9660 header /////////////////////////////////////