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

linux: fix bundle.S
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 26 17:09:38 2023 +0000 (7 months ago)
parents bbb34fe4904d
children 5d44015ce878
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 jmp boot
189 found:
190 cli
191 movb 0x1F1+BUFFER, %al // setup size
192 boot:
193 pushw %ds
194 pushw %bx
195 pushw %ss
196 popw %ds
197 pushw %ss
198 popw %es
199 xorw %di, %di
200 xchgw %ax, %di // ax = limits = 0
201 xorw %bx, %bx // to %es:%bx = 9000:0000
202 incw %di // Add bootsector, Clear Z
203 lret // Read from %dx, %cx
205 #ifdef CHECK_FILES
206 docrc:
207 movw $menu, %si
208 skiptitle:
209 lodsb
210 orb %al, %al
211 jnz skiptitle
212 nextchklp:
213 pushw %si // start of menu
214 nextchk:
215 lodsw // sector offset
216 cmpw %ax, %di // next sector offset
217 jne toeos
218 call puts // menu entry
219 call getsectors // %di -> %cx, %dx & %bp=sector max
220 lodsw
221 addw (%si), %di
222 pushw %di // next sector offset
223 xchgw %ax, %di // crc
224 lodsw // sector count
225 xchgw %ax, %si
226 chksector:
227 call readsector
228 jc chkfail
229 chksectorz:
230 subw (%bx), %di
231 incw %bx
232 incw %bx
233 cmpb $4, %bh
234 jne chksectorz
235 decw %si
236 je chkend
237 movw %bp, %ax
238 incw %cx
239 cmpb %al, %cl
240 jle rdit
241 movb $1, %cl
242 xorb %cl, %dh
243 jne rdit
244 incb %ch
245 cmp $80, %ch
246 jb rdit
247 push %si
248 mov $msgnext, %si
249 call puts
250 call wait4kbd
251 pop %si
252 mov $0, %ch
253 rdit:
254 jmp chksector
255 chkend:
256 movw $msgok, %si
257 orw %di, %di
258 je chkok
259 chkfail:
260 movw $msgko, %si
261 chkok:
262 call puts
263 popw %di // next sector offset
264 popw %si // start of menu
265 jmp nextchklp
267 readsector:
268 movw $BUFFER, %bx
269 readsector2:
270 movw $0x201, %ax
271 int $0x13
272 ret
274 getsectors:
275 tochs // %di -> %cx, %dx & %bp=sector max
276 ret
278 wait4kbd:
279 waitkbdcode
280 ret
282 putentry:
283 entry
284 jmp putcs
285 #endif
287 puts:
288 lodsb
289 cmpb $2, %al
290 jnc putcs
291 putcr:
292 movb $10, %al
293 putlf:
294 xorb $10^13, %al
295 putcs:
296 movw $7, %bx
297 movb $0xE, %ah
298 int $0x10
299 cmpb $13, %al
300 jz putlf
301 jnc puts
302 ret
304 #ifdef CHECK_FILES
305 msgok:
306 .asciz " OK"
307 msgko:
308 .ascii " Broken"
309 .word 1 // next sector offset
310 msgcrc:
311 .asciz "Check media" // used to detect CHECK_FILES
312 #endif
313 menu:
315 .org 0x1F1
316 setupsz:
317 .byte 0
318 rootflags:
319 .word menu
320 syssz:
321 .long 0 // updated by bundle
322 ramsize:
323 #ifdef CHECK_FILES
324 msgnext:
325 .asciz "Next!"
326 #else
327 .ascii "SliTaz"
328 #endif
329 // .word 0
330 //vidmode:
331 // .word 0
332 //rootdev:
333 // .word 0
334 bootflag:
335 .word 0xAA55