1 /* $NetBSD: mboot.c,v 1.7 2009/01/12 07:56:31 tsutsui Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
33 #include <machine/disklabel.h>
44 register unsigned int reg_d0
__asm ("%d0");
46 __asm
volatile ("movel %1,%%d1\n\t"
56 IOCS_B_PRINT (const char *str
)
58 __asm
volatile ("moval %0,%%a1\n\t"
59 "movel #0x21,%%d0\n\t"
67 IOCS_S_READCAP (int id
, struct iocs_readcap
*cap
)
69 register int reg_d0
__asm ("%d0");
71 __asm
volatile ("moveml %%d4,%%sp@-\n\t"
74 "movel #0x25,%%d1\n\t"
75 "movel #0xf5,%%d0\n\t"
78 : "=d" (reg_d0
), "=m" (*cap
)
79 : "ri" (id
), "g" ((int) cap
)
85 IOCS_S_READ (int pos
, int blk
, int id
, int size
, void *buf
)
87 register int reg_d0
__asm ("%d0");
89 __asm
volatile ("moveml %%d3-%%d5,%%sp@-\n\t"
95 "movel #0x26,%%d1\n\t"
96 "movel #0xf5,%%d0\n\t"
98 "moveml %%sp@+,%%d3-%%d5"
99 : "=d" (reg_d0
), "=m" (*(char*) buf
)
100 : "ri" (pos
), "ri" (blk
), "ri" (id
), "ri" (size
), "g" ((int) buf
)
101 : "%d1", "%d2", "%a1");
107 IOCS_S_READEXT (int pos
, int blk
, int id
, int size
, void *buf
)
109 register int reg_d0
__asm ("%d0");
111 __asm
volatile ("moveml %%d3-%%d5,%%sp@-\n\t"
117 "movel #0x26,%%d1\n\t"
118 "movel #0xf5,%%d0\n\t"
120 "moveml %%sp@+,%%d3-%%d5"
121 : "=d" (reg_d0
), "=m" (*(char*) buf
)
122 : "ri" (pos
), "ri" (blk
), "ri" (id
), "ri" (size
), "g" ((int) buf
)
123 : "%d1", "%d2", "%a1");
128 #define PART_BOOTABLE 0
129 #define PART_UNUSED 1
137 struct iocs_readcap cap
;
140 if (IOCS_BITSNS(0) & 1) /* ESC key */
143 if (IOCS_S_READCAP(scsiid
, &cap
) < 0) {
144 IOCS_B_PRINT("Error in reading.\r\n");
147 size
= cap
.size
>> 9;
150 long *label
= (void*) 0x3000;
151 if (IOCS_S_READ(0, 1, scsiid
, size
, label
) < 0) {
152 IOCS_B_PRINT("Error in reading.\r\n");
155 if (label
[0] != 0x58363853 ||
156 label
[1] != 0x43534931) {
157 IOCS_B_PRINT("Invalid disk.\r\n");
163 struct cpu_disklabel
*label
= (void*) 0x3000;
164 int i
, firstinuse
=-1;
166 if (IOCS_S_READ(2<<(2-size
), size
?2:1, scsiid
, size
, label
) < 0) {
167 IOCS_B_PRINT("Error in reading.\r\n");
170 if (*((long*) &label
->dosparts
[0].dp_typname
) != 0x5836384b) {
171 IOCS_B_PRINT("Invalid disk.\r\n");
175 for (i
= 1; i
< NDOSPART
; i
++) {
176 if (label
->dosparts
[i
].dp_flag
== PART_BOOTABLE
)
178 else if (label
->dosparts
[i
].dp_flag
== PART_INUSE
)
181 if (i
>= NDOSPART
&& firstinuse
>= 0)
184 unsigned int start
= label
->dosparts
[i
].dp_start
;
185 unsigned int start1
= start
<< (2-size
);
187 if ((start1
& 0x1fffff) == 0x1fffff)
188 r
= IOCS_S_READ(start1
,
194 r
= IOCS_S_READEXT(start1
,
200 IOCS_B_PRINT ("Error in reading.\r\n");
203 if (*((char*) 0x2400) != 0x60) {
204 IOCS_B_PRINT("Invalid disk.\r\n");
207 __asm
volatile ("movl %0,%%d4\n\t"
211 : "g" (scsiid
), "g"(start
)
215 IOCS_B_PRINT ("No bootable partition.\r\n");