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