1 /* $NetBSD: promlib.c,v 1.9 2007/03/04 06:00:48 christos 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.
33 * Specially crafted scaled-down version of promlib for the first-stage
36 * bootxx needs the follwoing PROM functions:
47 #include <sys/errno.h>
48 #include <sys/param.h>
50 #include <machine/stdarg.h>
51 #include <machine/oldmon.h>
52 #include <machine/bsd_openprom.h>
53 #include <machine/promlib.h>
55 #include <lib/libsa/stand.h>
57 #define obpvec ((struct promvec *)romp)
59 static void obp_v2_putchar(int);
60 static int obp_v2_seek(int, u_quad_t
);
61 static const char *obp_v0_getbootpath(void);
62 static const char *obp_v2_getbootpath(void);
67 struct promops promops
;
70 * Determine whether a node has the given property.
86 (*promops
.po_write
)(promops
.po_stdout
, &c0
, 1);
90 obp_v2_seek(int handle
, u_quad_t offset
)
94 lo
= offset
& ((uint32_t)-1);
95 hi
= (offset
>> 32) & ((uint32_t)-1);
96 (*obpvec
->pv_v2devops
.v2_seek
)(handle
, hi
, lo
);
101 * On SS1s (and also IPCs, SLCs), `promvec->pv_v0bootargs->ba_argv[1]'
102 * contains the flags that were given after the boot command. On SS2s
103 * (and ELCs, IPXs, etc. and any sun4m class machine), `pv_v0bootargs'
104 * is NULL but `*promvec->pv_v2bootargs.v2_bootargs' points to
105 * "netbsd -s" or whatever.
108 obp_v0_getbootpath(void)
110 struct v0bootargs
*ba
= promops
.po_bootcookie
;
111 return (ba
->ba_argv
[0]);
115 obp_v2_getbootpath(void)
117 struct v2bootargs
*ba
= promops
.po_bootcookie
;
118 return (*ba
->v2_bootpath
);
122 static void prom_init_oldmon(void);
123 static void prom_init_obp(void);
126 prom_init_oldmon(void)
128 struct om_vector
*oldpvec
= (struct om_vector
*)PROM_BASE
;
130 promops
.po_version
= PROM_OLDMON
;
131 promops
.po_revision
= oldpvec
->monId
[0]; /*XXX*/
133 promops
.po_stdout
= *oldpvec
->outSink
;
134 promops
.po_putchar
= oldpvec
->putChar
;
135 promops
.po_halt
= oldpvec
->exitToMon
;
136 promops
.po_bootcookie
= *oldpvec
->bootParam
; /* deref 1 lvl */
137 promops
.po_bootpath
= obp_v0_getbootpath
;
146 switch (obpvec
->pv_romvec_vers
) {
148 promops
.po_version
= PROM_OBP_V0
;
151 promops
.po_version
= PROM_OBP_V2
;
154 promops
.po_version
= PROM_OBP_V3
;
157 obpvec
->pv_halt(); /* What else? */
160 promops
.po_revision
= obpvec
->pv_printrev
;
161 promops
.po_halt
= obpvec
->pv_halt
;
164 * Next, deal with prom vector differences between versions.
166 switch (promops
.po_version
) {
168 promops
.po_stdout
= *obpvec
->pv_stdout
;
169 promops
.po_putchar
= obpvec
->pv_putchar
;
170 promops
.po_open
= obpvec
->pv_v0devops
.v0_open
;
171 promops
.po_close
= (void *)obpvec
->pv_v0devops
.v0_close
;
172 promops
.po_bootcookie
= *obpvec
->pv_v0bootargs
; /* deref 1 lvl */
173 promops
.po_bootpath
= obp_v0_getbootpath
;
177 /* Deref stdio handles one level */
178 promops
.po_stdout
= *obpvec
->pv_v2bootargs
.v2_fd1
;
179 promops
.po_putchar
= obp_v2_putchar
;
180 promops
.po_open
= obpvec
->pv_v2devops
.v2_open
;
181 promops
.po_close
= (void *)obpvec
->pv_v2devops
.v2_close
;
182 promops
.po_read
= obpvec
->pv_v2devops
.v2_read
;
183 promops
.po_write
= obpvec
->pv_v2devops
.v2_write
;
184 promops
.po_seek
= obp_v2_seek
;
185 promops
.po_bootcookie
= &obpvec
->pv_v2bootargs
;
186 promops
.po_bootpath
= obp_v2_getbootpath
;
192 * Initialize our PROM operations vector.
200 romp
= (void *)PROM_LOADADDR
; /* Used in main() */
201 } else if (obpvec
->pv_magic
== OBP_MAGIC
) {
204 /* No Openfirmware support */