1 /* $NetBSD: promlib.c,v 1.3 2003/02/26 17:39:08 pk 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Specially crafted scaled-down version of promlib for the first-stage 41 * boot program. 42 * 43 * bootxx needs the follwoing PROM functions: 44 * prom_version() 45 * prom_getbootpath() 46 * prom_putchar() 47 * prom_halt() 48 * prom_open() 49 * prom_close() 50 * prom_seek() 51 * prom_read() 52 */ 53 54 #include <sys/errno.h> 55 #include <sys/param.h> 56 57 #include <machine/stdarg.h> 58 #include <machine/oldmon.h> 59 #include <machine/bsd_openprom.h> 60 #include <machine/promlib.h> 61 62 #include <lib/libsa/stand.h> 63 64 #define obpvec ((struct promvec *)romp) 65 66 static void obp_v2_putchar __P((int)); 67 static int obp_v2_seek __P((int, u_quad_t)); 68 static char *obp_v0_getbootpath __P((void)); 69 static char *obp_v2_getbootpath __P((void)); 70 71 /* 72 * PROM entry points. 73 */ 74 struct promops promops; 75 76 /* 77 * Determine whether a node has the given property. 78 */ 79 void 80 prom_halt() 81 { 82 83 _prom_halt(); 84 } 85 86 87 void 88 obp_v2_putchar(c) 89 int c; 90 { 91 char c0; 92 93 c0 = (c & 0x7f); 94 (*promops.po_write)(promops.po_stdout, &c0, 1); 95 } 96 97 int 98 obp_v2_seek(handle, offset) 99 int handle; 100 u_quad_t offset; 101 { 102 u_int32_t hi, lo; 103 104 lo = offset & ((u_int32_t)-1); 105 hi = (offset >> 32) & ((u_int32_t)-1); 106 (*obpvec->pv_v2devops.v2_seek)(handle, hi, lo); 107 return (0); 108 } 109 110 /* 111 * On SS1s (and also IPCs, SLCs), `promvec->pv_v0bootargs->ba_argv[1]' 112 * contains the flags that were given after the boot command. On SS2s 113 * (and ELCs, IPXs, etc. and any sun4m class machine), `pv_v0bootargs' 114 * is NULL but `*promvec->pv_v2bootargs.v2_bootargs' points to 115 * "netbsd -s" or whatever. 116 */ 117 char * 118 obp_v0_getbootpath() 119 { 120 struct v0bootargs *ba = promops.po_bootcookie; 121 return (ba->ba_argv[0]); 122 } 123 124 char * 125 obp_v2_getbootpath() 126 { 127 struct v2bootargs *ba = promops.po_bootcookie; 128 return (*ba->v2_bootpath); 129 } 130 131 132 static void prom_init_oldmon __P((void)); 133 static void prom_init_obp __P((void)); 134 135 static __inline__ void 136 prom_init_oldmon() 137 { 138 struct om_vector *oldpvec = (struct om_vector *)PROM_BASE; 139 140 promops.po_version = PROM_OLDMON; 141 promops.po_revision = oldpvec->monId[0]; /*XXX*/ 142 143 promops.po_stdout = *oldpvec->outSink; 144 promops.po_putchar = oldpvec->putChar; 145 promops.po_halt = oldpvec->exitToMon; 146 promops.po_bootcookie = *oldpvec->bootParam; /* deref 1 lvl */ 147 promops.po_bootpath = obp_v0_getbootpath; 148 } 149 150 static __inline__ void 151 prom_init_obp() 152 { 153 /* 154 * OBP v0, v2 & v3 155 */ 156 switch (obpvec->pv_romvec_vers) { 157 case 0: 158 promops.po_version = PROM_OBP_V0; 159 break; 160 case 2: 161 promops.po_version = PROM_OBP_V2; 162 break; 163 case 3: 164 promops.po_version = PROM_OBP_V3; 165 break; 166 default: 167 obpvec->pv_halt(); /* What else? */ 168 } 169 170 promops.po_revision = obpvec->pv_printrev; 171 promops.po_halt = obpvec->pv_halt; 172 173 /* 174 * Next, deal with prom vector differences between versions. 175 */ 176 switch (promops.po_version) { 177 case PROM_OBP_V0: 178 promops.po_stdout = *obpvec->pv_stdout; 179 promops.po_putchar = obpvec->pv_putchar; 180 promops.po_open = obpvec->pv_v0devops.v0_open; 181 promops.po_close = (void *)obpvec->pv_v0devops.v0_close; 182 promops.po_bootcookie = *obpvec->pv_v0bootargs; /* deref 1 lvl */ 183 promops.po_bootpath = obp_v0_getbootpath; 184 break; 185 case PROM_OBP_V3: 186 case PROM_OBP_V2: 187 /* Deref stdio handles one level */ 188 promops.po_stdout = *obpvec->pv_v2bootargs.v2_fd1; 189 promops.po_putchar = obp_v2_putchar; 190 promops.po_open = obpvec->pv_v2devops.v2_open; 191 promops.po_close = (void *)obpvec->pv_v2devops.v2_close; 192 promops.po_read = obpvec->pv_v2devops.v2_read; 193 promops.po_write = obpvec->pv_v2devops.v2_write; 194 promops.po_seek = obp_v2_seek; 195 promops.po_bootcookie = &obpvec->pv_v2bootargs; 196 promops.po_bootpath = obp_v2_getbootpath; 197 break; 198 } 199 } 200 201 /* 202 * Initialize our PROM operations vector. 203 */ 204 void 205 prom_init() 206 { 207 208 if (CPU_ISSUN4) { 209 prom_init_oldmon(); 210 romp = (caddr_t)PROM_LOADADDR; /* Used in main() */ 211 } else if (obpvec->pv_magic == OBP_MAGIC) { 212 prom_init_obp(); 213 } else { 214 /* No Openfirmware support */ 215 } 216 } 217