Merge from vendor branch GDB:
[dragonfly.git] / sys / boot / pc98 / boot0.5 / boot0.5.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/boot0.5.s,v 1.2 2000/08/06 14:35:37 kato Exp $
29 # $DragonFly: src/sys/boot/pc98/boot0.5/Attic/boot0.5.s,v 1.3 2003/11/10 06:08:38 dillon Exp $
30 #
31         .global main
32         .code16
33
34         .text
35 main:
36         # Check hireso mode
37         movw    $0x501, %bx             # BIOS_FLAG
38         call    read_biosparam
39         testb   $0x08, %dl
40         jz      normalmode
41         movb    $1, ishireso
42 normalmode:
43         call    sc_init
44
45         # Display title and copyright.
46         movw    $title, %di
47         call    sc_puts
48         xorw    %cx, %cx
49         movw    $1, %dx
50         call    sc_goto
51         movw    $copyright, %di
52         call    sc_puts
53
54         # Scan hard drives
55         xorw    %si, %si                # number of partition
56         call    scan_sasi               # SASI/IDE
57         call    scan_scsi               # SCSI
58         movw    %si, ndevice
59         orw     %si, %si
60         jnz     drives_found
61         jmp     exit                    # No hard drives
62
63 drives_found:
64         # Setup sector size depended parameters
65         movw    %si, %cx                # %cx = number of devices
66 setup_loop:
67         movw    %cx, %di
68         decw    %di
69         shlw    %di
70         movw    secsize(%di), %ax
71         cmpw    $1024, %ax
72         je      setup_1024
73         cmpw    $512, %ax
74         je      setup_512
75         # 256 bytes/sector
76         movw    $0x100, partoff(%di)
77         movw    $0x0fa, defflagoff(%di)
78         movw    $0x0fb, defpartoff(%di)
79         movw    $8, maxpart(%di)
80         jmp     setup_secsize_end
81         # 1024 bytes/sector
82 setup_1024:
83         # XXX Fix me!
84         movw    $0x400, partoff(%di)
85         movw    $0x3fa, defflagoff(%di)
86         movw    $0x3fb, defpartoff(%di)
87         movb    $32, maxpart(%di)
88         jmp     setup_secsize_end
89         # 512 bytes/sector
90 setup_512:
91         movw    $0x200, partoff(%di)
92         movw    $0x1fa, defflagoff(%di)
93         movw    $0x1fb, defpartoff(%di)
94         movb    $16, maxpart(%di)
95 setup_secsize_end:
96         loop    setup_loop
97
98         # For debug with floppy, fake the parameter.
99         movw    $0x584, %bx             # DISK_BOOT
100         call    read_biosparam
101         andb    $0xf0, %dl
102         cmpb    $0x90, %ah
103         jne     boot_from_hdd
104         movb    daua, %dl
105         call    write_biosparam
106
107 boot_from_hdd:
108         movw    $500, %cx
109 wait_0_5:
110         call    wait1ms
111         loop    wait_0_5
112
113         # If the TAB is pressed, don't try to boot from default partition
114         xorw    %di, %di                # flag
115 wait_key_release:
116         call    sc_iskeypress
117         orw     %ax, %ax
118         jz      key_release             # KBD buffer empty.
119         call    sc_getc
120         cmpb    $0x0f, %ah              # TAB
121         jne     wait_key_release
122         # TAB pressed
123         movw    $1, %di
124         jmp     wait_key_release
125 key_release:
126         orw     %di, %di
127         jnz     dont_try_default        # TAB pressed.
128         call    trydefault
129         # Default partition not found.
130 dont_try_default:
131         call    show_usage
132         call    showdevices
133         call    selector
134 exit:
135         ret
136 #
137 # Display usage
138 #
139 show_usage:
140         movw    $44, %cx
141         movw    $3, %dx
142         call    sc_goto
143         movw    $msg_usage1, %di
144         call    sc_puts
145         movw    $44, %cx
146         movw    $4, %dx
147         call    sc_goto
148         movw    $msg_usage2, %di
149         call    sc_puts
150         movw    $44, %cx
151         movw    $5, %dx
152         call    sc_goto
153         movw    $msg_usage3, %di
154         call    sc_puts
155         movw    $44, %cx
156         movw    $7, %dx
157         call    sc_goto
158         movw    $msg_usage4, %di
159         call    sc_puts
160         movw    $44, %cx
161         movw    $8, %dx
162         call    sc_goto
163         movw    $msg_usage5, %di
164         call    sc_puts
165         movw    $44, %cx
166         movw    $9, %dx
167         call    sc_goto
168         movw    $msg_usage6, %di
169         call    sc_puts
170         movw    $44, %cx
171         movw    $10, %dx
172         call    sc_goto
173         movw    $msg_usage7, %di
174         call    sc_puts
175         movw    $44, %cx
176         movw    $11, %dx
177         call    sc_goto
178         movw    $msg_usage8, %di
179         call    sc_puts
180         movw    $44, %cx
181         movw    $16, %dx
182         call    sc_goto
183         movw    $msg_usage9, %di
184         call    sc_puts
185         movw    $44, %cx
186         movw    $17, %dx
187         call    sc_goto
188         movw    $msg_usage10, %di
189         call    sc_puts
190         movw    $44, %cx
191         movw    $18, %dx
192         call    sc_goto
193         movw    $msg_usage11, %di
194         call    sc_puts
195         movw    $44, %cx
196         movw    $19, %dx
197         call    sc_goto
198         movw    $msg_usage12, %di
199         call    sc_puts
200         ret
201
202 #
203 # Display device list
204 #
205 showdevices:
206         movw    $2, %cx
207         movw    $4, %dx
208         call    sc_goto
209         movw    $msg_device, %di
210         call    sc_puts
211         xorw    %si, %si                # %si = device number
212         movw    ndevice, %cx            # %cx = number of devices
213 showdev_loop:
214         push    %cx
215         movw    $2, %cx
216         movw    $5, %dx
217         addw    %si, %dx
218         call    sc_goto
219         # Check DA
220         movb    daua(%si), %al
221         push    %ax
222         andb    $0xf0, %al
223         cmpb    $0x80, %al
224         je      show_sasi
225         cmpb    $0xa0, %al
226         je      show_scsi
227         # unknown device
228         movw    $msg_unknown, %di
229         call    sc_puts
230         jmp     showunit
231         # SASI
232 show_sasi:
233         movw    $msg_sasi, %di
234         call    sc_puts
235         jmp     showunit
236         # SCSI
237 show_scsi:
238         movw    $msg_scsi, %di
239         call    sc_puts
240         # Display unit number.
241 showunit:
242         pop     %ax
243         andb    $0x0f, %al
244         addb    $'0', %al
245         call    sc_putc
246         incw    %si
247         pop     %cx
248         loop    showdev_loop
249         movw    ndevice, %dx
250         addw    $5, %dx
251         movw    $2, %cx
252         call    sc_goto
253         movw    $msg_exitmenu, %di
254         call    sc_puts
255         ret
256
257         .data
258         .global curdevice, daua, secsize, defflagoff, defpartoff
259         .global maxpart, partoff, ndevice
260 ndevice:        .word   0               # number of device
261 curdevice:      .word   0               # current device
262 daua:           .space  12              # DA/DU list
263 secsize:        .space  12 * 2          # Sector soize
264 defflagoff:     .space  12 * 2
265 defpartoff:     .space  12 * 2
266 maxpart:        .space  12 * 2
267 partoff:        .space  12 * 2
268
269         .global ishireso
270 ishireso:       .byte   0
271
272 title:          .asciz  "PC98 Boot Selector Version 1.1"
273 copyright:      .ascii  "(C)Copyright 1999, 2000 KATO Takenori. "
274                 .asciz  "All rights reserved."
275 msg_device:     .asciz  "Device"
276 msg_sasi:       .asciz  "SASI/IDE unit "
277 msg_scsi:       .asciz  "SCSI ID "
278 msg_unknown:    .asciz  "unknown unit "
279 msg_exitmenu:   .asciz  "Exit this menu"
280 msg_usage1:     .asciz  "Device list"
281 msg_usage2:     .asciz  "UP, DOWN: select boot device"
282 msg_usage3:     .asciz  "RETURN: move to slice list"
283 msg_usage4:     .asciz  "Slice list"
284 msg_usage5:     .asciz  "UP, DOWN: select boot slice"
285 msg_usage6:     .asciz  "RETURN: boot"
286 msg_usage7:     .asciz  "SPACE: toggle default"
287 msg_usage8:     .asciz  "ESC: move to device list"
288 msg_usage9:     .asciz  "LEGEND"
289 msg_usage10:    .asciz  ">>: selected device/slice"
290 msg_usage11:    .asciz  "*: default slice to boot"
291 msg_usage12:    .asciz  "!: unbootable slice"