Use PROMLIB to streamline this code. This also provides the bulk of

Open Firmware boot code.
This commit is contained in:
pk 1999-02-15 18:59:36 +00:00
parent 8460b71d8d
commit d292580f3f
10 changed files with 675 additions and 441 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.9 1997/12/18 21:03:58 pk Exp $
# $NetBSD: Makefile,v 1.10 1999/02/15 18:59:36 pk Exp $
PROG= boot
PROGSOURCE= boot.c net.c netif_sun.c conf.c
PROGSOURCE= boot.c net.c netif_sun.c conf.c openfirm.c
NEWVERSWHAT= "Secondary Boot"
CLEANFILES+= vers.c vers.o

View File

@ -1,4 +1,4 @@
/* $NetBSD: boot.c,v 1.3 1998/08/29 06:40:43 mrg Exp $ */
/* $NetBSD: boot.c,v 1.4 1999/02/15 18:59:36 pk Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
@ -41,10 +41,15 @@
#include <lib/libsa/stand.h>
#include <machine/promlib.h>
#include <sparc/stand/common/promdev.h>
static void copyunix __P((int, char *));
static void promsyms __P((int, struct exec *));
static int bootoptions __P((char *));
void loadfile __P((int, caddr_t));
#if 0
static void promsyms __P((int, struct exec *));
#endif
int debug;
int netif_debug;
@ -54,9 +59,9 @@ char *strtab;
int strtablen;
char fbuf[80], dbuf[128];
int main __P((void));
typedef void (*entry_t)__P((caddr_t, int, int, int, long, long));
void loadfile __P((int, caddr_t));
/*
* Boot device is derived from ROM provided information, or if there is none,
@ -79,10 +84,39 @@ char *kernels[] = {
NULL
};
int
bootoptions(ap)
char *ap;
{
int v = 0;
if (ap == NULL || *ap++ != '-')
return (0);
while (*ap != '\0' && *ap != ' ' && *ap != '\t' && *ap != '\n') {
switch (*ap) {
case 'a':
v |= RB_ASKNAME;
break;
case 's':
v |= RB_SINGLE;
break;
case 'd':
v |= RB_KDB;
debug = 1;
break;
}
ap++;
}
return (v);
}
int
main()
{
int io, i;
char *kernel;
int how;
prom_init();
@ -92,9 +126,12 @@ main()
/*
* get default kernel.
*/
if (prom_bootfile && *prom_bootfile) {
prom_bootdevice = prom_getbootpath();
kernel = prom_getbootfile();
how = bootoptions(prom_getbootargs());
if (kernel != NULL && *kernel != '\0') {
i = -1; /* not using the kernels */
kernel = prom_bootfile;
} else {
i = 0;
kernel = kernels[i];
@ -104,9 +141,9 @@ main()
/*
* ask for a kernel first ..
*/
if (prom_boothow & RB_ASKNAME) {
if (how & RB_ASKNAME) {
printf("device[%s] (\"halt\" to halt): ",
prom_bootdevice);
prom_bootdevice);
gets(dbuf);
if (strcmp(dbuf, "halt") == 0)
_rtt();
@ -117,7 +154,7 @@ main()
if (fbuf[0])
kernel = fbuf;
else {
prom_boothow &= ~RB_ASKNAME;
how &= ~RB_ASKNAME;
i = 0;
kernel = kernels[i];
}
@ -132,13 +169,13 @@ main()
* prom bootfile, try the next one (if it exits). otherwise,
* go into askname mode.
*/
if ((prom_boothow & RB_ASKNAME) == 0 &&
if ((how & RB_ASKNAME) == 0 &&
i != -1 && kernels[++i]) {
kernel = kernels[i];
printf(": trying %s...\n", kernel);
} else {
printf("\n");
prom_boothow |= RB_ASKNAME;
how |= RB_ASKNAME;
}
}
@ -147,18 +184,19 @@ main()
* make loadfile() return a value, so that if the load of the kernel
* fails, we can jump back and try another kernel in the list.
*/
printf("Booting %s @ 0x%x\n", kernel, LOADADDR);
loadfile(io, LOADADDR);
printf("Booting %s @ %p\n", kernel, PROM_LOADADDR);
loadfile(io, PROM_LOADADDR);
_rtt();
}
void
loadfile(io, addr)
register int io;
register caddr_t addr;
int io;
caddr_t addr;
{
register entry_t entry = (entry_t)LOADADDR;
entry_t entry = (entry_t)PROM_LOADADDR;
void *arg;
struct exec x;
int i;
@ -168,7 +206,7 @@ loadfile(io, addr)
printf("Bad format\n");
return;
}
printf("%d", x.a_text);
printf("%ld", x.a_text);
if (N_GETMAGIC(x) == ZMAGIC) {
entry = (entry_t)(addr+sizeof(struct exec));
addr += sizeof(struct exec);
@ -179,17 +217,17 @@ loadfile(io, addr)
if (N_GETMAGIC(x) == ZMAGIC || N_GETMAGIC(x) == NMAGIC)
while ((int)addr & __LDPGSZ)
*addr++ = 0;
printf("+%d", x.a_data);
printf("+%ld", x.a_data);
if (read(io, addr, x.a_data) != x.a_data)
goto shread;
addr += x.a_data;
printf("+%d", x.a_bss);
printf("+%ld", x.a_bss);
for (i = 0; i < x.a_bss; i++)
*addr++ = 0;
if (x.a_syms != 0) {
bcopy(&x.a_syms, addr, sizeof(x.a_syms));
addr += sizeof(x.a_syms);
printf("+[%d", x.a_syms);
printf("+[%ld", x.a_syms);
if (read(io, addr, x.a_syms) != x.a_syms)
goto shread;
addr += x.a_syms;
@ -198,7 +236,7 @@ loadfile(io, addr)
goto shread;
bcopy(&strtablen, addr, sizeof(int));
if (i = strtablen) {
if ((i = strtablen) != 0) {
i -= sizeof(int);
addr += sizeof(int);
if (read(io, addr, i) != i)
@ -206,7 +244,7 @@ loadfile(io, addr)
addr += i;
}
printf("+%d]", i);
esym = ((u_int)x.a_entry - (u_int)LOADADDR) +
esym = ((u_int)x.a_entry - (u_int)PROM_LOADADDR) +
(((int)addr + sizeof(int) - 1) & ~(sizeof(int) - 1));
#if 0
/*
@ -217,12 +255,12 @@ loadfile(io, addr)
promsyms(io, &x);
#endif
}
printf("=0x%x\n", addr);
printf("=%p\n", addr);
close(io);
/* Note: args 2-4 not used due to conflicts with SunOS loaders */
(*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec,
0, 0, 0, esym, DDB_MAGIC1);
arg = (prom_version() == PROM_OLDMON) ? PROM_LOADADDR : romp;
(*entry)(arg, 0, 0, 0, esym, DDB_MAGIC1);
return;
shread:
@ -311,6 +349,6 @@ promsyms(fd, hp)
}
sprintf(buf, "%x %d %x loadsyms", syms, n, str);
(promvec->pv_fortheval.v2_eval)(buf);
prom_interpret(buf);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootxx.c,v 1.3 1998/09/05 15:12:26 pk Exp $ */
/* $NetBSD: bootxx.c,v 1.4 1999/02/15 18:59:36 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -42,6 +42,7 @@
#include <lib/libsa/stand.h>
#include <machine/promlib.h>
#include <sparc/stand/common/promdev.h>
int debug;
@ -65,34 +66,39 @@ int32_t block_count = MAXBLOCKNUM;
daddr_t block_table[MAXBLOCKNUM] = { 0 };
int main __P((void));
void loadboot __P((struct open_file *, caddr_t));
int
main()
{
char *dummy;
size_t n;
register void (*entry)__P((caddr_t)) = (void (*)__P((caddr_t)))LOADADDR;
void (*entry)__P((void *)) = (void (*)__P((void *)))PROM_LOADADDR;
void *arg;
prom_init();
prom_bootdevice = prom_getbootpath();
io.f_flags = F_RAW;
if (devopen(&io, 0, &dummy)) {
panic("%s: can't open device", progname);
panic("%s: can't open device `%s'", progname,
prom_bootdevice != NULL ? prom_bootdevice : "unknown");
}
(void)loadboot(&io, LOADADDR);
(void)loadboot(&io, PROM_LOADADDR);
(io.f_dev->dv_close)(&io);
(*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec);
arg = (prom_version() == PROM_OLDMON) ? PROM_LOADADDR : romp;
(*entry)(arg);
_rtt();
}
void
loadboot(f, addr)
register struct open_file *f;
register char *addr;
struct open_file *f;
char *addr;
{
register int i;
register char *buf;
int i;
char *buf;
size_t n;
daddr_t blk;
@ -114,13 +120,14 @@ loadboot(f, addr)
#endif
if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ,
blk, block_size, buf, &n)) {
panic("%s: read failure", progname);
printf("%s: read failure", progname);
_rtt();
}
bcopy(buf, addr, block_size);
if (n != block_size)
panic("%s: short read", progname);
if (i == 0) {
register int m = N_GETMAGIC(*(struct exec *)addr);
int m = N_GETMAGIC(*(struct exec *)addr);
if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) {
/* Move exec header out of the way */
bcopy(addr, addr - sizeof(struct exec), n);
@ -131,3 +138,20 @@ loadboot(f, addr)
}
}
/*
* We don't need the overlap handling feature that the libkern version
* of bcopy() provides. We DO need code compactness..
*/
void
bcopy(src, dst, n)
const void *src;
void *dst;
size_t n;
{
const char *p = src;
char *q = dst;
while (n-- > 0)
*q++ = *p++;
}

View File

@ -0,0 +1,217 @@
/* $NetBSD: promlib.c,v 1.1 1999/02/15 18:59:36 pk Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Specially crafted scaled-down version of promlib for the first-stage
* boot program.
*
* bootxx needs the follwoing PROM functions:
* prom_version()
* prom_getbootpath()
* prom_putchar()
* prom_halt()
* prom_open()
* prom_close()
* prom_seek()
* prom_read()
*/
#include <sys/errno.h>
#include <sys/param.h>
#include <machine/stdarg.h>
#include <machine/oldmon.h>
#include <machine/bsd_openprom.h>
#include <machine/promlib.h>
#include <machine/openfirm.h>
#include <lib/libsa/stand.h>
#define obpvec ((struct promvec *)romp)
static void obp_v2_putchar __P((int));
static int obp_v2_seek __P((int, u_quad_t));
static char *obp_v0_getbootpath __P((void));
static char *obp_v2_getbootpath __P((void));
/*
* PROM entry points.
*/
struct promops promops;
/*
* Determine whether a node has the given property.
*/
void
prom_halt()
{
_prom_halt();
}
void
obp_v2_putchar(c)
int c;
{
char c0;
c0 = (c & 0x7f);
(*promops.po_write)(promops.po_stdout, &c0, 1);
}
int
obp_v2_seek(handle, offset)
int handle;
u_quad_t offset;
{
u_int32_t hi, lo;
lo = offset & ((u_int32_t)-1);
hi = (offset >> 32) & ((u_int32_t)-1);
(*obpvec->pv_v2devops.v2_seek)(handle, hi, lo);
return (0);
}
/*
* On SS1s (and also IPCs, SLCs), `promvec->pv_v0bootargs->ba_argv[1]'
* contains the flags that were given after the boot command. On SS2s
* (and ELCs, IPXs, etc. and any sun4m class machine), `pv_v0bootargs'
* is NULL but `*promvec->pv_v2bootargs.v2_bootargs' points to
* "netbsd -s" or whatever.
*/
char *
obp_v0_getbootpath()
{
struct v0bootargs *ba = promops.po_bootcookie;
return (ba->ba_argv[0]);
}
char *
obp_v2_getbootpath()
{
struct v2bootargs *ba = promops.po_bootcookie;
return (*ba->v2_bootpath);
}
static void prom_init_oldmon __P((void));
static void prom_init_obp __P((void));
static __inline__ void
prom_init_oldmon()
{
struct om_vector *oldpvec = (struct om_vector *)PROM_BASE;
promops.po_version = PROM_OLDMON;
promops.po_revision = oldpvec->monId[0]; /*XXX*/
promops.po_stdout = *oldpvec->outSink;
promops.po_putchar = oldpvec->putChar;
promops.po_halt = oldpvec->exitToMon;
promops.po_bootcookie = *oldpvec->bootParam; /* deref 1 lvl */
promops.po_bootpath = obp_v0_getbootpath;
}
static __inline__ void
prom_init_obp()
{
/*
* OBP v0, v2 & v3
*/
switch (obpvec->pv_romvec_vers) {
case 0:
promops.po_version = PROM_OBP_V0;
break;
case 2:
promops.po_version = PROM_OBP_V2;
break;
case 3:
promops.po_version = PROM_OBP_V3;
break;
default:
obpvec->pv_halt(); /* What else? */
}
promops.po_revision = obpvec->pv_printrev;
promops.po_halt = obpvec->pv_halt;
/*
* Next, deal with prom vector differences between versions.
*/
switch (promops.po_version) {
case PROM_OBP_V0:
promops.po_stdout = *obpvec->pv_stdout;
promops.po_putchar = obpvec->pv_putchar;
promops.po_open = obpvec->pv_v0devops.v0_open;
promops.po_close = (void *)obpvec->pv_v0devops.v0_close;
promops.po_bootcookie = *obpvec->pv_v0bootargs; /* deref 1 lvl */
promops.po_bootpath = obp_v0_getbootpath;
break;
case PROM_OBP_V3:
case PROM_OBP_V2:
/* Deref stdio handles one level */
promops.po_stdout = *obpvec->pv_v2bootargs.v2_fd1;
promops.po_putchar = obp_v2_putchar;
promops.po_open = obpvec->pv_v2devops.v2_open;
promops.po_close = (void *)obpvec->pv_v2devops.v2_close;
promops.po_read = obpvec->pv_v2devops.v2_read;
promops.po_write = obpvec->pv_v2devops.v2_write;
promops.po_seek = obp_v2_seek;
promops.po_bootcookie = &obpvec->pv_v2bootargs;
promops.po_bootpath = obp_v2_getbootpath;
break;
}
}
/*
* Initialize our PROM operations vector.
*/
void
prom_init()
{
if (CPU_ISSUN4) {
prom_init_oldmon();
romp = PROM_LOADADDR; /* Used in main() */
} else if (obpvec->pv_magic == OBP_MAGIC) {
prom_init_obp();
} else {
/* No Openfirmware support */
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dvma.c,v 1.2 1998/10/12 21:17:28 pk Exp $ */
/* $NetBSD: dvma.c,v 1.3 1999/02/15 18:59:36 pk Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
* All rights reserved.
@ -42,6 +42,7 @@
#include <machine/pte.h>
#include <machine/ctlreg.h>
#include <lib/libsa/stand.h>
#include <sparc/stand/common/promdev.h>
#define DVMA_BASE 0xFFF00000
@ -50,16 +51,25 @@
#define SA_MIN_VA (RELOC - 0x40000) /* XXX - magic constant */
#define SA_MAX_VA (SA_MIN_VA + DVMA_MAPLEN)
#if 0
#define getsegmap(va) (CPU_ISSUN4C \
? lduba(va, ASI_SEGMAP) \
: (lduha(va, ASI_SEGMAP)))
#define setsegmap(va, pmeg) (CPU_ISSUN4C \
? stba(va, ASI_SEGMAP, pmeg) \
: stha(va, ASI_SEGMAP, pmeg))
#else
/*
* This module is only used on sun4, so:
*/
#define getsegmap(va) (lduha(va, ASI_SEGMAP))
#define setsegmap(va, pmeg) do stha(va, ASI_SEGMAP, pmeg); while(0)
#endif
void
dvma_init()
{
register int segva, dmava;
int segva, dmava;
dmava = DVMA_BASE;
for (segva = SA_MIN_VA; segva < SA_MAX_VA; segva += NBPSG) {
@ -72,9 +82,11 @@ dvma_init()
* Convert a local address to a DVMA address.
*/
char *
dvma_mapin(char *addr, size_t len)
dvma_mapin(addr, len)
char *addr;
size_t len;
{
register int va = (int)addr;
int va = (int)addr;
/* Make sure the address is in the DVMA map. */
if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
@ -89,7 +101,9 @@ dvma_mapin(char *addr, size_t len)
* Convert a DVMA address to a local address.
*/
char *
dvma_mapout(char *addr, size_t len)
dvma_mapout(addr, len)
char *addr;
size_t len;
{
int va = (int)addr;
@ -102,26 +116,26 @@ dvma_mapout(char *addr, size_t len)
return ((char *)va);
}
extern char *alloc __P((int));
char *
dvma_alloc(int len)
dvma_alloc(len)
int len;
{
char *mem;
mem = alloc(len);
if (!mem)
if (mem == NULL)
return (mem);
return (dvma_mapin(mem, len));
}
extern void free(void *ptr, int len);
void
dvma_free(char *dvma, int len)
dvma_free(dvma, len)
char *dvma;
int len;
{
char *mem;
mem = dvma_mapout(dvma, len);
if (mem)
if (mem != NULL)
free(mem, len);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.2 1997/07/22 17:41:07 drochner Exp $ */
/* $NetBSD: net.c,v 1.3 1999/02/15 18:59:36 pk Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
@ -58,6 +58,9 @@
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>
#include <lib/libsa/bootparam.h>
#include <lib/libsa/nfs.h>
#include <sparc/stand/common/promdev.h>
char rootpath[FNAME_SIZE];
@ -94,9 +97,13 @@ net_close(pd)
struct promdata *pd;
{
/* On last close, do netif close, etc. */
if (open_count > 0)
if (--open_count == 0)
netif_close(netdev_sock);
if (open_count <= 0)
return (0);
if (--open_count == 0)
return (netif_close(netdev_sock));
return (0);
}
int
@ -119,7 +126,7 @@ net_mountroot()
/* Get our IP address. (rarp.c) */
if (rarp_getipaddress(netdev_sock) == -1)
return errno;
return (errno);
printf("boot: client IP address: %s\n", inet_ntoa(myip));
@ -154,5 +161,6 @@ net_mountroot()
/* Get the NFS file handle (mount). */
if (nfs_mount(netdev_sock, rootip, rootpath) != 0)
return (errno);
return 0;
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netif_sun.c,v 1.2 1997/07/22 17:41:08 drochner Exp $ */
/* $NetBSD: netif_sun.c,v 1.3 1999/02/15 18:59:36 pk Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
@ -77,7 +77,6 @@ netif_open(machdep_hint)
{
struct promdata *pd = machdep_hint;
struct iodesc *io;
int fd, error;
/* find a free socket */
io = sockets;
@ -179,7 +178,7 @@ netif_get(desc, pkt, maxlen, timo)
time_t timo;
{
struct promdata *pd;
int tick0, tmo_ticks;
int tick0;
ssize_t len;
pd = (struct promdata *)desc->io_netif->nif_devdata;
@ -190,12 +189,11 @@ netif_get(desc, pkt, maxlen, timo)
pkt, maxlen, timo);
#endif
tmo_ticks = timo * hz;
tick0 = getticks();
tick0 = getsecs();
do {
len = (*pd->recv)(pd, pkt, maxlen);
} while ((len == 0) && ((getticks() - tick0) < tmo_ticks));
} while ((len == 0) && ((getsecs() - tick0) < timo));
#ifdef NETIF_DEBUG
if (netif_debug)

View File

@ -1,4 +1,4 @@
/* $NetBSD: promdev.c,v 1.6 1998/10/12 21:17:28 pk Exp $ */
/* $NetBSD: promdev.c,v 1.7 1999/02/15 18:59:36 pk Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
@ -39,6 +39,7 @@
#include <sys/reboot.h>
#include <machine/idprom.h>
#include <machine/oldmon.h>
#include <machine/promlib.h>
#include <machine/ctlreg.h>
#include <sparc/sparc/asm.h>
#include <machine/pte.h>
@ -47,124 +48,67 @@
#include <sparc/stand/common/promdev.h>
/* OBP V0-3 PROM vector */
#define obpvec ((struct promvec *)romp)
int obp_close __P((struct open_file *));
int obp_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
ssize_t obp_xmit __P((struct promdata *, void *, size_t));
ssize_t obp_recv __P((struct promdata *, void *, size_t));
int prom0_close __P((struct open_file *));
int prom0_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
void prom0_iclose __P((struct saioreq *));
int prom0_iopen __P((struct promdata *));
ssize_t prom0_xmit __P((struct promdata *, void *, size_t));
ssize_t prom0_recv __P((struct promdata *, void *, size_t));
int obp_v0_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
ssize_t obp_v0_xmit __P((struct promdata *, void *, size_t));
ssize_t obp_v0_recv __P((struct promdata *, void *, size_t));
int obp_v2_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
ssize_t obp_v2_xmit __P((struct promdata *, void *, size_t));
ssize_t obp_v2_recv __P((struct promdata *, void *, size_t));
int oldmon_close __P((struct open_file *));
int oldmon_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
void oldmon_iclose __P((struct saioreq *));
int oldmon_iopen __P((struct promdata *));
ssize_t oldmon_xmit __P((struct promdata *, void *, size_t));
ssize_t oldmon_recv __P((struct promdata *, void *, size_t));
static char *prom_mapin __P((u_long, int, int));
int getdevtype __P((int, char *));
int getpropval __P((int, char *, void *, int));
char *getpropstring __P((int, char *));
static void prom0_fake __P((void));
static char *oldmon_mapin __P((u_long, int, int));
#ifndef BOOTXX
static char *mygetpropstring __P((int, char *));
static int getdevtype __P((int, char *));
#endif
extern struct filesystem file_system_nfs[];
extern struct filesystem file_system_ufs[];
int prom_open __P((struct open_file *f, ...)) { return 0; }
int prom_ioctl __P((struct open_file *f, u_long c, void *d)) { return EIO; }
struct devsw devsw[] = {
{ "prom0", prom0_strategy, prom_open, prom0_close, prom_ioctl },
{ "prom", obp_strategy, prom_open, obp_close, prom_ioctl }
};
#define null_devopen (void *)sparc_noop
#define null_devioctl (void *)sparc_noop
#if 0
struct devsw devsw[];
int ndevs = (sizeof(devsw)/sizeof(devsw[0]));
#endif
struct devsw oldmon_devsw =
{ "oldmon", oldmon_strategy, null_devopen, oldmon_close, null_devioctl };
struct devsw obp_v0_devsw =
{ "obp v0", obp_v0_strategy, null_devopen, obp_close, null_devioctl };
struct devsw obp_v2_devsw =
{ "obp v2", obp_v2_strategy, null_devopen, obp_close, null_devioctl };
char *prom_bootdevice;
char *prom_bootfile;
int prom_boothow;
struct promvec *promvec;
static int saveecho;
void
prom_init()
putchar(c)
int c;
{
static char storage[1024];
char *ap, *cp, *dp;
if (c == '\n')
prom_putchar('\r');
prom_putchar(c);
}
if (cputyp == CPU_SUN4)
prom0_fake();
if (promvec->pv_romvec_vers >= 2) {
char *ep = storage + sizeof(storage) - 1;
prom_bootdevice = *promvec->pv_v2bootargs.v2_bootpath;
#ifndef BOOTXX
cp = *promvec->pv_v2bootargs.v2_bootargs;
dp = prom_bootfile = storage;
/* Skip whitespace */
while (*cp != 0 && (*cp == ' ' || *cp == '\t'))
cp++;
/* Check for options */
if (cp[0] == '-' &&
(cp[1] == 'a' || cp[1] == 's' || cp[1] == 'd'))
cp++;
else {
/* Copy kernel name */
while (*cp != 0 && *cp != ' ' && *cp != '\t') {
if (dp >= ep) {
printf("v2_bootargs too long\n");
_rtt();
}
*dp++ = *cp++;
}
*dp = '\0';
/* Skip whitespace */
while (*cp != 0 && (*cp == ' ' || *cp == '\t'))
cp++;
}
ap = cp;
#endif
} else {
dp = prom_bootdevice = storage;
cp = (*promvec->pv_v0bootargs)->ba_argv[0];
while (*cp) {
*dp++ = *cp;
if (*cp++ == ')')
break;
}
*dp = '\0';
#ifndef BOOTXX
prom_bootfile = (*promvec->pv_v0bootargs)->ba_kernel;
ap = (*promvec->pv_v0bootargs)->ba_argv[1];
#endif
}
#ifndef BOOTXX
if (ap == NULL || *ap++ != '-')
return;
while (*ap && *ap != ' ' && *ap != '\t' && *ap != '\n') {
switch (*ap) {
case 'a':
prom_boothow |= RB_ASKNAME;
break;
case 's':
prom_boothow |= RB_SINGLE;
break;
case 'd':
prom_boothow |= RB_KDB;
debug = 1;
break;
}
ap++;
}
#endif
void
_rtt()
{
prom_halt();
}
int
@ -177,25 +121,50 @@ devopen(f, fname, file)
struct promdata *pd;
pd = (struct promdata *)alloc(sizeof *pd);
f->f_devdata = (void *)pd;
if (cputyp == CPU_SUN4) {
error = prom0_iopen(pd);
switch (prom_version()) {
case PROM_OLDMON:
error = oldmon_iopen(pd);
#ifndef BOOTXX
pd->xmit = prom0_xmit;
pd->recv = prom0_recv;
pd->xmit = oldmon_xmit;
pd->recv = oldmon_recv;
#endif
} else {
fd = (promvec->pv_romvec_vers >= 2)
? (*promvec->pv_v2devops.v2_open)(prom_bootdevice)
: (*promvec->pv_v0devops.v0_open)(prom_bootdevice);
f->f_dev = &oldmon_devsw;
saveecho = *romVectorPtr->echo;
*romVectorPtr->echo = 0;
break;
case PROM_OBP_V0:
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
if (prom_bootdevice == NULL) {
error = ENXIO;
break;
}
fd = prom_open(prom_bootdevice);
if (fd == 0) {
error = ENXIO;
} else {
pd->fd = fd;
break;
}
pd->fd = fd;
switch (prom_version()) {
case PROM_OBP_V0:
#ifndef BOOTXX
pd->xmit = obp_xmit;
pd->recv = obp_recv;
pd->xmit = obp_v0_xmit;
pd->recv = obp_v0_recv;
#endif
f->f_dev = &obp_v0_devsw;
break;
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
#ifndef BOOTXX
pd->xmit = obp_v2_xmit;
pd->recv = obp_v2_recv;
#endif
f->f_dev = &obp_v2_devsw;
}
}
@ -215,21 +184,60 @@ devopen(f, fname, file)
if (pd->devtype == DT_NET) {
bcopy(file_system_nfs, file_system, sizeof(struct fs_ops));
if ((error = net_open(pd)) != 0) {
printf("Can't open network device `%s'\n",
printf("Can't open NFS network connection on `%s'\n",
prom_bootdevice);
return error;
return (error);
}
} else
bcopy(file_system_ufs, file_system, sizeof(struct fs_ops));
#endif /* BOOTXX */
return (0);
}
f->f_dev = &devsw[cputyp == CPU_SUN4 ? 0 : 1];
f->f_devdata = (void *)pd;
return 0;
int
obp_v0_strategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
size_t size;
void *buf;
size_t *rsize;
{
int n, error = 0;
struct promdata *pd = (struct promdata *)devdata;
int fd = pd->fd;
#ifdef DEBUG_PROM
printf("promstrategy: size=%d dblk=%d\n", size, dblk);
#endif
#define prom_bread(fd, nblk, dblk, buf) \
(*obpvec->pv_v0devops.v0_rbdev)(fd, nblk, dblk, buf)
#define prom_bwrite(fd, nblk, dblk, buf) \
(*obpvec->pv_v0devops.v0_wbdev)(fd, nblk, dblk, buf)
#ifndef BOOTXX /* We know it's a block device, so save some space */
if (pd->devtype != DT_BLOCK) {
printf("promstrategy: non-block device not supported\n");
error = EINVAL;
}
#endif
n = (flag == F_READ)
? prom_bread(fd, btodb(size), dblk, buf)
: prom_bwrite(fd, btodb(size), dblk, buf);
*rsize = dbtob(n);
#ifdef DEBUG_PROM
printf("rsize = %x\n", *rsize);
#endif
return (error);
}
int
obp_strategy(devdata, flag, dblk, size, buf, rsize)
obp_v2_strategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
@ -245,33 +253,26 @@ obp_strategy(devdata, flag, dblk, size, buf, rsize)
printf("promstrategy: size=%d dblk=%d\n", size, dblk);
#endif
if (promvec->pv_romvec_vers >= 2) {
if (pd->devtype == DT_BLOCK)
(*promvec->pv_v2devops.v2_seek)(fd, 0, dbtob(dblk));
#ifndef BOOTXX /* We know it's a block device, so save some space */
if (pd->devtype == DT_BLOCK)
#endif
prom_seek(fd, dbtob(dblk));
*rsize = (*((flag == F_READ)
? (u_int (*)())promvec->pv_v2devops.v2_read
: (u_int (*)())promvec->pv_v2devops.v2_write
))(fd, buf, size);
} else {
int n = (*((flag == F_READ)
? (u_int (*)())promvec->pv_v0devops.v0_rbdev
: (u_int (*)())promvec->pv_v0devops.v0_wbdev
))(fd, btodb(size), dblk, buf);
*rsize = dbtob(n);
}
*rsize = (flag == F_READ)
? prom_read(fd, buf, size)
: prom_write(fd, buf, size);
#ifdef DEBUG_PROM
printf("rsize = %x\n", *rsize);
#endif
return error;
return (error);
}
/*
* On old-monitor machines, things work differently.
*/
int
prom0_strategy(devdata, flag, dblk, size, buf, rsize)
oldmon_strategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
@ -325,15 +326,12 @@ obp_close(f)
if (pd->devtype == DT_NET)
net_close(pd);
#endif
if (promvec->pv_romvec_vers >= 2)
(void)(*promvec->pv_v2devops.v2_close)(fd);
else
(void)(*promvec->pv_v0devops.v0_close)(fd);
prom_close(fd);
return 0;
}
int
prom0_close(f)
oldmon_close(f)
struct open_file *f;
{
struct promdata *pd = f->f_devdata;
@ -342,40 +340,59 @@ prom0_close(f)
if (pd->devtype == DT_NET)
net_close(pd);
#endif
prom0_iclose(pd->si);
oldmon_iclose(pd->si);
pd->si = NULL;
*romp->echo = saveecho; /* Hmm, probably must go somewhere else */
*romVectorPtr->echo = saveecho; /* Hmm, probably must go somewhere else */
return 0;
}
#ifndef BOOTXX
ssize_t
obp_xmit(pd, buf, len)
obp_v0_xmit(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
{
return (promvec->pv_romvec_vers >= 2
? (*promvec->pv_v2devops.v2_write)(pd->fd, buf, len)
: (*promvec->pv_v0devops.v0_wnet)(pd->fd, len, buf));
return ((*obpvec->pv_v0devops.v0_wnet)(pd->fd, len, buf));
}
ssize_t
obp_recv(pd, buf, len)
obp_v2_xmit(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
{
int n;
n = (promvec->pv_romvec_vers >= 2
? (*promvec->pv_v2devops.v2_read)(pd->fd, buf, len)
: (*promvec->pv_v0devops.v0_rnet)(pd->fd, len, buf));
return (prom_write(pd->fd, buf, len));
}
ssize_t
obp_v0_recv(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
{
return ((*obpvec->pv_v0devops.v0_rnet)(pd->fd, len, buf));
}
ssize_t
obp_v2_recv(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
{
int n;
n = prom_read(pd->fd, buf, len);
/* OBP V2 & V3 may return -2 */
return (n == -2 ? 0 : n);
}
ssize_t
prom0_xmit(pd, buf, len)
oldmon_xmit(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
@ -399,7 +416,7 @@ prom0_xmit(pd, buf, len)
}
ssize_t
prom0_recv(pd, buf, len)
oldmon_recv(pd, buf, len)
struct promdata *pd;
void *buf;
size_t len;
@ -421,103 +438,32 @@ prom0_recv(pd, buf, len)
int
getchar()
{
char c;
register int n;
if (promvec->pv_romvec_vers > 2)
while ((n = (*promvec->pv_v2devops.v2_read)
(*promvec->pv_v2bootargs.v2_fd0, (caddr_t)&c, 1)) != 1);
else
c = (*promvec->pv_getchar)();
if (c == '\r')
c = '\n';
return (c);
return (prom_getchar());
}
int
peekchar()
{
char c;
register int n;
if (promvec->pv_romvec_vers > 2) {
n = (*promvec->pv_v2devops.v2_read)
(*promvec->pv_v2bootargs.v2_fd0, (caddr_t)&c, 1);
if (n < 0)
return -1;
} else
c = (*promvec->pv_nbgetchar)();
if (c == '\r')
c = '\n';
return (c);
}
#endif
static void
pv_putchar(c)
int c;
{
char c0 = c;
if (promvec->pv_romvec_vers > 2)
(*promvec->pv_v2devops.v2_write)
(*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
else
(*promvec->pv_putchar)(c);
}
void
putchar(c)
int c;
{
if (c == '\n')
pv_putchar('\r');
pv_putchar(c);
}
void
_rtt()
{
promvec->pv_halt();
}
#ifndef BOOTXX
int hz = 1000;
time_t
getsecs()
{
register int ticks = getticks();
return ((time_t)(ticks / hz));
(void)prom_peekchar();
return (prom_ticks() / 1000);
}
int
getticks()
{
if (promvec->pv_romvec_vers >= 2) {
char c;
(void)(*promvec->pv_v2devops.v2_read)
(*promvec->pv_v2bootargs.v2_fd0, (caddr_t)&c, 0);
} else {
(void)(*promvec->pv_nbgetchar)();
}
return *(promvec->pv_ticks);
}
void
prom_getether(fd, ea)
int fd;
u_char *ea;
{
if (cputyp == CPU_SUN4) {
static struct idprom sun4_idprom;
u_char *src, *dst;
int len, x;
static struct idprom idprom;
char buf[64];
u_char *src, *dst;
int len, x;
if (sun4_idprom.id_format == 0) {
dst = (char*)&sun4_idprom;
switch (prom_version()) {
case PROM_OLDMON:
if (idprom.id_format == 0) {
dst = (char*)&idprom;
src = (char*)AC_IDPROM;
len = sizeof(struct idprom);
do {
@ -525,13 +471,16 @@ prom_getether(fd, ea)
*dst++ = x;
} while (--len > 0);
}
bcopy(sun4_idprom.id_ether, ea, 6);
} else if (promvec->pv_romvec_vers <= 2) {
(void)(*promvec->pv_enaddr)(fd, (char *)ea);
} else {
char buf[64];
sprintf(buf, "%x mac-address drop swap 6 cmove", ea);
promvec->pv_fortheval.v2_eval(buf);
bcopy(idprom.id_ether, ea, 6);
break;
case PROM_OBP_V0:
case PROM_OBP_V2:
(void)(*obpvec->pv_enaddr)(fd, (char *)ea);
break;
case PROM_OBP_V3:
sprintf(buf, "%lx mac-address drop swap 6 cmove", (u_long)ea);
prom_interpret(buf);
break;
}
}
@ -558,48 +507,33 @@ getdevtype(fd, name)
int fd;
char *name;
{
if (promvec->pv_romvec_vers >= 2) {
int node = (*promvec->pv_v2devops.v2_fd_phandle)(fd);
char *cp = getpropstring(node, "device_type");
if (strcmp(cp, "block") == 0)
return DT_BLOCK;
else if (strcmp(cp, "network") == 0)
return DT_NET;
else if (strcmp(cp, "byte") == 0)
return DT_BYTE;
} else {
struct dtab *dp;
struct dtab *dp;
int node;
char *cp;
switch (prom_version()) {
case PROM_OLDMON:
case PROM_OBP_V0:
for (dp = dtab; dp->name; dp++) {
if (name[0] == dp->name[0] &&
name[1] == dp->name[1])
return dp->type;
return (dp->type);
}
}
return 0;
}
break;
/*
* OpenPROM nodes & property routines (from <sparc/autoconf.c>).
*/
int
getpropval(node, name, buf, bufsiz)
int node;
char *name;
void *buf;
register int bufsiz;
{
register struct nodeops *no;
register int len;
no = promvec->pv_nodeops;
len = no->no_proplen(node, name);
if (len > bufsiz) {
printf("node %x property %s length %d > %d\n",
node, name, len, bufsiz);
return (0);
case PROM_OBP_V2:
case PROM_OBP_V3:
node = (*obpvec->pv_v2devops.v2_fd_phandle)(fd);
cp = mygetpropstring(node, "device_type");
if (strcmp(cp, "block") == 0)
return (DT_BLOCK);
else if (strcmp(cp, "network") == 0)
return (DT_NET);
else if (strcmp(cp, "byte") == 0)
return (DT_BYTE);
break;
}
no->no_getprop(node, name, buf);
return (len);
return (0);
}
/*
@ -608,18 +542,21 @@ getpropval(node, name, buf, bufsiz)
* subsequent calls.
*/
char *
getpropstring(node, name)
mygetpropstring(node, name)
int node;
char *name;
{
register int len;
static char stringbuf[64];
int len;
static char buf[64];
len = getpropval(node, name, (void *)stringbuf, sizeof stringbuf - 1);
if (len == -1)
len = prom_proplen(node, name);
if (len > 0)
_prom_getprop(node, name, buf, len);
else
len = 0;
stringbuf[len] = '\0'; /* usually unnecessary */
return (stringbuf);
buf[len] = '\0'; /* usually unnecessary */
return (buf);
}
#endif /* BOOTXX */
@ -631,7 +568,7 @@ struct saioreq prom_si;
static int promdev_inuse;
int
prom0_iopen(pd)
oldmon_iopen(pd)
struct promdata *pd;
{
struct om_bootparam *bp;
@ -641,9 +578,9 @@ prom0_iopen(pd)
int error;
if (promdev_inuse)
return(EMFILE);
return (EMFILE);
bp = *romp->bootParam;
bp = *romVectorPtr->bootParam;
ops = bp->bootTable;
dip = ops->b_devinfo;
@ -661,19 +598,17 @@ prom0_iopen(pd)
dvma_init();
si = &prom_si;
bzero((caddr_t)si, sizeof(*si));
memset(si, 0, sizeof(*si));
si->si_boottab = ops;
si->si_ctlr = bp->ctlrNum;
si->si_unit = bp->unitNum;
si->si_boff = bp->partNum;
if (si->si_ctlr > dip->d_stdcount) {
printf("Invalid controller number\n");
return(ENXIO);
}
if (si->si_ctlr > dip->d_stdcount)
return (ECTLR);
if (dip->d_devbytes) {
si->si_devaddr = prom_mapin(dip->d_stdaddrs[si->si_ctlr],
si->si_devaddr = oldmon_mapin(dip->d_stdaddrs[si->si_ctlr],
dip->d_devbytes, dip->d_devtype);
#ifdef DEBUG_PROM
printf("prom_iopen: devaddr=0x%x pte=0x%x\n",
@ -699,8 +634,7 @@ prom0_iopen(pd)
/* OK, call the PROM device open routine. */
error = (*ops->b_open)(si);
if (error != 0) {
printf("prom_iopen: \"%s\" error=%d\n",
ops->b_desc, error);
printf("prom_iopen: \"%s\" error=%d\n", ops->b_desc, error);
return (ENXIO);
}
#ifdef DEBUG_PROM
@ -713,7 +647,7 @@ prom0_iopen(pd)
}
void
prom0_iclose(si)
oldmon_iclose(si)
struct saioreq *si;
{
struct om_boottable *ops;
@ -739,44 +673,45 @@ static struct mapinfo {
int maptype;
int pgtype;
int base;
} prom_mapinfo[] = {
{ MAP_MAINMEM, PG_OBMEM, 0 },
{ MAP_OBIO, PG_OBIO, 0 },
{ MAP_MBMEM, PG_VME16, 0xFF000000 },
{ MAP_MBIO, PG_VME16, 0xFFFF0000 },
{ MAP_VME16A16D, PG_VME16, 0xFFFF0000 },
{ MAP_VME16A32D, PG_VME32, 0xFFFF0000 },
{ MAP_VME24A16D, PG_VME16, 0xFF000000 },
{ MAP_VME24A32D, PG_VME32, 0xFF000000 },
{ MAP_VME32A16D, PG_VME16, 0 },
{ MAP_VME32A32D, PG_VME32, 0 },
} oldmon_mapinfo[] = {
#define PG_COMMON (PG_V|PG_W|PG_S|PG_NC)
{ MAP_MAINMEM, PG_OBMEM | PG_COMMON, 0 },
{ MAP_OBIO, PG_OBIO | PG_COMMON, 0 },
{ MAP_MBMEM, PG_VME16 | PG_COMMON, 0xFF000000 },
{ MAP_MBIO, PG_VME16 | PG_COMMON, 0xFFFF0000 },
{ MAP_VME16A16D, PG_VME16 | PG_COMMON, 0xFFFF0000 },
{ MAP_VME16A32D, PG_VME32 | PG_COMMON, 0xFFFF0000 },
{ MAP_VME24A16D, PG_VME16 | PG_COMMON, 0xFF000000 },
{ MAP_VME24A32D, PG_VME32 | PG_COMMON, 0xFF000000 },
{ MAP_VME32A16D, PG_VME16 | PG_COMMON, 0 },
{ MAP_VME32A32D, PG_VME32 | PG_COMMON, 0 },
};
static prom_mapinfo_cnt = sizeof(prom_mapinfo) / sizeof(prom_mapinfo[0]);
static int oldmon_mapinfo_cnt =
sizeof(oldmon_mapinfo) / sizeof(oldmon_mapinfo[0]);
/* The virtual address we will use for PROM device mappings. */
static u_long prom_devmap = MONSHORTSEG;
static char *
prom_mapin(physaddr, length, maptype)
oldmon_mapin(physaddr, length, maptype)
u_long physaddr;
int length, maptype;
{
int i, pa, pte, va;
if (length > (4*NBPG))
panic("prom_mapin: length=%d\n", length);
panic("oldmon_mapin: length=%d\n", length);
for (i = 0; i < prom_mapinfo_cnt; i++)
if (prom_mapinfo[i].maptype == maptype)
for (i = 0; i < oldmon_mapinfo_cnt; i++)
if (oldmon_mapinfo[i].maptype == maptype)
goto found;
panic("prom_mapin: invalid maptype %d\n", maptype);
found:
panic("oldmon_mapin: invalid maptype %d\n", maptype);
pte = prom_mapinfo[i].pgtype;
pte |= (PG_V|PG_W|PG_S|PG_NC);
pa = prom_mapinfo[i].base;
found:
pte = oldmon_mapinfo[i].pgtype;
pa = oldmon_mapinfo[i].base;
pa += physaddr;
pte |= ((pa >> PGSHIFT) & PG_PFNUM);
pte |= ((pa >> SUN4_PGSHIFT) & PG_PFNUM);
va = prom_devmap;
do {
@ -787,27 +722,3 @@ found:
} while (length > 0);
return ((char*)(prom_devmap | (pa & PGOFSET)));
}
void
prom0_fake()
{
static struct promvec promvecstore;
promvec = &promvecstore;
promvec->pv_stdin = romp->inSource;
promvec->pv_stdout = romp->outSink;
promvec->pv_putchar = romp->putChar;
promvec->pv_putstr = romp->fbWriteStr;
promvec->pv_nbgetchar = romp->mayGet;
promvec->pv_getchar = romp->getChar;
promvec->pv_romvec_vers = 0; /* eek! */
promvec->pv_reboot = romp->reBoot;
promvec->pv_abort = romp->abortEntry;
promvec->pv_setctxt = romp->setcxsegmap;
promvec->pv_v0bootargs = (struct v0bootargs **)(romp->bootParam);
promvec->pv_halt = romp->exitToMon;
promvec->pv_ticks = romp->nmiClock;
saveecho = *romp->echo;
*romp->echo = 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: promdev.h,v 1.4 1998/10/12 21:17:28 pk Exp $ */
/* $NetBSD: promdev.h,v 1.5 1999/02/15 18:59:36 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -50,22 +50,27 @@ struct promdata {
int (*recv) __P((struct promdata *, void *, size_t));
};
#define LOADADDR ((caddr_t)0x4000)
#define DDB_MAGIC0 ( ('D'<<24) | ('D'<<16) | ('B'<<8) | ('0') )
#define DDB_MAGIC1 ( ('D'<<24) | ('D'<<16) | ('B'<<8) | ('1') )
extern struct promvec *promvec;
extern time_t getsecs __P((void));
extern void prom_getether __P((int, u_char *));
extern char *prom_bootdevice;
extern char *prom_bootfile;
extern int prom_boothow;
extern int hz;
extern int cputyp, nbpg, pgofset, pgshift;
extern int debug;
extern void prom_init __P((void));
/* Note: dvma_*() routines are for "oldmon" machines only */
extern void dvma_init __P((void));
extern char *dvma_mapin __P((char *, size_t));
extern char *dvma_mapout __P((char *, size_t));
extern char *dvma_alloc __P((int));
extern void dvma_free __P((char *, int));
/* In net.c: */
extern int net_open __P((struct promdata *));
extern int net_close __P((struct promdata *));
extern int net_mountroot __P((void));
/* In str0.S: */
extern void sparc_noop __P((void));
extern void *romp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: srt0.S,v 1.1 1997/06/01 03:39:40 mrg Exp $ */
/* $NetBSD: srt0.S,v 1.2 1999/02/15 18:59:36 pk Exp $ */
/*
* Copyright (c) 1994 Paul Kranenburg
@ -30,6 +30,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _LOCORE /* XXX - fix Makefile */
#include <machine/param.h>
#include <machine/psl.h>
@ -37,16 +39,12 @@
.file "str0.s"
.data
.global _cputyp, _nbpg, _pgofset, _pgshift
_cputyp:
.word 1
_nbpg:
.word 1
_pgofset:
.word 1
_pgshift:
.word 1
.comm _romp, 4
.comm _opf_romp, 4
.comm _cputyp, 4
.comm _nbpg, 4
.comm _pgofset, 4
.comm _pgshift, 4
.text
.globl start
@ -99,8 +97,17 @@ start:
*/
set _edata, %o0 ! bzero(edata, end - edata)
set _end, %o1
call _bzero
sub %o1, %o0, %o1
/* note: bzero() expanded inline for compactness */
subcc %o1, %o0, %o1
bz 2f ! in case there is no BSS
srl %o1, 2, %o1 ! assume _edata & _end are aligned
1:
st %g0, [%o0] ! while (n--)
subcc %o1, 1, %o1 ! *p = 0; etc..
bnz 1b
add %o0, 4, %o0
2:
/*
* Enable interrupts, but only above level 11. This enables "L1-A",
@ -117,24 +124,28 @@ start:
sethi %hi(_cputyp), %o0
set 0x4000, %g7
cmp %i0, %g7
beq 5f
beq is_sun4
nop
mov CPU_SUN4C, %g4
mov SUN4CM_PGSHIFT, %g5
/*
* Save address of PROM vector (passed in %i0).
*/
sethi %hi(_promvec), %o1
st %i0, [%o1 + %lo(_promvec)]
sethi %hi(_romp), %o1
st %i0, [%o1 + %lo(_romp)]
mov CPU_SUN4C, %g4
mov SUN4CM_PGSHIFT, %g5
b,a 6f
/* Also save %i3, which is the Openfirmware entry, if any */
sethi %hi(_opf_romp), %o1
st %i3, [%o1 + %lo(_opf_romp)]
b,a is_sun4cm
5:
is_sun4:
mov CPU_SUN4, %g4
mov SUN4_PGSHIFT, %g5
6:
is_sun4cm:
st %g4, [%o0 + %lo(_cputyp)]
sethi %hi(_pgshift), %o0 ! pgshift = log2(nbpg)
st %g5, [%o0 + %lo(_pgshift)]
@ -154,6 +165,14 @@ start:
ret
restore
/*
* NO-OP place holder function.
*/
.globl _sparc_noop
_sparc_noop:
retl
nop
#ifdef TIGHT