Home | History | Annotate | Line # | Download | only in bootxx
promlib.c revision 1.9.40.1
      1 /*	$NetBSD: promlib.c,v 1.9.40.1 2008/06/02 13:22:42 mjf Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Paul Kranenburg.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     18  *
     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.
     30  */
     31 
     32 /*
     33  * Specially crafted scaled-down version of promlib for the first-stage
     34  * boot program.
     35  *
     36  * bootxx needs the follwoing PROM functions:
     37  *	prom_version()
     38  *	prom_getbootpath()
     39  *	prom_putchar()
     40  *	prom_halt()
     41  *	prom_open()
     42  *	prom_close()
     43  *	prom_seek()
     44  *	prom_read()
     45  */
     46 
     47 #include <sys/errno.h>
     48 #include <sys/param.h>
     49 
     50 #include <machine/stdarg.h>
     51 #include <machine/oldmon.h>
     52 #include <machine/bsd_openprom.h>
     53 #include <machine/promlib.h>
     54 
     55 #include <lib/libsa/stand.h>
     56 
     57 #define obpvec ((struct promvec *)romp)
     58 
     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);
     63 
     64 /*
     65  * PROM entry points.
     66  */
     67 struct promops promops;
     68 
     69 /*
     70  * Determine whether a node has the given property.
     71  */
     72 void
     73 prom_halt(void)
     74 {
     75 
     76 	_prom_halt();
     77 }
     78 
     79 
     80 void
     81 obp_v2_putchar(int c)
     82 {
     83 	char c0;
     84 
     85 	c0 = (c & 0x7f);
     86 	(*promops.po_write)(promops.po_stdout, &c0, 1);
     87 }
     88 
     89 int
     90 obp_v2_seek(int handle, u_quad_t offset)
     91 {
     92 	uint32_t hi, lo;
     93 
     94 	lo = offset & ((uint32_t)-1);
     95 	hi = (offset >> 32) & ((uint32_t)-1);
     96 	(*obpvec->pv_v2devops.v2_seek)(handle, hi, lo);
     97 	return (0);
     98 }
     99 
    100 /*
    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.
    106  */
    107 const char *
    108 obp_v0_getbootpath(void)
    109 {
    110 	struct v0bootargs *ba = promops.po_bootcookie;
    111 	return (ba->ba_argv[0]);
    112 }
    113 
    114 const char *
    115 obp_v2_getbootpath(void)
    116 {
    117 	struct v2bootargs *ba = promops.po_bootcookie;
    118 	return (*ba->v2_bootpath);
    119 }
    120 
    121 
    122 static void prom_init_oldmon(void);
    123 static void prom_init_obp(void);
    124 
    125 static inline void
    126 prom_init_oldmon(void)
    127 {
    128 	struct om_vector *oldpvec = (struct om_vector *)PROM_BASE;
    129 
    130 	promops.po_version = PROM_OLDMON;
    131 	promops.po_revision = oldpvec->monId[0];	/*XXX*/
    132 
    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;
    138 }
    139 
    140 static inline void
    141 prom_init_obp(void)
    142 {
    143 	/*
    144 	 * OBP v0, v2 & v3
    145 	 */
    146 	switch (obpvec->pv_romvec_vers) {
    147 	case 0:
    148 		promops.po_version = PROM_OBP_V0;
    149 		break;
    150 	case 2:
    151 		promops.po_version = PROM_OBP_V2;
    152 		break;
    153 	case 3:
    154 		promops.po_version = PROM_OBP_V3;
    155 		break;
    156 	default:
    157 		obpvec->pv_halt();	/* What else? */
    158 	}
    159 
    160 	promops.po_revision = obpvec->pv_printrev;
    161 	promops.po_halt = obpvec->pv_halt;
    162 
    163 	/*
    164 	 * Next, deal with prom vector differences between versions.
    165 	 */
    166 	switch (promops.po_version) {
    167 	case PROM_OBP_V0:
    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;
    174 		break;
    175 	case PROM_OBP_V3:
    176 	case PROM_OBP_V2:
    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;
    187 		break;
    188 	}
    189 }
    190 
    191 /*
    192  * Initialize our PROM operations vector.
    193  */
    194 void
    195 prom_init(void)
    196 {
    197 
    198 	if (CPU_ISSUN4) {
    199 		prom_init_oldmon();
    200 		romp = (void *)PROM_LOADADDR;	/* Used in main() */
    201 	} else if (obpvec->pv_magic == OBP_MAGIC) {
    202 		prom_init_obp();
    203 	} else {
    204 		/* No Openfirmware support */
    205 	}
    206 }
    207