wok-current view syslinux/stuff/iso2exe/bootiso.S @ rev 19861
hunspell: typo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Mar 24 15:04:56 2017 +0100 (2017-03-24) |
parents | c281a4009aaa |
children | de17d022fe9c |
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 0x7F4E
181 ////////////////////////////// DOS EXE code ///////////////////////////////////
183 exestart:
184 cld
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 movb $EXESTR(noDOS3), %al
197 movw $0x100, %di
198 jc tst386
199 abort:
200 goputs:
201 jmp puts
203 tst386:
204 pushw %sp
205 popw %ax
206 subw %sp, %ax
207 jnz is86 // 86/186 not a 286+
208 .arch i486
209 is386:
210 smsww %ax // not privileged
211 andb $1, %al
212 movw $10, %si
213 jne tstvcpi
214 movl %cr0, %eax // privileged
215 incl %eax
216 movb $EXESTR(rmPaging), %al
217 js abort
218 inc %ax
219 //movb $EXESTR(realmodemsg), %al
220 realmode:
221 call goputs
222 .arch i8086
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 .arch i486
232 CallVCPI:
233 int $0x67
234 testb %ah, %ah
235 xchgw %ax, %cx
236 pushw %si
237 ScanVCPI:
238 popw %si
239 ChkVCPI:
240 NoVCPI:
241 movb $EXESTR(ERRvcpi), %al
242 jne abort
243 lodsb
244 shlw $8, %ax
245 jne CallVCPI
246 VersionVCPI:
247 xchgw %ax, %si // movb $EXESTR(vm86modemsg), %al
248 cmpb $0x40, %cl // EMM386 / VCPI 4.0 mini
249 jnc realmode // %si = 0
250 tstvcpi:
251 pushw %ds
252 movw %si, %ds // %si = 10
253 movw (0x67*4)+2-(16*10)-0x100(%di), %ds
254 lodsw
255 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
256 lodsw
257 lodsw
258 popw %ds
259 jne NoVCPI
260 xorw $0x5858, %ax // XX(X0)
261 call ScanVCPI
262 CmdVCPI:
263 .byte 0x40 // status
264 .byte 0xDE // vcpi present ?
265 .byte 0x46 // version
266 .byte 0
268 vm86modemsg:
269 // --------------- Must be in 7F40 7FFF range ------------------------
270 .ascii "86" // 86 mode
271 .byte EXESTR(mode)
272 ERRvcpi:
273 .ascii "VCPI4" // VCPI4?
274 .byte EXESTR(need)
275 rmPaging:
276 .ascii "X" // Xreal mode
277 realmodemsg:
278 .ascii "real" // real mode
279 // --------------- Must be in 7FC0 7FFF range ------------------------
280 mode:
281 .ascii " m"
282 ode:
283 .ascii "ode"
284 .byte EXESTR(eol)
285 noDOS3:
286 .ascii "DOS3" // DOS3?
287 need:
288 .ascii "?"
289 .byte EXESTR(eol)
290 help:
291 .ascii "SliTaz iso boot." // SliTaz iso boot.
292 eol:
293 .ascii "\r\n"
294 .byte 1 // puts will return
296 .space 16,0 // ISO md5
297 .org 0x8000
298 ////////////////////////// ISO9660 header /////////////////////////////////////