wok-tiny view linux/stuff/bundle.S @ rev 182

Update bootpillman & bootsokoban
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 24 17:53:05 2023 +0000 (7 months ago)
parents f93fa966f210
children 1e55ea7da8de
line source
1 #define TIMEOUT autostart after 5 seconds
2 #define CHECK_FILES add 'Check media' entry
4 .arch i8086
5 .code16
6 .org 0
7 start:
8 // stack segment setup
9 cld
10 movw $0x9000, %di
11 pushw %di
12 popw %ss
13 movw %di, %sp
15 // patch disk parameter table
16 xorw %cx, %cx
17 pushw %cx // bootloader may want to pull 0
18 movw $0x78, %bx
19 movw %cx, %ds
20 ldsw (%bx), %si // %ds:0x78 is parameter table address
21 pushw %ss
22 popw %es
23 movb $6, %cl // copy 12 bytes
24 pushw %di
25 rep
26 movsw
27 movb $63, %es:4-12(%di) // patch max sector count
28 movw %cx, %ds
29 popw (%bx)
30 movw %es, 2(%bx) // update parameter table address
32 // data segments setup
33 movw $0x7C0, %ax
34 pushw %ax
35 popw %ds
36 pushw %ds
37 popw %es
39 // main loop
40 menustart:
41 xorw %bp, %bp
42 menudown:
43 incw %bp
44 menustartlp:
45 movw $3, %ax
46 int $0x10 // clear screen
47 movb $1, %ah
48 movw $0x1000, %cx
49 int $0x10 // clear cursor
50 movw $menu, %si
51 call puts
52 call putcr
53 movw %bp, %cx
54 menulp:
56 .macro entry
57 movb $' ', %bl // not selected by default
58 lodsw
59 loop notcur
60 xchgw %ax, %di
61 movb $'>', %bl // selected when cx = 0
62 notcur:
63 xchgw %ax, %bx
64 .endm
66 #ifdef CHECK_FILES
67 call putentry
68 lodsw // CRC16
69 lodsw // sector count
70 #else
71 entry
72 call putcs
73 #endif
74 cmpw $0, (%si) // end of list ?
75 jne menulp
76 #ifdef CHECK_FILES
77 movw $msgcrc-2, %si
78 call putentry
79 #endif
80 menustartz:
82 .macro waitkbdcode
83 #ifdef TIMEOUT
84 clock = 0x46C
85 wait:
86 wait4key:
87 pushw %ds
88 xorw %ax, %ax
89 movw %ax, %ds
90 movw $clock, %si
91 #define DELAY 5
92 movb $257-(DELAY*182)/10, (%si)
93 waitkbd:
94 movw $0x10D, %ax // test keyboard, timeout => CR
95 cmpb (%si), %ah
96 clock_patch:
97 je waitdone
98 int $0x16
99 jz waitkbd
100 cbw
101 int $0x16 // eat char
102 movb $0xA8, clock_patch+0x7C00 // disable timeout
103 waitdone:
104 popw %ds
105 #else
106 xorb %ax, %ax
107 int $0x16
108 #endif
109 .endm
111 #ifdef CHECK_FILES
112 call wait4kbd
113 #else
114 waitkbdcode
115 #endif
116 cmpb $0x0D, %al // CR ?
117 je doit
118 cmpb $0x48, %ah // UP ?
119 jne isitdn
120 decw %bp
121 jz menudown
122 isitdn:
123 incw %cx
124 cmpb $0x50, %ah // DN ?
125 loope menudown
126 jmp menustartlp
128 #ifdef CHECK_FILES
129 toeos:
130 lodsb
131 orb %al, %al
132 jnz toeos
133 lodsw // crc, count
134 lodsw
135 cmpw $0, (%si)
136 jne nextchk
137 call wait4kbd
138 jmp start
139 #endif
141 .macro tochs // %di -> %cx, %dx & %bp=sector max
142 movw $64, %cx
143 sectlp:
144 movb %ch, %dh
145 decw %cx
146 #define BUFFER 0x200
147 #ifdef CHECK_FILES
148 call readsector
149 #else
150 movw $BUFFER, %bx
151 movw $0x201, %ax
152 int $0x13
153 #endif
154 jc sectlp
155 movw %cx, %bp
156 movw %di, %ax
157 div %cl // 32 Mb & 255 tracks max
158 movb %ah, %cl // sector
159 incb %cl
160 shrb $1, %al // C = head, AL = cylinder
161 adcb %dh, %dh
162 movb %al, %ch
163 .endm
165 doit:
166 #ifdef CHECK_FILES
167 jcxz docrc
168 call getsectors
169 call readsector2
170 #else
171 tochs // %di -> %cx, %dx & %bp=sector max
172 movw $0x201, %ax
173 int $0x13
174 #endif
175 jc menustart
177 // scan boot code
178 scanboot:
179 incw %bx
180 cmpw $0x5897, -3(%bx) // xchgw %ax, %di; popw %ax
181 jne nofound
182 cmpw $0xE841, -1(%bx) // incw %cx ; call ...
183 je found
184 nofound:
185 orb %bl, %bl
186 jnz scanboot
187 decb %bh
188 found:
189 pushw %ds
190 pushw %bx
191 // cli
192 // movb 0x1F1+BUFFER, %al // setup size
193 pushw %ss
194 popw %ds
195 pushw %ss
196 popw %es
197 xorw %di, %di
198 xchgw %ax, %di // ax = limits = 0
199 xorw %bx, %bx // to %es:%bx = 9000:0000
200 incw %di // Add bootsector, Clear Z
201 lret // Read from %dx, %cx
203 #ifdef CHECK_FILES
204 docrc:
205 movw $menu, %si
206 skiptitle:
207 lodsb
208 orb %al, %al
209 jnz skiptitle
210 nextchklp:
211 pushw %si // start of menu
212 nextchk:
213 lodsw // sector offset
214 cmpw %ax, %di // next sector offset
215 jne toeos
216 call puts // menu entry
217 call getsectors // %di -> %cx, %dx & %bp=sector max
218 lodsw
219 addw (%si), %di
220 pushw %di // next sector offset
221 xchgw %ax, %di // crc
222 lodsw // sector count
223 xchgw %ax, %si
224 chksector:
225 call readsector
226 jc chkfail
227 chksectorz:
228 subw (%bx), %di
229 incw %bx
230 incw %bx
231 cmpb $4, %bh
232 jne chksectorz
233 decw %si
234 je chkend
235 movw %bp, %ax
236 incw %cx
237 cmpb %al, %cl
238 jle rdit
239 movb $1, %cl
240 xorb %cl, %dh
241 jne rdit
242 incb %ch
243 cmp $80, %ch
244 jb rdit
245 push %si
246 mov $msgnext, %si
247 call puts
248 call wait4kbd
249 pop %si
250 mov $0, %ch
251 rdit:
252 jmp chksector
253 chkend:
254 movw $msgok, %si
255 orw %di, %di
256 je chkok
257 chkfail:
258 movw $msgko, %si
259 chkok:
260 call puts
261 popw %di // next sector offset
262 popw %si // start of menu
263 jmp nextchklp
265 readsector:
266 movw $BUFFER, %bx
267 readsector2:
268 movw $0x201, %ax
269 int $0x13
270 ret
272 getsectors:
273 tochs // %di -> %cx, %dx & %bp=sector max
274 ret
276 wait4kbd:
277 waitkbdcode
278 ret
280 putentry:
281 entry
282 jmp putcs
283 #endif
285 puts:
286 lodsb
287 cmpb $2, %al
288 jnc putcs
289 putcr:
290 movb $10, %al
291 putlf:
292 xorb $10^13, %al
293 putcs:
294 movw $7, %bx
295 movb $0xE, %ah
296 int $0x10
297 cmpb $13, %al
298 jz putlf
299 jnc puts
300 ret
302 #ifdef CHECK_FILES
303 msgok:
304 .asciz " OK"
305 msgko:
306 .ascii " Broken"
307 .word 1 // next sector offset
308 msgcrc:
309 .asciz "Check media" // used to detect CHECK_FILES
310 #endif
311 menu:
313 .org 0x1F1
314 setupsz:
315 .byte 0
316 rootflags:
317 .word menu
318 syssz:
319 .long 0 // updated by bundle
320 ramsize:
321 #ifdef CHECK_FILES
322 msgnext:
323 .asciz "Next!"
324 #else
325 .ascii "SliTaz"
326 #endif
327 // .word 0
328 //vidmode:
329 // .word 0
330 //rootdev:
331 // .word 0
332 bootflag:
333 .word 0xAA55