Merge from vendor branch BINUTILS:
[dragonfly.git] / sys / boot / pc98 / boot0.5 / selector.s
1 # Copyright (c) KATO Takenori, 1999, 2000.
2 #
3 # All rights reserved.  Unpublished rights reserved under the copyright
4 # laws of Japan.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer as
12 #    the first lines of this file unmodified.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # $FreeBSD: src/sys/boot/pc98/boot0.5/selector.s,v 1.2 2000/08/06 14:35:37 kato Exp $
29 # $DragonFly: src/sys/boot/pc98/boot0.5/Attic/selector.s,v 1.3 2003/11/10 06:08:38 dillon Exp $
30 #
31
32         .code16
33
34         .text
35 #
36 # Display partition table.
37 #
38 showpartitions:
39         # Clear partion table area
40         movw    $16, %cx
41 clear_part:
42         push    %cx
43         movw    %cx, %dx
44         decw    %dx
45         addw    $5, %dx
46         movw    $20, %cx
47         call    sc_goto
48         movw    $msg_spc, %di
49         call    sc_puts
50         pop     %cx
51         loop    clear_part
52
53         # Check `Exit' menu
54         movw    curdevice, %ax
55         cmpw    ndevice, %ax
56         je      no_slice
57
58         # XXX Move this to a suitable place!
59         movw    $22, %cx
60         movw    $4, %dx
61         call    sc_goto
62         movw    $msg_slice, %di
63         call    sc_puts
64
65         # Check the number of partitions
66         movw    npartition, %cx
67         orw     %cx, %cx
68         jnz     partitionexist
69 no_slice:
70         # Just show the `no slice' message.
71         movw    $22, %cx
72         movw    $5, %dx
73         call    sc_goto
74         movw    $msg_noslice, %di
75         call    sc_puts
76         ret
77 partitionexist:
78         xorw    %si, %si                # %si = partition number
79 showpart_loop:
80         push    %cx                     # %cx = number of partitions
81         movw    $22, %cx
82         movw    %si, %dx
83         addw    $5, %dx
84         call    sc_goto
85         movw    %si, %di
86         movb    $5, %cl
87         shlw    %cl, %di
88         addw    $0x10, %di              # SYSM field
89         # SYSM: space filled string.  Don't use sc_puts.
90         movw    $16, %cx
91 showpart_name:
92         push    %cx
93         movb    parttable(%di), %al
94         call    sc_putc
95         incw    %di
96         pop     %cx
97         loop    showpart_name
98         incw    %si
99         pop     %cx
100         loop    showpart_loop
101         ret
102
103 #
104 # Show default slice indicator
105 # If the default boot slice exists, `*' indicator will be showed.
106 #
107 showdefaultslicemark:
108         cmpb    $0x80, defpartflag
109         je      defpartexist
110         ret
111 defpartexist:
112         movw    npartition, %cx
113 defslice_loop:
114         movw    %cx, %bx
115         decw    %bx
116         push    %cx
117         push    %bx
118         movw    $40, %cx
119         movw    %bx, %dx
120         addw    $5, %dx
121         call    sc_goto
122
123         pop     %bx
124         pop     %cx
125         movb    defpartnum, %al
126         cmpb    partnum(%bx), %al
127         jne     nomatch
128         movb    $'*', %al
129         call    sc_putc
130         jmp     defslice_done
131 nomatch:
132         movb    $' ', %al
133         call    sc_putc
134 defslice_done:
135         loop    defslice_loop
136         ret
137
138 #
139 # Hide default slice indicator
140 #
141 hidedefaultslicemark:
142         movw    $16, %cx
143 hidedefslice_loop:
144         push    %cx
145         movw    %cx, %dx
146         addw    $4, %dx
147         movw    $40, %cx
148         call    sc_goto
149         movb    $' ', %al
150         call    sc_putc
151         pop     %cx
152         loop    hidedefslice_loop
153         ret
154
155 #
156 # Toggle default slice
157 #
158 toggle_default:
159         cmpb    $0x80, defpartflag
160         jne     set_default
161         # Clear default
162         movb    $0, defpartflag
163         call    write_ipl               # Restore
164         call    hidedefaultslicemark
165         ret
166         # Set default slice
167 set_default:
168         movw    curpartition, %si
169         movb    partnum(%si), %al       # %al = real partition number
170         movb    $5, %cl
171         shlw    %cl, %si
172         # Default slice must be bootable
173         testb   $0x80, parttable(%si)
174         jnz     curpart_bootable
175         # Current partition is not bootable.
176         ret
177 curpart_bootable:
178         movb    $0x80, defpartflag
179         movb    %al, defpartnum
180         call    write_ipl               # Restore
181         call    showdefaultslicemark
182         ret
183
184 #
185 # Show/hide cursor
186 #
187 show_devcurs:
188         xorw    %cx, %cx
189         movw    curdevice, %dx
190         addw    $5, %dx
191         call    sc_goto
192         movb    $'>', %al
193         call    sc_putc
194         movb    $'>', %al
195         call    sc_putc
196         ret
197
198 hide_devcurs:
199         xorw    %cx, %cx
200         movw    curdevice, %dx
201         addw    $5, %dx
202         call    sc_goto
203         movb    $' ', %al
204         call    sc_putc
205         movb    $' ', %al
206         call    sc_putc
207         ret
208
209 show_slicecurs:
210         movw    $20, %cx
211         movw    curpartition, %dx
212         addw    $5, %dx
213         call    sc_goto
214         movb    $'>', %al
215         call    sc_putc
216         movb    $'>', %al
217         call    sc_putc
218         ret
219
220 hide_slicecurs:
221         movw    $20, %cx
222         movw    curpartition, %dx
223         addw    $5, %dx
224         call    sc_goto
225         movb    $' ', %al
226         call    sc_putc
227         movb    $' ', %al
228         call    sc_putc
229         ret
230
231 isforceboot:
232         xorw    %cx, %cx
233         movw    $20, %dx
234         call    sc_goto
235         movw    $msg_force, %di
236         call    sc_puts
237         call    sc_getc
238         push    %ax
239         xorw    %cx, %cx
240         movw    $20, %dx
241         call    sc_goto
242         movw    $msg_forceclr, %di
243         call    sc_puts
244         pop     %ax
245         cmpb    $0x15, %ah
246         je      force_yes
247         xorw    %ax, %ax
248         ret
249 force_yes:
250         movw    $1, %ax
251         ret
252
253 #
254 # Main loop for device mode
255 #
256 devmode:
257         call    read_ipl
258         call    hidedefaultslicemark
259         call    showpartitions
260         call    showdefaultslicemark
261         call    show_devcurs
262
263         movw    $2, %cx
264         movw    $4, %dx
265         call    sc_goto
266         movb    $0xe5, %al
267         movw    $6, %cx
268         call    sc_setattr
269         movw    $22, %cx
270         movw    $4, %dx
271         call    sc_goto
272         movb    $0xe1, %al
273         movw    $5, %cx
274         call    sc_setattr
275         movw    $44, %cx
276         movw    $3, %dx
277         call    sc_goto
278         movb    $0xe5, %al
279         movw    $11, %cx
280         call    sc_setattr
281         movw    $44, %cx
282         movw    $7, %dx
283         call    sc_goto
284         movb    $0xe1, %al
285         movw    $10, %cx
286         call    sc_setattr
287
288 devmode_loop:
289         call    sc_getc
290         movw    ndevice, %bx
291         cmpb    $0x3a, %ah              # UP
292         je      dev_up
293         cmpb    $0x3d, %ah              # DOWN
294         je      dev_down
295         cmpb    $0x3c, %ah              # RIGHT
296         je      dev_right
297         cmpb    $0x1c, %ah              # RETURN
298         jne     devmode_loop
299         cmpw    curdevice, %bx
300         jne     dev_right
301         movw    $3, mode                # N88-BASIC
302         ret
303 dev_up:
304         cmpw    $0, curdevice
305         je      devmode_loop
306         call    hide_devcurs
307         decw    curdevice
308         call    read_ipl
309         call    hidedefaultslicemark
310         call    showpartitions
311         call    showdefaultslicemark
312         call    show_devcurs
313         jmp     devmode_loop
314 dev_down:
315         cmpw    curdevice, %bx
316         je      devmode_loop
317         call    hide_devcurs
318         incw    curdevice
319         call    read_ipl
320         call    hidedefaultslicemark
321         call    showpartitions
322         call    showdefaultslicemark
323         call    show_devcurs
324         jmp     devmode_loop
325 dev_right:
326         cmpw    curdevice, %bx
327         je      devmode_loop
328         movw    $1, mode                # Slice mode
329         ret
330
331 #
332 # main loop for slice mode
333 #
334 slicemode:
335         movw    $0, curpartition
336         call    show_slicecurs
337         movw    $2, %cx
338         movw    $4, %dx
339         call    sc_goto
340         movb    $0xe1, %al
341         movw    $6, %cx
342         call    sc_setattr
343         movw    $22, %cx
344         movw    $4, %dx
345         call    sc_goto
346         movb    $0xe5, %al
347         movw    $5, %cx
348         call    sc_setattr
349         movw    $44, %cx
350         movw    $3, %dx
351         call    sc_goto
352         movb    $0xe1, %al
353         movw    $11, %cx
354         call    sc_setattr
355         movw    $44, %cx
356         movw    $7, %dx
357         call    sc_goto
358         movb    $0xe5, %al
359         movw    $10, %cx
360         call    sc_setattr
361
362 slicemode_loop:
363         call    sc_getc
364         cmpb    $0x3a, %ah              # UP
365         je      slice_up
366         cmpb    $0x3d, %ah              # DOWN
367         je      slice_down
368         cmpb    $0x3b, %ah              # LEFT
369         je      slice_esc
370         cmpb    $0x00, %ah              # ESC
371         je      slice_esc
372         cmpb    $0x1c, %ah              # RETURN
373         je      slice_ret
374         cmpb    $0x34, %ah              # SPC
375         je      slice_spc
376         cmpb    $0x62, %ah              # f1
377         je      slice_spc
378         jmp     slicemode_loop
379 slice_up:
380         cmpw    $0, curpartition
381         je      slicemode_loop
382         call    hide_slicecurs
383         decw    curpartition
384         call    show_slicecurs
385         jmp     slicemode_loop
386 slice_down:
387         movw    curpartition, %bx
388         movw    npartition, %ax
389         decw    %ax
390         cmpw    %bx, %ax
391         je      slicemode_loop
392         call    hide_slicecurs
393         incw    curpartition
394         call    show_slicecurs
395         jmp     slicemode_loop
396 slice_esc:
397         movw    $0, mode                # Device mode
398         ret
399 slice_spc:
400         call    toggle_default
401         jmp     slicemode_loop
402 slice_ret:
403         # Test bit 7 of mid
404         movw    curpartition, %si
405         movb    $5, %cl
406         shlw    %cl, %si
407         testb   $0x80, parttable(%si)
408         jnz     bootable_slice
409         call    isforceboot
410         orw     %ax, %ax
411         jz      slicemode_loop
412 bootable_slice:
413         call    boot
414         jmp     slicemode_loop
415
416 #
417 # Main loop
418 #
419         .global selector
420 selector:
421         movw    $0, curdevice   # trydefault may change the curdevice.
422         movw    $0, mode
423
424 selector_loop:
425         cmpw    $0, mode
426         je      status_dev
427         cmpw    $1, mode
428         je      status_slice
429         ret
430 status_dev:
431         call    devmode
432         jmp     selector_loop
433 status_slice:
434         call    slicemode
435         jmp     selector_loop
436
437         .data
438         .global curpartition
439 curpartition:   .word   0               # current patition
440 mode:           .word   0
441
442 msg_spc:        .asciz  "                        "
443 msg_slice:      .asciz  "Slice"
444 msg_noslice:    .asciz  "no slice"
445 msg_force:      .asciz  "This slice is not bootable. Continue? (Y / [N])"
446 msg_forceclr:   .asciz  "                                               "