wok-current view syslinux/stuff/iso2exe/bootiso.S @ rev 13699

syslinux/iso2exe: only DOS 3, 4 and 6 supported :-/
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 15 13:43:51 2012 +0100 (2012-12-15)
parents d47403fdd900
children 9d2380009b81
line source
1 .text
2 .code16
3 .org 0
5 CODESZ = 0x8000 // 16 sectors = 32Kb
6 #define EXEADRS(x) x+0xE0
7 #define EXESTR(x) x-0x20
9 .globl _start
10 _start:
11 decw %bp // Magic number: MZ
12 popw %dx
13 jmp start // 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(fixseg) // Initial IP value
23 .word 0xFFF0 // Initial (relative) CS value
24 .word 0x001C // File address of relocation table
25 .word 0 // Overlay number
26 initramfssize:
27 .word 0
28 id:
29 .word 0
30 end_header:
32 chksum:
33 .word 0
34 comstart:
35 .word 0
37 /////////////////////// Master Boot Record code //////////////////////////////
39 start:
40 incw %bp
41 pushw %dx // restore SP
42 pushaw
43 movw %sp, %bp
44 pushf
45 pushw %ds
46 pushw %es
47 call setreg
48 rep
49 movsw
50 ljmp $0, $0x0600+start2
52 readsector2:
53 incw %cx
54 readsector1:
55 movw %cx, (%bx)
56 incw %cx
57 movw $0x201, %ax
58 int $0x13
59 setreg:
60 cld
61 xorw %bx, %bx // Clear C
62 movw %bx, %ds
63 movw %bx, %es
64 movb $0x7C, %bh
65 movw %bx, %si
66 movw $0x0600, %di
67 movw $0x0100, %cx
68 return:
69 ret
70 start2:
71 movw $0x80, %dx
72 dxloop:
73 call readsector1
74 repe
75 cmpsw
76 je dxfound
77 next:
78 xorw %cx, %cx
79 xchgw %ax, %dx
80 addb $0x7D, %al // try every hard disk
81 andb $0x83, %al // and floppy disk
82 cmpb $0x80, %al
83 xchgw %ax, %dx
84 jnz dxloop
85 fail:
86 int $0x19
87 dxfound:
88 movw %dx, 10(%bp)
89 call readsector2
90 lodsw
91 decw %ax
92 jz fail // read fail or not isohydrid
93 popw %es
94 popw %ds
95 popf
96 popa
97 ljmp $0, $0x7C00
99 ////////////////////////////// DOS EXE code ///////////////////////////////////
101 eol:
102 .ascii ".\r\n$"
103 no386:
104 .ascii "No 386+$"
105 noDOS3:
106 .ascii "No DOS 3.0+$"
107 rmPaging:
108 .ascii "Broken paging$"
109 ERRvcpi:
110 .ascii "No EMM386/VCPI 4.0+$"
111 chkerr:
112 .ascii "Broken ISO file$"
113 realmodemsg:
114 .ascii "Real mode$"
115 vm86modemsg:
116 .ascii "VM86 mode$"
117 help:
118 .ascii "SliTaz GNU/Linux boot loader$"
120 fixseg:
121 cld
122 movb $EXESTR(help), %dl
123 movw $0x100, %si
124 cmpw $0x3F2F, -126(%si) # /?
125 je abort
126 movw (%si), %cx
127 jcxz skip
128 xorw %dx, %dx
129 movw $0x7FE0/2, %cx
130 chklp:
131 lodsw
132 addw %ax, %dx
133 loop chklp
134 orw %dx, %dx
135 movb $EXESTR(chkerr), %dl
136 jne abort
137 skip:
138 pushf
139 popw %ax
140 movw $0xF0F0, %dx
141 orb %ah, %dh
142 andb $0xF, %ah
143 pushw %ax
144 popf
145 pushf
146 popw %ax
147 andb %dl, %ah
148 cmp %dl, %ah
149 je NotSupported // 8086 family
150 pushw %dx
151 popf
152 pushf
153 popw %ax
154 andb %dl, %ah
155 jnz is386 // 80286 family
156 NotSupported:
157 movb $EXESTR(no386), %dl
158 abort:
159 puts:
160 movb $1, %dh
161 call puts2
162 movw $EXEADRS(eol), %dx
163 puts2:
164 movb $9, %ah
165 int $0x21
166 ret
168 is386:
169 movl %cr0, %eax
170 andb $1, %al
171 jne tstvcpi
172 movb $EXESTR(rmPaging), %dl
173 shll $1, %eax
174 cabort:
175 jc abort
176 movb $EXESTR(realmodemsg), %dl
177 jmp realmode
179 tstvcpi:
180 pushw %ds
181 movw %cx, %ds // %cx = 0
182 movw 0x67*4+2, %ds
183 std
184 movw $14, %si
185 lodsl
186 cmpl $0x30585858, %eax // 0XXX
187 lodsl
188 cld
189 popw %ds
190 NoVCPI:
191 movb $EXESTR(ERRvcpi), %dl
192 jne abort
193 shll $8, %eax
194 cmpl $0x4D4D4500, %eax // [XQ]MME
195 movw $EXEADRS(CmdVCPI), %si
196 ChkVCPI:
197 jne NoVCPI
198 lodsb
199 shlw $8, %ax
200 je VersionVCPI
201 int $0x67
202 jmp ChkVCPI
204 CmdVCPI:
205 .byte 0x40 // status
206 .byte 0xDE // vcpi present ?
207 .byte 0x46 // version
208 .byte 0
210 VersionVCPI:
211 cmpb $0x40, %al // >= 4.0 ?
212 jb NoVCPI
213 movb $EXESTR(vm86modemsg), %dl
214 realmode:
215 call puts
216 movb $0x30, %ah
217 int $0x21
218 cmpb $3, %al
219 movb $EXESTR(noDOS3), %dl
220 jb cabort
221 movw EXEADRS(comstart), %ax // .com address
222 movw $moveend-move, %cx
223 movw $EXEADRS(move), %si
224 movw $0xC000, %di
225 jmp move2
227 move:
228 movb $0x80, %ch
229 xchgw %ax, %si
230 movw $0x0100, %di
231 move2:
232 pushw %di
233 rep
234 movsb
235 ret
236 moveend:
238 .org 440
239 //////////////////////////// partition table //////////////////////////////////