wok-current view syslinux/stuff/iso2exe/bootiso.S @ rev 13713
syslinux/iso2exe: add loram support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Dec 18 16:09:07 2012 +0100 (2012-12-18) |
parents | 58b695f73790 |
children | 3d4df3952952 |
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 pushw $0
43 popw %ds
44 movw $0x7C00, %bx
45 pushfw
46 pushw %ds
47 pushw %bx
48 pushaw
49 movw %sp, %bp
50 pushw %es
51 call setreg
52 rep
53 movsw
54 ljmp $0, $0x0600+start2
56 readsector2:
57 incw %cx
58 readsector1:
59 movw %cx, (%bx)
60 incw %cx
61 movw $0x201, %ax
62 int $0x13
63 setreg:
64 cld
65 pushw %ds
66 popw %es
67 movw %bx, %si
68 movw $0x0600, %di
69 movw $0x0100, %cx
70 return:
71 ret
72 start2:
73 movw $0x80, %dx
74 dxloop:
75 call readsector1
76 repe
77 cmpsw
78 je dxfound
79 next:
80 xorw %cx, %cx
81 xchgw %ax, %dx
82 addb $0x7D, %al // try every hard disk
83 andb $0x83, %al // and floppy disk
84 cmpb $0x80, %al
85 xchgw %ax, %dx
86 jnz dxloop
87 fail:
88 movw $0x0600+noloader, %si
89 call putslp
90 stop:
91 hlt
92 jmp stop
93 dxfound:
94 movw %dx, 10(%bp)
95 call readsector2
96 lodsw
97 shrw $1, %ax
98 jz fail // read fail or not isohydrid
99 popw %es
100 popa
101 iret
104 ////////////////////////////// DOS EXE code ///////////////////////////////////
106 help:
107 .ascii "SliTaz GNU/Linux"
108 .byte EXESTR(loader)
109 no386:
110 .ascii "No 386" // No 386+
111 .byte EXESTR(plus)
112 ERRvcpi:
113 .ascii "No EMM386/VCPI 4" // No EMM386/VCPI 4.0+
114 .byte EXESTR(dot0)
115 chkerr:
116 .ascii "Broken ISO image fil" // Broken ISO image file.
117 .byte EXESTR(eeol)
118 vm86modemsg:
119 .ascii "vm86" // vm86 mode.
120 .byte EXESTR(mode)
121 rmPaging:
122 .ascii "Invalid: paging + " // Invalid: paging + real mode.
123 realmodemsg:
124 .ascii "real" // real mode.
125 // -------------------------------------------------------------------
126 mode:
127 .ascii " mod"
128 eeol:
129 .ascii "e"
130 .byte EXESTR(eol)
131 noloader:
132 .ascii "No"
133 loader:
134 .ascii " boot loader"
135 eol:
136 .ascii "."
137 eol2:
138 .asciz "\r\n"
139 noDOS3:
140 .ascii "No DOS 3" // No DOS 3.0+
141 dot0:
142 .ascii ".0"
143 plus:
144 .ascii "+"
145 .byte EXESTR(eol2)
147 fixseg:
148 cld
149 movw $0x100, %si
150 movw -127(%si), %ax
151 cwd
152 pushw %dx // dos exit
153 cmpw $0x2F20, %ax
154 movb $EXESTR(help), %al
155 je abort
156 movw (%si), %cx
157 jcxz skip
158 movw $0x7FE0/2, %cx
159 chklp:
160 lodsw
161 addw %ax, %dx
162 loop chklp
163 orw %dx, %dx
164 movb $EXESTR(chkerr), %al
165 jne abort
166 skip:
167 pushfw // save flags
168 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
169 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
170 movb $0x70, %ah
171 pushw %ax
172 popfw // < 286 : flags[12..15] are forced 1
173 pushfw // = 286 : flags[12..15] are forced 0
174 popw %ax // > 286 : only flags[15] is forced 0
175 popfw // restore flags
176 addb $0x10, %ah // test F0 and 00 cases
177 cmpb $0x10, %ah
178 ja is386 // C=8086/80186, Z=80286
179 #if 0
180 jz is286
181 xorw %bx, %bx
182 movb (%bx), %dh
183 decw %bx
184 xorw %bx, (%bx) // 80186 write bytes at FFFF and 10000
185 movw (%bx), %ax
186 xorw %bx, (%bx) // 8086 write bytes at FFFF and 0000
187 cmpw %ah, %dh
188 jnz is186
189 #endif
190 NotSupported:
191 movb $EXESTR(no386), %al
192 abort:
193 puts:
194 movb $1, %ah
195 xchgw %ax, %si
196 putslp:
197 lodsb
198 orb %al, %al
199 jz moveret
200 js puts
201 movw $7, %bx
202 movb $0xE, %ah
203 int $0x10
204 jmp putslp
206 is386:
207 movl %cr0, %eax
208 andb $1, %al
209 jne tstvcpi
210 shll $1, %eax
211 movb $EXESTR(rmPaging), %al
212 jc abort
213 movb $EXESTR(realmodemsg), %al
214 realmode:
215 call puts
216 movb $0x30, %ah
217 int $0x21
218 cmpb $3, %al
219 movb $EXESTR(noDOS3), %al
220 jb abort
221 movw EXEADRS(comstart), %ax // .com address
222 movw $moveend-move, %cx
223 movw $EXEADRS(move), %si
224 movw $0xC000, %di
225 jmp move2
226 move:
227 movb $0x80, %ch
228 xchgw %ax, %si
229 movw $0x0100, %di
230 move2:
231 pushw %di
232 rep
233 movsb
234 moveret:
235 ret
236 moveend:
238 VersionVCPI:
239 cmpb $0x40, %dl // >= 4.0 ?
240 jb NoVCPI
241 movb $EXESTR(vm86modemsg), %al
242 jmp realmode
243 tstvcpi:
244 pushw %ds
245 movw %cx, %ds // %cx = 0
246 movw 0x67*4+2, %ds
247 movw $10, %si
248 lodsw
249 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
250 xchgw %ax, %dx
251 lodsw // si += 2
252 lodsw
253 xorw $0x5858, %ax // XX
254 orw %ax, %dx
255 lodsw
256 popw %ds
257 xorw $0x3058, %ax // X0
258 orw %ax, %dx
259 movw $EXEADRS(CmdVCPI), %si
260 ChkVCPI:
261 NoVCPI:
262 xchgw %ax, %dx
263 movb $EXESTR(ERRvcpi), %al
264 jne abort
265 lodsb
266 shlw $8, %ax
267 je VersionVCPI
268 int $0x67
269 testb %ah, %ah
270 jmp ChkVCPI
271 CmdVCPI:
272 .byte 0x40 // status
273 .byte 0xDE // vcpi present ?
274 .byte 0x46 // version
275 .byte 0
277 .org 440
278 //////////////////////////// partition table //////////////////////////////////