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