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

memtest: 386 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 30 16:35:54 2021 +0000 (2021-04-30)
parents 502f4a0181d9
children bbb34fe4904d
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
21 pushw %ss
22 popw %es
23 movb $6, %cl
24 pushw %di
25 rep
26 movsw
27 movb $63, %es:4-12(%di)
28 movw %cx, %ds
29 popw (%bx)
30 movw %es, 2(%bx)
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:
55 .macro entry
56 movb $' ', %bl
57 lodsw
58 loop notcur
59 xchgw %ax, %di
60 movb $'>', %bl
61 notcur:
62 xchgw %ax, %bx
63 .endm
64 #ifdef CHECK_FILES
65 call putentry
66 lodsw // CRC16
67 lodsw // sector count
68 #else
69 entry
70 call putcs
71 #endif
72 cmpw $0, (%si)
73 jne menulp
74 #ifdef CHECK_FILES
75 movw $msgcrc-2, %si
76 call putentry
77 #endif
78 menustartz:
79 .macro waitkbdcode
80 #ifdef TIMEOUT
81 clock = 0x46C
82 wait:
83 wait4key:
84 pushw %ds
85 xorw %ax, %ax
86 movw %ax, %ds
87 movw $clock, %si
88 #define DELAY 5
89 movb $257-(DELAY*182)/10, (%si)
90 waitkbd:
91 movw $0x10D, %ax // test keyboard, timeout => CR
92 cmpb (%si), %ah
93 clock_patch:
94 je waitdone
95 int $0x16
96 jz waitkbd
97 cbw
98 int $0x16 // eat char
99 movb $0xA8, clock_patch+0x7C00 // disable timeout
100 waitdone:
101 popw %ds
102 #else
103 xorb %ax, %ax
104 int $0x16
105 #endif
106 .endm
107 #ifdef CHECK_FILES
108 call wait4kbd
109 #else
110 waitkbdcode
111 #endif
112 cmpb $0x0D, %al // CR ?
113 je doit
114 cmpb $0x48, %ah // UP ?
115 jne isitdn
116 decw %bp
117 jz menudown
118 isitdn:
119 incw %cx
120 cmpb $0x50, %ah // DN ?
121 loope menudown
122 jmp menustartlp
124 #ifdef CHECK_FILES
125 toeos:
126 lodsb
127 orb %al, %al
128 jnz toeos
129 lodsw // crc, count
130 lodsw
131 cmpw $0, (%si)
132 jne nextchk
133 call wait4kbd
134 jmp start
135 #endif
137 .macro tochs // %di -> %cx, %dx & %bp=sector max
138 movw $64, %cx
139 sectlp:
140 movb %ch, %dh
141 decw %cx
142 #define BUFFER 0x200
143 #ifdef CHECK_FILES
144 call readsector
145 #else
146 movw $BUFFER, %bx
147 movw $0x201, %ax
148 int $0x13
149 #endif
150 jc sectlp
151 movw %cx, %bp
152 movw %di, %ax
153 div %cl // 32 Mb & 255 tracks max
154 movb %ah, %cl // sector
155 incb %cl
156 shrb $1, %al // C = head, AL = cylinder
157 adcb %dh, %dh
158 movb %al, %ch
159 .endm
161 doit:
162 #ifdef CHECK_FILES
163 jcxz docrc
164 call getsectors
165 call readsector2
166 #else
167 tochs // %di -> %cx, %dx & %bp=sector max
168 movw $0x201, %ax
169 int $0x13
170 #endif
171 jc menustart
173 // scan boot code
174 scanboot:
175 incw %bx
176 cmpw $0x5897, -3(%bx) // xchgw %ax, %di; popw %ax
177 jne scanboot
178 cmpw $0xE841, -1(%bx) // incw %cx ; call ...
179 jne scanboot
180 found:
181 pushw %ds
182 pushw %bx
183 cli
184 movb 0x1F1+BUFFER, %al // setup size
185 pushw %ss
186 popw %ds
187 pushw %ss
188 popw %es
189 xorw %di, %di
190 xchgw %ax, %di // ax = limits = 0
191 xorw %bx, %bx // to %es:%bx = 9000:0000
192 incw %di // Add bootsector, Clear Z
193 lret // Read from %dx, %cx
195 #ifdef CHECK_FILES
196 docrc:
197 movw $menu, %si
198 skiptitle:
199 lodsb
200 orb %al, %al
201 jnz skiptitle
202 nextchklp:
203 pushw %si // start of menu
204 nextchk:
205 lodsw // sector offset
206 cmpw %ax, %di // next sector offset
207 jne toeos
208 call puts // menu entry
209 call getsectors // %di -> %cx, %dx & %bp=sector max
210 lodsw
211 addw (%si), %di
212 pushw %di // next sector offset
213 xchgw %ax, %di // crc
214 lodsw // sector count
215 xchgw %ax, %si
216 chksector:
217 call readsector
218 jc chkfail
219 chksectorz:
220 subw (%bx), %di
221 incw %bx
222 incw %bx
223 cmpb $4, %bh
224 jne chksectorz
225 decw %si
226 je chkend
227 movw %bp, %ax
228 incw %cx
229 cmpb %al, %cl
230 jle rdit
231 movb $1, %cl
232 xorb %cl, %dh
233 jne rdit
234 incb %ch
235 cmp $80, %ch
236 jb rdit
237 push %si
238 mov $msgnext, %si
239 call puts
240 call wait4kbd
241 pop %si
242 mov $0, %ch
243 rdit:
244 jmp chksector
245 chkend:
246 movw $msgok, %si
247 orw %di, %di
248 je chkok
249 chkfail:
250 movw $msgko, %si
251 chkok:
252 call puts
253 popw %di // next sector offset
254 popw %si // start of menu
255 jmp nextchklp
257 readsector:
258 movw $BUFFER, %bx
259 readsector2:
260 movw $0x201, %ax
261 int $0x13
262 ret
264 getsectors:
265 tochs // %di -> %cx, %dx & %bp=sector max
266 ret
268 wait4kbd:
269 waitkbdcode
270 ret
272 putentry:
273 entry
274 jmp putcs
275 #endif
277 puts:
278 lodsb
279 cmpb $2, %al
280 jnc putcs
281 putcr:
282 movb $10, %al
283 putlf:
284 xorb $10^13, %al
285 putcs:
286 movw $7, %bx
287 movb $0xE, %ah
288 int $0x10
289 cmpb $13, %al
290 jz putlf
291 jnc puts
292 ret
294 #ifdef CHECK_FILES
295 msgok:
296 .asciz " OK"
297 msgko:
298 .ascii " Broken"
299 .word 1 // next sector offset
300 msgcrc:
301 .asciz "Check media" // used to detect CHECK_FILES
302 #endif
303 menu:
305 .org 0x1F1
306 setupsz:
307 .byte 0
308 rootflags:
309 .word menu
310 syssz:
311 .long 0 // updated by bundle
312 ramsize:
313 #ifdef CHECK_FILES
314 msgnext:
315 .asciz "Next!"
316 #else
317 .ascii "SliTaz"
318 #endif
319 // .word 0
320 //vidmode:
321 // .word 0
322 //rootdev:
323 // .word 0
324 bootflag:
325 .word 0xAA55