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