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