1 /* $NetBSD: promlib.c,v 1.2 1999/05/03 16:13:16 christos 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 #include <machine/openfirm.h> 62 63 #include <lib/libsa/stand.h> 64 65 #define obpvec ((struct promvec *)romp) 66 67 static void obp_v2_putchar __P((int)); 68 static int obp_v2_seek __P((int, u_quad_t)); 69 static char *obp_v0_getbootpath __P((void)); 70 static char *obp_v2_getbootpath __P((void)); 71 72 /* 73 * PROM entry points. 74 */ 75 struct promops promops; 76 77 /* 78 * Determine whether a node has the given property. 79 */ 80 void 81 prom_halt() 82 { 83 84 _prom_halt(); 85 } 86 87 88 void 89 obp_v2_putchar(c) 90 int c; 91 { 92 char c0; 93 94 c0 = (c & 0x7f); 95 (*promops.po_write)(promops.po_stdout, &c0, 1); 96 } 97 98 int 99 obp_v2_seek(handle, offset) 100 int handle; 101 u_quad_t offset; 102 { 103 u_int32_t hi, lo; 104 105 lo = offset & ((u_int32_t)-1); 106 hi = (offset >> 32) & ((u_int32_t)-1); 107 (*obpvec->pv_v2devops.v2_seek)(handle, hi, lo); 108 return (0); 109 } 110 111 /* 112 * On SS1s (and also IPCs, SLCs), `promvec->pv_v0bootargs->ba_argv[1]' 113 * contains the flags that were given after the boot command. On SS2s 114 * (and ELCs, IPXs, etc. and any sun4m class machine), `pv_v0bootargs' 115 * is NULL but `*promvec->pv_v2bootargs.v2_bootargs' points to 116 * "netbsd -s" or whatever. 117 */ 118 char * 119 obp_v0_getbootpath() 120 { 121 struct v0bootargs *ba = promops.po_bootcookie; 122 return (ba->ba_argv[0]); 123 } 124 125 char * 126 obp_v2_getbootpath() 127 { 128 struct v2bootargs *ba = promops.po_bootcookie; 129 return (*ba->v2_bootpath); 130 } 131 132 133 static void prom_init_oldmon __P((void)); 134 static void prom_init_obp __P((void)); 135 136 static __inline__ void 137 prom_init_oldmon() 138 { 139 struct om_vector *oldpvec = (struct om_vector *)PROM_BASE; 140 141 promops.po_version = PROM_OLDMON; 142 promops.po_revision = oldpvec->monId[0]; /*XXX*/ 143 144 promops.po_stdout = *oldpvec->outSink; 145 promops.po_putchar = oldpvec->putChar; 146 promops.po_halt = oldpvec->exitToMon; 147 promops.po_bootcookie = *oldpvec->bootParam; /* deref 1 lvl */ 148 promops.po_bootpath = obp_v0_getbootpath; 149 } 150 151 static __inline__ void 152 prom_init_obp() 153 { 154 /* 155 * OBP v0, v2 & v3 156 */ 157 switch (obpvec->pv_romvec_vers) { 158 case 0: 159 promops.po_version = PROM_OBP_V0; 160 break; 161 case 2: 162 promops.po_version = PROM_OBP_V2; 163 break; 164 case 3: 165 promops.po_version = PROM_OBP_V3; 166 break; 167 default: 168 obpvec->pv_halt(); /* What else? */ 169 } 170 171 promops.po_revision = obpvec->pv_printrev; 172 promops.po_halt = obpvec->pv_halt; 173 174 /* 175 * Next, deal with prom vector differences between versions. 176 */ 177 switch (promops.po_version) { 178 case PROM_OBP_V0: 179 promops.po_stdout = *obpvec->pv_stdout; 180 promops.po_putchar = obpvec->pv_putchar; 181 promops.po_open = obpvec->pv_v0devops.v0_open; 182 promops.po_close = (void *)obpvec->pv_v0devops.v0_close; 183 promops.po_bootcookie = *obpvec->pv_v0bootargs; /* deref 1 lvl */ 184 promops.po_bootpath = obp_v0_getbootpath; 185 break; 186 case PROM_OBP_V3: 187 case PROM_OBP_V2: 188 /* Deref stdio handles one level */ 189 promops.po_stdout = *obpvec->pv_v2bootargs.v2_fd1; 190 promops.po_putchar = obp_v2_putchar; 191 promops.po_open = obpvec->pv_v2devops.v2_open; 192 promops.po_close = (void *)obpvec->pv_v2devops.v2_close; 193 promops.po_read = obpvec->pv_v2devops.v2_read; 194 promops.po_write = obpvec->pv_v2devops.v2_write; 195 promops.po_seek = obp_v2_seek; 196 promops.po_bootcookie = &obpvec->pv_v2bootargs; 197 promops.po_bootpath = obp_v2_getbootpath; 198 break; 199 } 200 } 201 202 /* 203 * Initialize our PROM operations vector. 204 */ 205 void 206 prom_init() 207 { 208 209 if (CPU_ISSUN4) { 210 prom_init_oldmon(); 211 romp = (caddr_t)PROM_LOADADDR; /* Used in main() */ 212 } else if (obpvec->pv_magic == OBP_MAGIC) { 213 prom_init_obp(); 214 } else { 215 /* No Openfirmware support */ 216 } 217 } 218