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

Add ipxe, memtest
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 07 14:42:58 2016 +0100 (2016-02-07)
parents
children cda63f13344c
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 %ax, %ax
17 movw $0x78, %bx
18 movw %ax, %ds
19 ldsw (%bx), %si
20 pushw %ss
21 popw %es
22 movw $64/2, %cx
23 rep
24 stosw
25 movb $6, %cl
26 pushw %di
27 rep
28 movsw
29 movb $63, %es:4-12(%di)
30 movw %cx, %ds
31 popw (%bx)
32 movw %es, 2(%bx)
34 // data segments setup
35 movw $0x7C0, %ax
36 pushw %ax
37 popw %ds
38 pushw %ds
39 popw %es
41 // main loop
42 menustart:
43 xorw %bp, %bp
44 menudown:
45 incw %bp
46 menustartlp:
47 movw $3, %ax
48 int $0x10 // clear screen
49 movb $1, %ah
50 movw $0x1000, %cx
51 int $0x10 // clear cursor
52 movw $menu, %si
53 call puts
54 call putcr
55 movw %bp, %cx
56 menulp:
57 movb $' ', %bh
58 lodsw
59 loop notcur
60 xchgw %ax, %di
61 movb $'>', %bh
62 notcur:
63 movb %bh, %al
64 call putcs
65 #ifdef CHECK_FILES
66 lodsw // CRC16
67 lodsw // sector count
68 #endif
69 cmpw %bx, (%si)
70 jnc menulp
71 #ifdef CHECK_FILES
72 movw $msgcrc, %si
73 movb $' ', %al
74 loop notcrc
75 movb $'>', %al
76 notcrc:
77 call putcs
78 #endif
79 menustartz:
80 #ifdef TIMEOUT
81 clock = 0x46C
82 wait:
83 wait4key:
84 pushw %ds
85 movw $0, %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 je waitdone
94 int $0x16
95 jz waitkbd
96 cbw
97 int $0x16 // eat char
98 movw %si, wait4key+0x7C02 // disable timeout
99 waitdone:
100 popw %ds
101 #else
102 xorb %ax, %ax
103 int $0x16
104 #endif
105 cmpb $0x0D, %al // CR ?
106 je doit
107 cmpb $0x48, %ah // UP ?
108 jne isitdn
109 decw %bp
110 jz menudown
111 isitdn:
112 incw %cx
113 cmpb $0x50, %ah // DN ?
114 loope menudown
115 jmp menustartlp
117 .macro tochs // %di -> %cx, %dx & %bp=sector max
118 movw $64, %cx
119 movw $0x200, %bx
120 sectlp:
121 movw $0x201, %ax
122 movb %ch, %dh
123 decw %cx
124 int $0x13
125 jc sectlp
126 movw %cx, %bp
127 movw %di, %ax
128 div %cl // 32 Mb & 255 tracks max
129 movb %ah, %cl // sector
130 incb %cl
131 shrb $1, %al // C = head, AL = cylinder
132 adcb %dh, %dh
133 movb %al, %ch
134 .endm
136 doit:
137 #ifdef CHECK_FILES
138 jcxz docrc
139 call getsectors
140 #else
141 tochs // %di -> %cx, %dx & %bp=sector max
142 #endif
143 pushw %cx
144 movw $0x201, %ax
145 int $0x13
146 popw %cx
147 jc menustart
149 // scan boot code
150 movw %bx, %di
151 scanboot:
152 incw %di
153 cmpw $0x5897, -3(%di) // xchgw %ax, %di; popw %ax
154 jne scanboot
155 cmpw $0xE841, -1(%di) // incw %cx ; call ...
156 jne scanboot
157 pushw %ds
158 pushw %di
159 movb 0x1F1(%bx), %al // setup size
160 pushw %ss
161 popw %ds
162 pushw %ss
163 popw %es
164 xorw %di, %di
165 xchgw %ax, %di // ax = limits = 0
166 xorw %bx, %bx // to %es:%bx = 9000:0000
167 incw %di // Add bootsector, Clear Z
168 lret // Read from %dx, %cx
170 #ifdef CHECK_FILES
171 docrc:
172 movw $menu, %si
173 skiptitle:
174 lodsb
175 orb %al, %al
176 jnz skiptitle
177 nextchk:
178 lodsw // sector offset
179 xchgw %ax, %di
180 movw %di, %cx
181 movw $1, %bp
182 jcxz menustartz
183 call puts // menu entry
184 call getsectors
185 lodsw
186 xchgw %ax, %di // crc
187 movw $0x201, %ax
188 int $0x13
189 lodsw // sector count
190 pushw %si
191 jc chkfail
192 xchgw %ax, %si
193 chksector:
194 subw (%bx), %di
195 incw %bx
196 incw %bx
197 cmpb $4, %bh
198 jne chksector
199 movb $2, %bh
200 decw %si
201 je chkend
202 movw %bp, %ax
203 incw %cx
204 cmpb %al, %cl
205 jle rdit
206 movb $1, %cl
207 xorb %cl, %dh
208 jne rdit
209 incb %ch
210 rdit:
211 movw $0x201, %ax
212 int $0x13
213 jnc chksector
214 chkend:
215 movw $msgok, %si
216 orw %di, %di
217 je chkok
218 chkfail:
219 movw $msgko, %si
220 chkok:
221 call puts
222 popw %si
223 jmp nextchk
225 getsectors:
226 tochs // %di -> %cx, %dx & %bp=sector max
227 return:
228 ret
229 #endif
231 putcr:
232 movb $10, %al
233 putlf:
234 xorb $10^13, %al
235 putcs:
236 movw $7, %bx
237 movb $0xE, %ah
238 int $0x10
239 cmpb $13, %al
240 jz putlf
241 jc return
242 puts:
243 lodsb
244 orb %al, %al
245 jnz putcs
246 jmp putcr
247 #ifndef CHECK_FILES
248 return:
249 ret
250 #endif
252 #ifdef CHECK_FILES
253 msgok:
254 .asciz " OK"
255 msgko:
256 .asciz " Broken"
257 msgcrc:
258 .asciz "Check media" // used to detect CHECK_FILES
259 #endif
260 menu:
262 .org 0x1F1
263 setupsz:
264 .byte 0
265 rootflags:
266 .word menu
267 syssz:
268 .long 0 // updated by bundle
269 ramsize:
270 .ascii "SliTaz"
271 // .word 0
272 //vidmode:
273 // .word 0
274 //rootdev:
275 // .word 0
276 bootflag:
277 .word 0xAA55