Merge from vendor branch OPENSSH:
[dragonfly.git] / sys / boot / pc98 / boot0.5 / boot.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/boot.s,v 1.2 2000/08/03 13:01:45 kato Exp $
29 # $DragonFly: src/sys/boot/pc98/boot0.5/Attic/boot.s,v 1.3 2003/11/10 06:08:38 dillon Exp $
30 #
31
32         .code16
33
34         .text
35         .global boot
36 #
37 # Read bootstrap program and jump to it.
38 #
39 boot:
40         # Step 1: Save parameters
41         movw    curdevice, %si
42         movb    daua(%si), %al
43         movb    %al, b_daua
44         shlw    %si
45         movw    secsize(%si), %ax
46         movw    %ax, b_secsize
47
48         movw    curpartition, %si
49         movb    partnum(%si), %al       # %al = real partition number
50         xorb    %ah, %ah
51         movw    %ax, b_partn            # save real parttion number
52         movb    $5, %cl
53         shlw    %cl, %si                # %si = offset to parttable
54         addw    $4, %si
55         movb    parttable(%si), %al     # IPLS
56         movb    %al, b_sector
57         incw    %si
58         movb    parttable(%si), %al     # IPLH
59         movb    %al, b_head
60         incw    %si                     # IPLC
61         movw    parttable(%si), %ax
62         movw    %ax, b_cylinder
63
64         # Step 2: Calculate egment address of bootstrap routine
65         movw    $0x1d00, %ax
66         movw    b_secsize, %cx
67         shrw    %cx
68         shrw    %cx
69         subw    %cx, %ax
70         subw    $0x100, %ax
71         movw    %ax, b_bootseg
72
73         # Step 3: Read bootstrap code
74         movb    $6, %ah
75         movb    b_daua, %al
76         movw    b_secsize, %bx
77         shlw    %bx                     # 2 sectors
78         movw    b_cylinder, %cx
79         movb    b_head, %dh
80         movb    b_sector, %dl
81         movw    b_bootseg, %es
82         xorw    %bp, %bp
83         int     $0x1b
84         jc      boot_error
85
86         # Step 4: Set DA/UA into BIOS work area
87         xorw    %ax, %ax
88         movw    %ax, %es
89         movw    $0x584, %bx             # DISK_BOOT
90         movb    b_daua, %dl
91         call    write_biosparam
92
93         call    sc_clean
94         # Step 5: Set registers
95         #       %ah:    00
96         #       %al:    DA/UA
97         #       %bx:    Sector size * 2
98         #       %cx:    cylinder number of boot partition
99         #       %si:    pointer to partition table
100         movw    b_partn, %ax
101         movb    $5, %cl
102         shl     %cl, %ax                # %ax = partition number * 32
103         addw    b_secsize, %ax
104         movw    %ax, %si                # %si = pointer to partition table
105         movw    b_cylinder, %cx         # %cx = cylinder
106         movb    b_head, %dh             # %dh = head
107         movb    b_sector, %dl           # %dl = sector
108         movw    b_bootseg, %es          # %es = boot segment
109         movb    b_daua, %al             # %al = DA/UA
110         movw    b_secsize, %bx
111         shlw    %bx                     # %bx = sector size * 2
112         cli
113         movw    %cs:iniss, %ss          # Restore stack pointer
114         movw    %cs:inisp, %sp
115         push    %es                     # Boot segment
116         xorw    %bp, %bp
117         push    %bp                     # 0
118         movw    %ax, %di                # Save %ax
119         xorw    %ax, %ax
120         movw    %ax, %ds                # %ds = 0
121         movw    %di, %ax                # Restore %ax
122         xorb    %ah, %ah                # %ah = 0
123         xorw    %di, %di                # %di = 0
124         sti
125
126         # Jump to bootstrap code
127         lret
128         # NOTREACHED
129
130 boot_error:
131         ret
132
133 #
134 # Try to boot from default partition.
135 #
136         .global trydefault
137 trydefault:
138         movw    ndevice, %cx
139         xorw    %si, %si
140 trydefault_loop:
141         movw    %si, curdevice
142         push    %cx
143         push    %si
144         call    read_ipl
145         pop     %si
146         pop     %cx
147         cmpb    $0x80, defpartflag
148         jne     nodefpart
149         # Default partition is defined.
150         push    %cx
151         movw    npartition, %cx
152 srch_part:
153         movw    %cx, %bx
154         decw    %bx
155         movb    defpartnum, %al         # %al = real partition number
156         cmpb    partnum(%bx), %al
157         jne     not_match
158         movw    %bx, curpartition       # Store partition number
159         call    boot
160 not_match:
161         loop    srch_part
162         pop     %cx
163 nodefpart:
164         incw    %si
165         loop    trydefault_loop
166         ret
167
168         .data
169 b_daua:         .byte   0               # DA/UA
170 b_head:         .byte   0               # SYSH
171 b_sector:       .byte   0               # SYSS
172 b_cylinder:     .word   0               # SYSC
173 b_bootseg:      .word   0
174 b_secsize:      .word   0
175 b_partn:        .word   0               # Real partition number