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

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