diff options
author | Dale S. Rahn <rahnds@cvs.openbsd.org> | 1998-05-29 04:16:11 +0000 |
---|---|---|
committer | Dale S. Rahn <rahnds@cvs.openbsd.org> | 1998-05-29 04:16:11 +0000 |
commit | d533ff01b0e7fecf6829b87c5eb45fac1a24daa8 (patch) | |
tree | baa5cc17d5d8abebf45492724ab6c004d9ba5e8c /sys/arch/powerpc | |
parent | 2de1e4190b510b46917c96c19d7ebd01a07b41b8 (diff) |
Major changes here and there, tweaks elsewhere.
Support for Openfirmware drivers was reintroduced so that more systems
were supported. This should work with the real driver configurations
as well.
Bootloader files were deleted/replaced with the newer versions in the
subdirectory. Some effort has been made to be closer to support booting
(at least the bootloader) on the Mac.
Config files that end with OFW are the openfirmware versions of the kernels
without have native drivers.
Native driver support has not been changed, presumably it still works.
I couldn't test that.
Diffstat (limited to 'sys/arch/powerpc')
41 files changed, 1056 insertions, 2219 deletions
diff --git a/sys/arch/powerpc/README b/sys/arch/powerpc/README index e4e961b11a6..59bd1151623 100644 --- a/sys/arch/powerpc/README +++ b/sys/arch/powerpc/README @@ -13,6 +13,10 @@ as little possible. The current kernel supports only V.I Power.4e PowerPC 604 based VME board. More will come in the future. +Support for Openfirmware drivers was reintroduced, in a manner which +should be compatible with "real" drivers. It is yet to be seen if +a kernel can have both OF drivers and real drivers. But at least +both versions can be built. Other notes: libexec/ftpd (ftpd.o) does not compile with optimization. @@ -21,6 +25,9 @@ Other notes: if compiled without -O. (worked around with a makefile change) + This probably has changed with the introduction of gcc 2.8.X.X + but not completely verified (yet). + TODO: ptrace support (that works) fp (setround, getround, getmask, setmask, setsticky, getsticky) diff --git a/sys/arch/powerpc/compile/.cvsignore b/sys/arch/powerpc/compile/.cvsignore index 3f18df26d27..57b753988bb 100644 --- a/sys/arch/powerpc/compile/.cvsignore +++ b/sys/arch/powerpc/compile/.cvsignore @@ -4,3 +4,5 @@ NFS TST DDB MINI +RAMDISKOFW +DDBOFW diff --git a/sys/arch/powerpc/conf/DDB b/sys/arch/powerpc/conf/DDB index 193a8e5c4b9..0df8e1d69a0 100644 --- a/sys/arch/powerpc/conf/DDB +++ b/sys/arch/powerpc/conf/DDB @@ -13,9 +13,11 @@ option NATIVE_ELF # various hacks due to bugs in Openfirmware implementation option FIREPOWERBUGS +# specific define for VI boards +options power4e + #option IPKDBUSERHACK #makeoptions DEBUG="-g" - options DDB options KTRACE options SYSCALL_DEBUG diff --git a/sys/arch/powerpc/conf/DDBOFW b/sys/arch/powerpc/conf/DDBOFW new file mode 100644 index 00000000000..71ccd22e51d --- /dev/null +++ b/sys/arch/powerpc/conf/DDBOFW @@ -0,0 +1,74 @@ +# +# First try for PPC GENERIC config file +# + +machine powerpc + +maxusers 32 + +# Standard system options (should go into std.powerpc?) +options SWAPPAGER, VNODEPAGER, DEVPAGER +options EXEC_ELF +options SYS_TYPE=OFWMACH + +# various hacks due to bugs in Openfirmware implementation +options FIREPOWERBUGS + +#options IPKDBUSERHACK +#makeoptions DEBUG="-g" + +options DDB +options KTRACE +options SYSCALL_DEBUG +#options TCP_COMPAT_42 +#options COMPAT_43 +#options COMPAT_09 +#options COMPAT_10 +#options COMPAT_12 + +options FFS +options MFS + +options NFSCLIENT +options NFSSERVER + +options CD9660 +options MSDOSFS +options FDESC +options FIFO +options KERNFS +options NULLFS +options PORTAL +options PROCFS +options UMAPFS +options UNION + +options INET +options NMBCLUSTERS=1024 + +#options MAXUSERS=20 +#options TARGET_ELF + +config bsd swap generic + +mainbus0 at root +cpu* at mainbus0 + +ofroot* at root + +ofbus* at openfirm? + +ofdisk* at openfirm? + +ofnet* at openfirm? +#ipkdbif0 at ofnet? + +ofcons* at openfirm? + +ofrtc* at openfirm? + +pseudo-device loop +pseudo-device pty 64 +pseudo-device random 1 +pseudo-device rd +pseudo-device vnd 2 diff --git a/sys/arch/powerpc/conf/GENERIC b/sys/arch/powerpc/conf/GENERIC index ad27de9c553..090356eba8d 100644 --- a/sys/arch/powerpc/conf/GENERIC +++ b/sys/arch/powerpc/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.6 1998/04/06 17:29:24 pefo Exp $ +# $OpenBSD: GENERIC,v 1.7 1998/05/29 04:15:26 rahnds Exp $ # # PPC GENERIC config file # @@ -7,6 +7,9 @@ machine powerpc maxusers 32 +# specific define for VI boards +options power4e + # Standard system options option SWAPPAGER # swap pager (anonymous and swap space) option VNODEPAGER # vnode pager (mapped files) diff --git a/sys/arch/powerpc/conf/Makefile.powerpc b/sys/arch/powerpc/conf/Makefile.powerpc index f1033d2882e..253e8814d87 100644 --- a/sys/arch/powerpc/conf/Makefile.powerpc +++ b/sys/arch/powerpc/conf/Makefile.powerpc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.powerpc,v 1.7 1998/04/06 17:29:25 pefo Exp $ +# $OpenBSD: Makefile.powerpc,v 1.8 1998/05/29 04:15:27 rahnds Exp $ # # Makefile for OpenBSD PowerPC # @@ -40,7 +40,7 @@ PPC= ../.. INCLUDES= -I. -I$S/arch -I$S -nostdinc -L${DESTDIR}/usr/include CPPFLAGS= ${INCLUDES} ${IDENT} -D_KERNEL \ - -Dpowerpc -Dpower4e + -Dpowerpc CWARNFLAGS= -Werror -Wreturn-type CFLAGS= ${DEBUG} ${CWARNFLAGS} -O2 -msoft-float AFLAGS= -D_LOCORE diff --git a/sys/arch/powerpc/conf/RAMDISK b/sys/arch/powerpc/conf/RAMDISK index 1d437f011ff..c34e76a7cec 100644 --- a/sys/arch/powerpc/conf/RAMDISK +++ b/sys/arch/powerpc/conf/RAMDISK @@ -13,6 +13,9 @@ option NATIVE_ELF option FIREPOWERBUGS +# specific define for VI boards +options power4e + options KTRACE options DEBUG diff --git a/sys/arch/powerpc/conf/RAMDISKOFW b/sys/arch/powerpc/conf/RAMDISKOFW new file mode 100644 index 00000000000..b6a5933ac28 --- /dev/null +++ b/sys/arch/powerpc/conf/RAMDISKOFW @@ -0,0 +1,82 @@ +# +# First try for PPC GENERIC config file +# + +machine powerpc + +maxusers 32 + +# Standard system options (should go into std.powerpc?) +options SWAPPAGER, VNODEPAGER, DEVPAGER +options EXEC_ELF +options SYS_TYPE=OFWMACH + +# various hacks due to bugs in Openfirmware implementation +options FIREPOWERBUGS + +#options IPKDBUSERHACK +#makeoptions DEBUG="-g" + +options DDB +options KTRACE +options SYSCALL_DEBUG +options TCP_COMPAT_42 +options COMPAT_43 +options COMPAT_09 +options COMPAT_10 +options COMPAT_12 + +options FFS +options MFS + +options NFSCLIENT +#options NFSSERVER + +options CD9660 +options MSDOSFS +options FDESC +options FIFO +options KERNFS +options NULLFS +#options PORTAL +options PROCFS +#options UMAPFS +#options UNION + +options INET +options NMBCLUSTERS=1024 + +#options MAXUSERS=20 +#options TARGET_ELF + +config bsd root on rd0a swap on rd0b + +mainbus0 at root +cpu* at mainbus0 + +ofroot* at root + +ofbus* at openfirm? + +ofdisk* at openfirm? + +ofnet* at openfirm? +#ipkdbif0 at ofnet? + +ofcons* at openfirm? + +ofrtc* at openfirm? + +pseudo-device loop +pseudo-device pty 64 +pseudo-device random 1 +pseudo-device rd +pseudo-device vnd 1 + + +# RAMDISK stuff +option MINIROOTSIZE=8192 +option RAMDISK_HOOKS + + + diff --git a/sys/arch/powerpc/conf/files.powerpc b/sys/arch/powerpc/conf/files.powerpc index 0ce47b4103c..32e9cf193d6 100644 --- a/sys/arch/powerpc/conf/files.powerpc +++ b/sys/arch/powerpc/conf/files.powerpc @@ -1,5 +1,5 @@ # -# V.I. powerpc-specific configuration info +# powerpc-specific configuration info # maxpartitions 16 @@ -61,19 +61,27 @@ major {rd = 17} device mpcpcibr {} : pcibus attach mpcpcibr at mainbus -file arch/powerpc/pci/mpcpcibus.c +file arch/powerpc/pci/mpcpcibus.c mpcpcibr device isabr {} : isabus attach isabr at mainbus file arch/powerpc/isa/isabus.c isabr include "../../../scsi/files.scsi" -major {sd = 0} +major {sd = 2} # hey this was 0 but at slot 2 in bdevsw XXX major {cd = 3} define pcmcia {} # XXX dummy decl... include "../../../dev/pci/files.pci" include "../../../dev/isa/files.isa" -major { wd = 4 } +major { wd = 5 } # Not even in bdevsw XXX include "../../../dev/isa/files.isapnp" file arch/arc/isa/isapnp_machdep.c isapnp + +# +# Openfirmware support +# + +include "../../../dev/ofw/files.ofw" +file arch/powerpc/powerpc/opendev.c ofcons | ofnet | ofdisk +major { ofdisk = 4 } diff --git a/sys/arch/powerpc/include/ansi.h b/sys/arch/powerpc/include/ansi.h index 51e8d03f272..07a240c928a 100644 --- a/sys/arch/powerpc/include/ansi.h +++ b/sys/arch/powerpc/include/ansi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ansi.h,v 1.5 1997/07/07 05:56:41 millert Exp $ */ +/* $OpenBSD: ansi.h,v 1.6 1998/05/29 04:15:31 rahnds Exp $ */ /* $NetBSD: ansi.h,v 1.2 1996/11/15 22:38:57 jtc Exp $ */ /*- @@ -53,8 +53,8 @@ #define _BSD_SIZE_T_ unsigned int /* sizeof() */ #define _BSD_SSIZE_T_ int /* byte count or error */ #define _BSD_TIME_T_ int /* time() */ -struct __gnuc_va_list__; -#define _BSD_VA_LIST_ struct __gnuc_va_list__ * /* va_list */ +struct __va_list_tag; +#define _BSD_VA_LIST_ struct __va_list_tag * /* va_list */ #define _BSD_CLOCKID_T_ int #define _BSD_TIMER_T_ int diff --git a/sys/arch/powerpc/include/autoconf.h b/sys/arch/powerpc/include/autoconf.h index 0dc3d55d0e3..d11e53617c2 100644 --- a/sys/arch/powerpc/include/autoconf.h +++ b/sys/arch/powerpc/include/autoconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.h,v 1.1 1997/10/13 10:53:41 pefo Exp $ */ +/* $OpenBSD: autoconf.h,v 1.2 1998/05/29 04:15:32 rahnds Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -41,6 +41,7 @@ /* * System types. */ +#define OFWMACH 0 /* Openfirmware drivers */ #define POWER4e 1 /* V.I Power.4e board */ extern int system_type; diff --git a/sys/arch/powerpc/include/va-ppc.h b/sys/arch/powerpc/include/va-ppc.h index a86ba278e20..4bf23184a6c 100644 --- a/sys/arch/powerpc/include/va-ppc.h +++ b/sys/arch/powerpc/include/va-ppc.h @@ -1,5 +1,6 @@ -/* GNU C varargs support for the PowerPC with V.4 calling */ +/* GNU C varargs support for the PowerPC with either the V.4 or Windows NT calling sequences */ +#ifndef _WIN32 /* System V.4 support */ /* Define __gnuc_va_list. */ @@ -15,7 +16,7 @@ /* Note that the names in this structure are in the user's namespace, but that the V.4 abi explicitly states that these names should be used. */ -typedef struct __gnuc_va_list__ { +typedef struct __va_list_tag { char gpr; /* index into the array of 8 GPRs stored in the register save area gpr=0 corresponds to r3, gpr=1 to r4, etc. */ @@ -76,8 +77,8 @@ typedef struct { #define __va_start_common(AP, FAKE) \ __extension__ ({ \ register int __words = __va_words - FAKE; \ - (AP) = (struct __gnuc_va_list__ *)__builtin_alloca(sizeof(struct __gnuc_va_list__)); \ \ + (AP) = (struct __va_list_tag *)__builtin_alloca(sizeof(struct __va_list_tag)); \ (AP)->gpr = (__words < 8) ? __words : 8; \ (AP)->fpr = __va_fregno - 33; \ (AP)->reg_save_area = (((char *) __builtin_frame_address (0)) \ @@ -175,3 +176,59 @@ __extension__ (*({ \ #endif /* __VA_PPC_H__ */ #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */ + + +#else +/* Windows NT */ +/* Define __gnuc_va_list. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef char *__gnuc_va_list; +#endif /* not __GNUC_VA_LIST */ + +/* If this is for internal libc use, don't define anything but + __gnuc_va_list. */ +#if defined (_STDARG_H) || defined (_VARARGS_H) + +#define __va_start_common(AP, LASTARG, FAKE) \ + ((__builtin_saveregs ()), ((AP) = ((char *) &LASTARG) + __va_rounded_size (AP)), 0) + +#ifdef _STDARG_H /* stdarg.h support */ + +/* Calling __builtin_next_arg gives the proper error message if LASTARG is + not indeed the last argument. */ +#define va_start(AP,LASTARG) \ + (__builtin_saveregs (), \ + (AP) = __builtin_next_arg (LASTARG), \ + 0) + +#else /* varargs.h support */ + +#define va_start(AP) \ + (__builtin_saveregs (), \ + (AP) = __builtin_next_arg (__va_1st_arg) - sizeof (int), \ + 0) + +#define va_alist __va_1st_arg +#define va_dcl register int __va_1st_arg; ... + +#endif /* _STDARG_H */ + +#define __va_rounded_size(TYPE) ((sizeof (TYPE) + 3) & ~3) +#define __va_align(AP, TYPE) \ + ((((unsigned long)(AP)) + ((sizeof (TYPE) >= 8) ? 7 : 3)) \ + & ~((sizeof (TYPE) >= 8) ? 7 : 3)) + +#define va_arg(AP,TYPE) \ +( *(TYPE *)((AP = (char *) (__va_align(AP, TYPE) \ + + __va_rounded_size(TYPE))) \ + - __va_rounded_size(TYPE))) + +#define va_end(AP) ((void)0) + +/* Copy __gnuc_va_list into another variable of this type. */ +#define __va_copy(dest, src) (dest) = (src) + +#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */ +#endif /* Windows NT */ diff --git a/sys/arch/powerpc/isa/isabus.c b/sys/arch/powerpc/isa/isabus.c index 1753fa866f6..f45d31e16f2 100644 --- a/sys/arch/powerpc/isa/isabus.c +++ b/sys/arch/powerpc/isa/isabus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isabus.c,v 1.1 1997/10/11 11:53:00 pefo Exp $ */ +/* $OpenBSD: isabus.c,v 1.2 1998/05/29 04:15:35 rahnds Exp $ */ /* $NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp $ */ /*- @@ -157,6 +157,10 @@ isabrmatch(parent, cfdata, aux) return (1); } +typedef void (void_f) (void); +extern void_f *pending_int_f; +void isa_do_pending_int(); + void isabrattach(parent, self, aux) struct device *parent; @@ -166,6 +170,8 @@ isabrattach(parent, self, aux) struct isabr_softc *sc = (struct isabr_softc *)self; struct isabus_attach_args iba; + pending_int_f = isa_do_pending_int; + printf("\n"); /* Initialize interrupt controller */ @@ -371,7 +377,7 @@ isabr_intr_disestablish(ic, arg) } void -do_pending_int() +isa_do_pending_int() { struct intrhand *ih; int vector; diff --git a/sys/arch/powerpc/powerpc/autoconf.c b/sys/arch/powerpc/powerpc/autoconf.c index 412a4da2a54..4ea12832c49 100644 --- a/sys/arch/powerpc/powerpc/autoconf.c +++ b/sys/arch/powerpc/powerpc/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.4 1997/10/21 11:00:09 pefo Exp $ */ +/* $OpenBSD: autoconf.c,v 1.5 1998/05/29 04:15:37 rahnds Exp $ */ /* * Copyright (c) 1996, 1997 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt @@ -41,7 +41,7 @@ * from: Utah Hdr: autoconf.c 1.31 91/01/21 * * from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93 - * $Id: autoconf.c,v 1.4 1997/10/21 11:00:09 pefo Exp $ + * $Id: autoconf.c,v 1.5 1998/05/29 04:15:37 rahnds Exp $ */ /* @@ -93,6 +93,7 @@ configure() (void)splhigh(); /* To be really sure.. */ if(config_rootfound("mainbus", "mainbus") == 0) panic("no mainbus found"); + ofrootfound(); (void)spl0(); setroot(); @@ -128,7 +129,8 @@ static struct nam2blk { char *name; int maj; } nam2blk[] = { - { "sd", 2 }, /* 2 = sd */ + { "sd", 2 }, /* 2 = sd */ + { "ofdisk", 4 }, /* 2 = ofdisk */ }; static int @@ -241,7 +243,7 @@ printf("bootpath: '%s'\n", bootpath); if(bootdv == NULL) { printf("boot device: lookup '%s' failed.\n", bootdev); boothowto |= RB_ASKNAME; /* Don't Panic :-) */ - boothowto |= RB_SINGLE; + /* boothowto |= RB_SINGLE; */ } else { printf("boot device: %s.\n", bootdv->dv_xname); diff --git a/sys/arch/powerpc/powerpc/conf.c b/sys/arch/powerpc/powerpc/conf.c index 2f9f293d3e8..e75d6e113ca 100644 --- a/sys/arch/powerpc/powerpc/conf.c +++ b/sys/arch/powerpc/powerpc/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.6 1997/11/23 05:21:58 mickey Exp $ */ +/* $OpenBSD: conf.c,v 1.7 1998/05/29 04:15:38 rahnds Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -46,6 +46,9 @@ bdev_decl(sw); #include "cd.h" bdev_decl(cd); +#include "ofdisk.h" +bdev_decl(ofd); + #include "rd.h" bdev_decl(rd); @@ -59,7 +62,7 @@ struct bdevsw bdevsw[] = { bdev_swap_init(1,sw), /* 1 swap pseudo device */ bdev_disk_init(NSD,sd), /* 2 SCSI Disk */ bdev_disk_init(NCD,cd), /* 3 SCSI CD-ROM */ - bdev_notdef(), /* 4 */ + bdev_disk_init(NOFDISK,ofd), /* 4 Openfirmware disk */ bdev_notdef(), /* 5 unknown*/ bdev_notdef(), /* 6 unknown*/ bdev_notdef(), /* 7 unknown*/ @@ -94,6 +97,13 @@ cdev_decl(sw); #include "com.h" cdev_decl(com); +#include "ofcons.h" +cdev_decl(ofc); +cdev_decl(ofd); + +#include "ofrtc.h" +cdev_decl(ofrtc); + #include <sd.h> #include <st.h> #include <cd.h> @@ -142,8 +152,8 @@ struct cdevsw cdevsw[] = { cdev_notdef(), /* 10: SCSI changer */ cdev_notdef(), /* 11 */ cdev_notdef(), /* 12 */ - cdev_notdef(), /* 13 */ - cdev_notdef(), /* 14 */ + cdev_disk_init(NOFDISK,ofd), /* 13 Openfirmware disk */ + cdev_tty_init(NOFCONS,ofc), /* 14 Openfirmware console */ cdev_notdef(), /* 15 */ cdev_notdef(), /* 16 */ cdev_disk_init(NRD,rd), /* 17 ram disk driver*/ @@ -217,7 +227,7 @@ static int chrtoblktbl[] = { /* 10 */ NODEV, /* 11 */ NODEV, /* 12 */ NODEV, - /* 13 */ NODEV, + /* 13 */ 4, /* 14 */ NODEV, /* 15 */ NODEV, /* 16 */ NODEV, @@ -284,8 +294,12 @@ blktochr(dev) #include <dev/cons.h> cons_decl(com); +cons_decl(ofc); struct consdev constab[] = { +#if NOFCONS > 0 + cons_init(ofc), +#endif #if NCOM > 0 cons_init(com), #endif diff --git a/sys/arch/powerpc/powerpc/machdep.c b/sys/arch/powerpc/powerpc/machdep.c index dbeaf15cc4f..aa029c8630e 100644 --- a/sys/arch/powerpc/powerpc/machdep.c +++ b/sys/arch/powerpc/powerpc/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.12 1997/10/21 18:01:45 pefo Exp $ */ +/* $OpenBSD: machdep.c,v 1.13 1998/05/29 04:15:39 rahnds Exp $ */ /* $NetBSD: machdep.c,v 1.4 1996/10/16 19:33:11 ws Exp $ */ /* @@ -85,7 +85,12 @@ struct bat battable[16]; int astpending; -int system_type = POWER4e; /* XXX Hardwire it for now */ +#ifndef SYS_TYPE +/* XXX Hardwire it for now */ +#define SYS_TYPE POWER4e +#endif + +int system_type = SYS_TYPE; /* XXX Hardwire it for now */ char ofw_eth_addr[6]; /* Save address of first network ifc found */ char *bootpath; @@ -804,3 +809,18 @@ power4e_get_eth_addr() } return(-1); } + +typedef void (void_f) (void); +void_f *pending_int_f = NULL; + +/* call the bus/interrupt controller specific pending interrupt handler + * would be nice if the offlevel interrupt code was handled here + * instead of being in each of the specific handler code + */ +void +do_pending_int() +{ + if (pending_int_f != NULL) { + (*pending_int_f)(); + } +} diff --git a/sys/arch/powerpc/powerpc/ofw_machdep.c b/sys/arch/powerpc/powerpc/ofw_machdep.c index f0d7c583d45..a544b97850e 100644 --- a/sys/arch/powerpc/powerpc/ofw_machdep.c +++ b/sys/arch/powerpc/powerpc/ofw_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_machdep.c,v 1.4 1997/10/13 13:42:59 pefo Exp $ */ +/* $OpenBSD: ofw_machdep.c,v 1.5 1998/05/29 04:15:40 rahnds Exp $ */ /* $NetBSD: ofw_machdep.c,v 1.1 1996/09/30 16:34:50 ws Exp $ */ /* @@ -44,6 +44,7 @@ #include <sys/systm.h> #include <machine/powerpc.h> +#include <machine/autoconf.h> void OF_exit __P((void)) __attribute__((__noreturn__)); void OF_boot __P((char *bootspec)) __attribute__((__noreturn__)); @@ -91,3 +92,61 @@ ppc_boot(str) { OF_boot(str); } + +#include <dev/ofw/openfirm.h> + +typedef void (void_f) (void); +extern void_f *pending_int_f; +void ofw_do_pending_int(); +extern int system_type; + +void +ofrootfound() +{ + int node; + struct ofprobe probe; + + if (!(node = OF_peer(0))) + panic("No PROM root"); + probe.phandle = node; + if (!config_rootfound("ofroot", &probe)) + panic("ofroot not configured"); + if (system_type == OFWMACH) { + pending_int_f = ofw_do_pending_int; + } +} +void +ofw_do_pending_int() +{ + struct intrhand *ih; + int vector; + int pcpl; + int hwpend; + int emsr, dmsr; +static int processing; + + if(processing) + return; + + processing = 1; + __asm__ volatile("mfmsr %0" : "=r"(emsr)); + dmsr = emsr & ~PSL_EE; + __asm__ volatile("mtmsr %0" :: "r"(dmsr)); + + pcpl = splhigh(); /* Turn off all */ + if(ipending & SINT_CLOCK) { + ipending &= ~SINT_CLOCK; + softclock(); + } + if(ipending & SINT_NET) { + extern int netisr; + int pisr = netisr; + netisr = 0; + ipending &= ~SINT_NET; + softnet(pisr); + } + ipending &= pcpl; + cpl = pcpl; /* Don't use splx... we are here already! */ + __asm__ volatile("mtmsr %0" :: "r"(emsr)); + processing = 0; +} diff --git a/sys/arch/powerpc/stand/ofwboot/Locore.c b/sys/arch/powerpc/powerpc/opendev.c index 4887605d145..c82812e7eb2 100644 --- a/sys/arch/powerpc/stand/ofwboot/Locore.c +++ b/sys/arch/powerpc/powerpc/opendev.c @@ -1,4 +1,5 @@ -/* $NetBSD: Locore.c,v 1.1 1997/04/16 20:29:11 thorpej Exp $ */ +/* $OpenBSD: opendev.c,v 1.1 1998/05/29 04:15:41 rahnds Exp $ */ +/* $NetBSD: openfirm.c,v 1.1 1996/09/30 16:34:52 ws Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -30,165 +31,166 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <sys/param.h> -#include <lib/libsa/stand.h> -#include <powerpc/stand/ofwboot/openfirm.h> +#include <machine/psl.h> +#include <machine/stdarg.h> -/* -#include "machine/cpu.h" -*/ - -static int (*openfirmware)(void *); +#include <dev/ofw/openfirm.h> -static void setup __P((void)); +char *OF_buf; -#ifdef XCOFF_GLUE -asm (".text; .globl _entry; _entry: .long _start,0,0"); -#endif +extern void ofw_stack __P((void)); +extern void ofbcopy __P((const void *, void *, size_t)); -__dead void -_start(vpd, res, openfirm, arg, argl) - void *vpd; - int res; - int (*openfirm)(void *); - char *arg; - int argl; -{ - extern char etext[]; -#ifdef FIRMWORKSBUGS - syncicache((void *)RELOC, etext - (char *)RELOC); -#endif - openfirmware = openfirm; /* Save entry to Open Firmware */ - setup(); - main(arg, argl); - exit(); -} - -__dead void -_rtt() -{ - static struct { - char *name; - int nargs; - int nreturns; - } args = { - "exit", - 0, - 0 - }; - openfirmware(&args); - while (1); /* just in case */ -} int -OF_finddevice(name) - char *name; +OF_instance_to_package(ihandle) + int ihandle; { static struct { char *name; int nargs; int nreturns; - char *device; + int ihandle; int phandle; } args = { - "finddevice", + "instance-to-package", 1, 1, - }; - - args.device = name; + }; + + ofw_stack(); + args.ihandle = ihandle; if (openfirmware(&args) == -1) return -1; return args.phandle; } int -OF_instance_to_package(ihandle) - int ihandle; +OF_package_to_path(phandle, buf, buflen) + int phandle; + char *buf; + int buflen; { static struct { char *name; int nargs; int nreturns; - int ihandle; int phandle; + char *buf; + int buflen; + int length; } args = { - "instance-to-package", - 1, + "package-to-path", + 3, 1, }; - args.ihandle = ihandle; - if (openfirmware(&args) == -1) + ofw_stack(); + if (buflen > NBPG) return -1; - return args.phandle; + args.phandle = phandle; + args.buf = OF_buf; + args.buflen = buflen; + if (openfirmware(&args) < 0) + return -1; + if (args.length > 0) + ofbcopy(OF_buf, buf, args.length); + return args.length; } + int -OF_getprop(handle, prop, buf, buflen) - int handle; - char *prop; - void *buf; - int buflen; +#ifdef __STDC__ +OF_call_method(char *method, int ihandle, int nargs, int nreturns, ...) +#else +OF_call_method(method, ihandle, nargs, nreturns, va_alist) + char *method; + int ihandle; + int nargs; + int nreturns; + va_dcl +#endif { + va_list ap; static struct { char *name; int nargs; int nreturns; - int phandle; - char *prop; - void *buf; - int buflen; - int size; + char *method; + int ihandle; + int args_n_results[12]; } args = { - "getprop", - 4, + "call-method", + 2, 1, }; + int *ip, n; - args.phandle = handle; - args.prop = prop; - args.buf = buf; - args.buflen = buflen; + if (nargs > 6) + return -1; + args.nargs = nargs + 2; + args.nreturns = nreturns + 1; + args.method = method; + args.ihandle = ihandle; + va_start(ap, nreturns); + for (ip = args.args_n_results + (n = nargs); --n >= 0;) + *--ip = va_arg(ap, int); + ofw_stack(); if (openfirmware(&args) == -1) return -1; - return args.size; + if (args.args_n_results[nargs]) + return args.args_n_results[nargs]; + for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;) + *va_arg(ap, int *) = *--ip; + va_end(ap); + return 0; } - -#ifdef __notyet__ /* Has a bug on FirePower */ int -OF_setprop(handle, prop, buf, len) - int handle; - char *prop; - void *buf; - int len; +#ifdef __STDC__ +OF_call_method_1(char *method, int ihandle, int nargs, ...) +#else +OF_call_method_1(method, ihandle, nargs, va_alist) + char *method; + int ihandle; + int nargs; + va_dcl +#endif { + va_list ap; static struct { char *name; int nargs; int nreturns; - int phandle; - char *prop; - void *buf; - int len; - int size; + char *method; + int ihandle; + int args_n_results[8]; } args = { - "setprop", - 4, - 1, + "call-method", + 2, + 2, }; + int *ip, n; - args.phandle = handle; - args.prop = prop; - args.buf = buf; - args.len = len; + if (nargs > 6) + return -1; + args.nargs = nargs + 2; + args.method = method; + args.ihandle = ihandle; + va_start(ap, nargs); + for (ip = args.args_n_results + (n = nargs); --n >= 0;) + *--ip = va_arg(ap, int); + va_end(ap); + ofw_stack(); if (openfirmware(&args) == -1) return -1; - return args.size; + if (args.args_n_results[nargs]) + return -1; + return args.args_n_results[nargs + 1]; } -#endif int OF_open(dname) @@ -205,8 +207,13 @@ OF_open(dname) 1, 1, }; + int l; - args.dname = dname; + ofw_stack(); + if ((l = strlen(dname)) >= NBPG) + return -1; + ofbcopy(dname, OF_buf, l + 1); + args.dname = OF_buf; if (openfirmware(&args) == -1) return -1; return args.handle; @@ -226,13 +233,17 @@ OF_close(handle) 1, 0, }; - + + ofw_stack(); args.handle = handle; openfirmware(&args); } +/* + * This assumes that character devices don't read in multiples of NBPG. + */ int -OF_write(handle, addr, len) +OF_read(handle, addr, len) int handle; void *addr; int len; @@ -246,21 +257,35 @@ OF_write(handle, addr, len) int len; int actual; } args = { - "write", + "read", 3, 1, }; - + int l, act = 0; + + ofw_stack(); args.ihandle = handle; - args.addr = addr; - args.len = len; - if (openfirmware(&args) == -1) - return -1; - return args.actual; + args.addr = OF_buf; + for (; len > 0; len -= l, addr += l) { + l = min(NBPG, len); + args.len = l; + if (openfirmware(&args) == -1) + return -1; + if (args.actual > 0) { + ofbcopy(OF_buf, addr, args.actual); + act += args.actual; + } + if (args.actual < l) + if (act) + return act; + else + return args.actual; + } + return act; } int -OF_read(handle, addr, len) +OF_write(handle, addr, len) int handle; void *addr; int len; @@ -274,17 +299,25 @@ OF_read(handle, addr, len) int len; int actual; } args = { - "read", + "write", 3, 1, }; - + int l, act = 0; + + ofw_stack(); args.ihandle = handle; - args.addr = addr; - args.len = len; - if (openfirmware(&args) == -1) - return -1; - return args.actual; + args.addr = OF_buf; + for (; len > 0; len -= l, addr += l) { + l = min(NBPG, len); + ofbcopy(addr, OF_buf, l); + args.len = l; + if (openfirmware(&args) == -1) + return -1; + l = args.actual; + act += l; + } + return act; } int @@ -305,7 +338,8 @@ OF_seek(handle, pos) 3, 1, }; - + + ofw_stack(); args.handle = handle; args.poshi = (int)(pos >> 32); args.poslo = (int)pos; @@ -313,165 +347,3 @@ OF_seek(handle, pos) return -1; return args.status; } - -void * -OF_claim(virt, size, align) - void *virt; - u_int size; - u_int align; -{ - static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; - u_int align; - void *baseaddr; - } args = { - "claim", - 3, - 1, - }; - -#ifdef FIRMWORKSBUGS - /* - * Bug with Firmworks OFW - */ - if (virt) - return virt; -#endif - args.virt = virt; - args.size = size; - args.align = align; - if (openfirmware(&args) == -1) - return (void *)-1; - return args.baseaddr; -} - -void -OF_release(virt, size) - void *virt; - u_int size; -{ - static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; - } args = { - "release", - 2, - 0, - }; - - args.virt = virt; - args.size = size; - openfirmware(&args); -} - -int -OF_milliseconds() -{ - static struct { - char *name; - int nargs; - int nreturns; - int ms; - } args = { - "milliseconds", - 0, - 1, - }; - - openfirmware(&args); - return args.ms; -} - -#ifdef __notyet__ -void -OF_chain(virt, size, entry, arg, len) - void *virt; - u_int size; - void (*entry)(); - void *arg; - u_int len; -{ - static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; - void (*entry)(); - void *arg; - u_int len; - } args = { - "chain", - 5, - 0, - }; - - args.virt = virt; - args.size = size; - args.entry = entry; - args.arg = arg; - args.len = len; - openfirmware(&args); -} -#else -void -OF_chain(virt, size, entry, arg, len) - void *virt; - u_int size; - void (*entry)(); - void *arg; - u_int len; -{ - /* - * This is a REALLY dirty hack till the firmware gets this going - */ - OF_release(virt, size); - entry(0, 0, openfirmware, arg, len); -} -#endif - -static int stdin; -static int stdout; - -static void -setup() -{ - int chosen; - - if ((chosen = OF_finddevice("/chosen")) == -1) - _rtt(); - if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) != sizeof(stdin) - || OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) != - sizeof(stdout)) - _rtt(); -} - -void -putchar(c) - int c; -{ - char ch = c; - - if (c == '\n') - putchar('\r'); - OF_write(stdout, &ch, 1); -} - -int -getchar() -{ - unsigned char ch; - int l; - - while ((l = OF_read(stdin, &ch, 1)) != 1) - if (l != -2) - return -1; - return ch; -} diff --git a/sys/arch/powerpc/powerpc/trap.c b/sys/arch/powerpc/powerpc/trap.c index 881c9e5a122..e95f96b49e9 100644 --- a/sys/arch/powerpc/powerpc/trap.c +++ b/sys/arch/powerpc/powerpc/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.7 1998/04/06 20:21:11 pefo Exp $ */ +/* $OpenBSD: trap.c,v 1.8 1998/05/29 04:15:41 rahnds Exp $ */ /* $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $ */ /* @@ -260,7 +260,9 @@ syscall_bad: brain_damage: printf("trap type %x at %x\n", type, frame->srr0); +/* mpc_print_pci_stat(); +*/ panic("trap"); case EXC_PGM|EXC_USER: diff --git a/sys/arch/powerpc/stand/Locore.c b/sys/arch/powerpc/stand/Locore.c index b50db4c1d92..d39d5d297e1 100644 --- a/sys/arch/powerpc/stand/Locore.c +++ b/sys/arch/powerpc/stand/Locore.c @@ -1,5 +1,4 @@ -/* $OpenBSD: Locore.c,v 1.5 1997/04/17 02:27:36 briggs Exp $ */ -/* $NetBSD: Locore.c,v 1.1 1996/09/30 16:34:58 ws Exp $ */ +/* $NetBSD: Locore.c,v 1.1 1997/04/16 20:29:11 thorpej Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -31,23 +30,21 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stand.h> -#include <openfirm.h> + +#include <lib/libsa/stand.h> +#include <powerpc/stand/openfirm.h> /* -#include <machine/cpu.h> +#include "machine/cpu.h" */ static int (*openfirmware)(void *); -static void -setup(); - -void _start(); - -#define __dead +static void setup __P((void)); -void const *__start[3] = { &_start, 0, 0}; +#ifdef XCOFF_GLUE +asm (".text; .globl _entry; _entry: .long _start,0,0"); +#endif __dead void _start(vpd, res, openfirm, arg, argl) @@ -57,15 +54,17 @@ _start(vpd, res, openfirm, arg, argl) char *arg; int argl; { - extern char etext; + extern char etext[]; +#ifdef FIRMWORKSBUGS + syncicache((void *)RELOC, etext - (char *)RELOC); +#endif openfirmware = openfirm; /* Save entry to Open Firmware */ setup(); main(arg, argl); exit(); } - __dead void _rtt() { @@ -335,9 +334,9 @@ OF_claim(virt, size, align) 1, }; -#ifdef FIREPOWERBUGS +#ifdef FIRMWORKSBUGS /* - * Bug with FirePower machines (actually Firmworks OFW) + * Bug with Firmworks OFW */ if (virt) return virt; @@ -449,7 +448,8 @@ setup() if ((chosen = OF_finddevice("/chosen")) == -1) _rtt(); if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) != sizeof(stdin) - || OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) != sizeof(stdout)) + || OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) != + sizeof(stdout)) _rtt(); } @@ -471,7 +471,7 @@ getchar() int l; while ((l = OF_read(stdin, &ch, 1)) != 1) - if (l != -2 && l != 0) + if (l != -2) return -1; return ch; } diff --git a/sys/arch/powerpc/stand/Makefile b/sys/arch/powerpc/stand/Makefile index fb1d3abc93a..96c7c9194ec 100644 --- a/sys/arch/powerpc/stand/Makefile +++ b/sys/arch/powerpc/stand/Makefile @@ -1,8 +1,7 @@ -# $OpenBSD: Makefile,v 1.7 1997/10/15 14:07:53 pefo Exp $ +# $OpenBSD: Makefile,v 1.8 1998/05/29 04:15:44 rahnds Exp $ # $NetBSD: Makefile,v 1.1 1996/09/30 16:34:59 ws Exp $ -#SUBDIR= boot boot.mac ofwboot mbr -SUBDIR= ofwboot mbr +SUBDIR= ofwboot boot.mac mbr SAREL= KERNREL= diff --git a/sys/arch/powerpc/stand/alloc.c b/sys/arch/powerpc/stand/alloc.c index be3051c217b..c29f286e75b 100644 --- a/sys/arch/powerpc/stand/alloc.c +++ b/sys/arch/powerpc/stand/alloc.c @@ -1,7 +1,10 @@ -/* $OpenBSD: alloc.c,v 1.4 1997/02/06 23:44:55 rahnds Exp $ */ -/* $NetBSD: alloc.c,v 1.1 1996/09/30 16:35:00 ws Exp $ */ +/* $NetBSD: alloc.c,v 1.1 1997/04/16 20:29:16 thorpej Exp $ */ /* + * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1996 + * Matthias Drochner. All rights reserved. * Copyright (C) 1995, 1996 Wolfgang Solfrank. * Copyright (C) 1995, 1996 TooLs GmbH. * All rights reserved. @@ -33,162 +36,182 @@ */ /* - * Substitute alloc.c for Openfirmware machines + * Dynamic memory allocator suitable for use with OpenFirmware. + * + * Compile options: + * + * ALLOC_TRACE enable tracing of allocations/deallocations + * + * ALLOC_FIRST_FIT use a first-fit allocation algorithm, rather than + * the default best-fit algorithm. + * + * DEBUG enable debugging sanity checks. */ + #include <sys/param.h> +#include <sys/queue.h> + +#include <lib/libsa/stand.h> + +#include <powerpc/stand/openfirm.h> -#include <openfirm.h> -#include <stand.h> +/* + * Each block actually has ALIGN(struct ml) + ALIGN(size) bytes allocated + * to it, as follows: + * + * 0 ... (sizeof(struct ml) - 1) + * allocated or unallocated: holds size of user-data part of block. + * + * sizeof(struct ml) ... (ALIGN(sizeof(struct ml)) - 1) + * allocated: unused + * unallocated: depends on packing of struct fl + * + * ALIGN(sizeof(struct ml)) ... (ALIGN(sizeof(struct ml)) + + * ALIGN(data size) - 1) + * allocated: user data + * unallocated: depends on packing of struct fl + * + * 'next' is only used when the block is unallocated (i.e. on the free list). + * However, note that ALIGN(sizeof(struct ml)) + ALIGN(data size) must + * be at least 'sizeof(struct fl)', so that blocks can be used as structures + * when on the free list. + */ /* - * al tracks the allocated regions, fl tracks the free list + * Memory lists. */ struct ml { - struct ml *next; - unsigned int size; -} *al, *fl; + unsigned size; + LIST_ENTRY(ml) list; +}; + +/* XXX - this is from NetBSD */ +#define LIST_HEAD_INITIALIZER(head) { NULL } + +LIST_HEAD(, ml) freelist = LIST_HEAD_INITIALIZER(freelist); +LIST_HEAD(, ml) allocatedlist = LIST_HEAD_INITIALIZER(allocatedlist); + +#define OVERHEAD ALIGN(sizeof (struct ml)) /* shorthand */ void * alloc(size) unsigned size; { - struct ml **fp, *f; - unsigned rsz; - - size = ALIGN(size) + ALIGN(sizeof(struct ml)); - for (fp = &fl; f = *fp; fp = &f->next) - if (f->size >= size) - break; - if (!f) { - rsz = roundup(size, NBPG); - f = OF_claim(0, rsz, NBPG); - if (f == (void *)-1) - panic("alloc"); - f->size = rsz; - } else { - *fp = f->next; - if (f->size > roundup(size, NBPG)) { - /* if the buffer is larger than necessary, split it */ - /* still rounding to page size */ - struct ml *f1; - f1 = (struct ml *)((u_int)f + roundup(size, NBPG)); - f1->size = f->size - roundup(size, NBPG); - f->size = roundup(size, NBPG); - /* put the unused portion back on free list */ - f1->next = fl; - fl = f1; + struct ml *f, *bestf; + unsigned bestsize = 0xffffffff; /* greater than any real size */ + char *help; + int failed; + +#ifdef ALLOC_TRACE + printf("alloc(%u)", size); +#endif + + /* + * Account for overhead now, so that we don't get an + * "exact fit" which doesn't have enough space. + */ + size = ALIGN(size) + OVERHEAD; + +#ifdef ALLOC_FIRST_FIT + /* scan freelist */ + for (f = freelist.lh_first; f != NULL && f->size < size; + f = f->list.le_next) + /* noop */ ; + bestf = f; + failed = (bestf == (struct fl *)0); +#else + /* scan freelist */ + f = freelist.lh_first; + while (f != NULL) { + if (f->size >= size) { + if (f->size == size) /* exact match */ + goto found; + + if (f->size < bestsize) { + /* keep best fit */ + bestf = f; + bestsize = f->size; + } } + f = f->list.le_next; + } + + /* no match in freelist if bestsize unchanged */ + failed = (bestsize == 0xffffffff); +#endif + + if (failed) { /* nothing found */ + /* + * Allocate memory from the OpenFirmware, rounded + * to page size, and record the chunk size. + */ + size = roundup(size, NBPG); + help = OF_claim(0, size, NBPG); + if (help == (char *)-1) + panic("alloc: out of memory"); + + f = (struct ml *)help; + f->size = size; +#ifdef ALLOC_TRACE + printf("=%lx (new chunk size %u)\n", + (u_long)(help + OVERHEAD), f->f_size); +#endif + goto out; } - - f->next = al; - al = f; - return (void *)f + ALIGN(sizeof(struct ml)); + + /* we take the best fit */ + f = bestf; + + found: + /* remove from freelist */ + LIST_REMOVE(f, list); + help = (char *)f; +#ifdef ALLOC_TRACE + printf("=%lx (origsize %u)\n", (u_long)(help + OVERHEAD), f->size); +#endif + out: + /* place on allocated list */ + LIST_INSERT_HEAD(&allocatedlist, f, list); + return (help + OVERHEAD); } void free(ptr, size) void *ptr; - unsigned size; + unsigned size; /* only for consistenct check */ { - struct ml *f = (struct ml *)(ptr - ALIGN(sizeof(struct ml))); - -#if IGNORE_FOR_NOW - if (f->size != roundup(ALIGN(size) + ALIGN(sizeof(struct ml)), NBPG)) - panic("free: wrong size (%x != %x)", - f->size, - roundup(ALIGN(size) + ALIGN(sizeof(struct ml)), NBPG)); + register struct ml *a = (struct ml *)((char*)ptr - OVERHEAD); + +#ifdef ALLOC_TRACE + printf("free(%lx, %u) (origsize %u)\n", (u_long)ptr, size, a->size); +#endif +#ifdef DEBUG + if (size > a->size) + printf("free %u bytes @%lx, should be <=%u\n", + size, (u_long)ptr, a->size); #endif - f->next = fl; - fl = f; + + /* Remove from allocated list, place on freelist. */ + LIST_REMOVE(a, list); + LIST_INSERT_HEAD(&freelist, a, list); } void freeall() { -#ifdef __notyet__ /* looks like there is a bug in Motorola OFW */ - struct ml *m1, *m2; +#ifdef __notyet__ /* Firmware bug ?! */ + struct ml *m; - for (m1 = fl; m1; m1 = m2) { - m2 = m1->next; - OF_release(m1, m1->size); - } - for (m1 = al; m1; m1 = m2) { - m2 = m1->next; - OF_release(m1, m1->size); + /* Release chunks on freelist... */ + while ((m = freelist.lh_first) != NULL) { + LIST_REMOVE(m, list); + OF_release(m, m->size); } -#endif -} - -#ifdef __notdef__ -#ifdef FIREPOWERBUGS -/* - * Since firmware insists on running virtual, we manage memory ourselves, - * hoping that OpenFirmware will not need extra memory. - * (But then, the callbacks don't work anyway). - */ -#define OFMEM_REGIONS 32 -static struct { - u_int start; - u_int size; -} OFavail[OFMEM_REGIONS]; -void * -OF_claim(virt, size, align) - void *virt; - u_int size, align; -{ - static int init; - int i; - u_int addr = -1; - - if (!init) { - int phandle; - - init = 1; - - if ((phandle = OF_finddevice("/memory")) == -1 - || OF_getprop(phandle, "available", - OFavail, sizeof OFavail) <= 0) - return (void *)-1; + /* ...and allocated list. */ + while ((m = allocatedlist.lh_first) != NULL) { + LIST_REMOVE(m, list); + OF_release(m, m->size); } - if (align) { - /* Due to the above, anything is page aligned here */ - for (i = 0; i < OFMEM_REGIONS; i++) { - if (!OFavail[i].size) - break; - if (OFavail[i].size > size) { - addr = OFavail[i].start; - OFavail[i].start += size; - OFavail[i].size -= size; - break; - } - } - } else { - addr = (u_int)virt; - for (i = 0; i < OFMEM_REGIONS; i++) { - if (!OFavail[i].size) { - addr = -1; - break; - } - if (OFavail[i].start <= addr - && addr + size - OFavail[i].start <= OFavail[i].size) { - /* Be lazy here, just cut off anything below addr */ - size += addr - OFavail[i].start; - OFavail[i].start += size; - OFavail[i].size -= size; - break; - } - } - } - return (void *)addr; -} - -/* Since this is called solely immediately before chain, we ignore it. */ -void -OF_release(virt, size) - void *virt; - u_int size; -{ +#endif /* __notyet__ */ } -#endif /* FIREPOWERBUGS */ -#endif diff --git a/sys/arch/powerpc/stand/boot.c b/sys/arch/powerpc/stand/boot.c index 6dd32cc4f62..cae95a59de6 100644 --- a/sys/arch/powerpc/stand/boot.c +++ b/sys/arch/powerpc/stand/boot.c @@ -1,11 +1,14 @@ -/* $OpenBSD: boot.c,v 1.5 1997/04/01 21:01:42 rahnds Exp $ */ -/* $NetBSD: boot.c,v 1.2 1996/10/07 21:43:02 cgd Exp $ */ +/* $NetBSD: boot.c,v 1.1 1997/04/16 20:29:17 thorpej Exp $ */ /* + * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. * Copyright (C) 1995, 1996 Wolfgang Solfrank. * Copyright (C) 1995, 1996 TooLs GmbH. * All rights reserved. * + * ELF support derived from NetBSD/alpha's boot loader, written + * by Christopher G. Demetriou. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -31,28 +34,46 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + /* * First try for the boot code * * Input syntax is: * [promdev[{:|,}partition]]/[filename] [flags] */ -#include <stand.h> +#define ELFSIZE 32 /* We use 32-bit ELF. */ + +#include <lib/libkern/libkern.h> +#include <lib/libsa/stand.h> + +#include <sys/param.h> #include <sys/exec.h> +#include <sys/exec_elf.h> #include <sys/reboot.h> #include <sys/disklabel.h> -#include <sys/exec_elf.h> +#include <machine/cpu.h> +/* +#include <machine/machine_type.h> +*/ -#include "ofdev.h" -#include "openfirm.h" +#include <powerpc/stand/ofdev.h> +#include <powerpc/stand/openfirm.h> char bootdev[128]; char bootfile[128]; int boothowto; int debug; +#ifdef POWERPC_BOOT_ELF +int elf_exec __P((int, Elf32_Ehdr *, u_int32_t *, void **)); +#endif + +#ifdef POWERPC_BOOT_AOUT +int aout_exec __P((int, struct exec *, u_int32_t *, void **)); +#endif + static void prom2boot(dev) char *dev; @@ -75,7 +96,11 @@ parseargs(str, howtop) int *howtop; { char *cp; - + + /* Allow user to drop back to the PROM. */ + if (strcmp(str, "exit") == 0) + _rtt(); + *howtop = 0; for (cp = str; *cp; cp++) if (*cp == ' ' || *cp == '-') @@ -101,134 +126,315 @@ parseargs(str, howtop) } static void -chain(entry, args) +chain(entry, args, esym) void (*entry)(); char *args; + void *esym; { - extern end; + extern char end[]; + int l, machine_tag; freeall(); - OF_chain((void *)RELOC, (void *)&end - (void *)RELOC, - entry, args, strlen(args) + 1); + + /* + * Stash pointer to end of symbol table after the argument + * strings. + */ + l = strlen(args) + 1; + bcopy(&esym, args + l, sizeof(esym)); + l += sizeof(esym); + +#ifdef __notyet__ + /* + * Tell the kernel we're an OpenFirmware system. + */ + machine_tag = POWERPC_MACHINE_OPENFIRMWARE; + bcopy(&machine_tag, args + l, sizeof(machine_tag)); + l += sizeof(machine_tag); +#endif + + OF_chain((void *)RELOC, end - (char *)RELOC, entry, args, l); panic("chain"); } -static void -loadfile(fd, addr, args) +int +loadfile(fd, args) int fd; - void *addr; char *args; { - struct exec hdr; - int n; - int *paddr; - void *exec_addr; - - if (read(fd, &hdr, sizeof hdr) != sizeof(hdr)) - panic("short a.out file"); - if ( -#if defined (EXEC_AOUT) - (N_BADMAG(hdr) || N_GETMID(hdr) != MID_POWERPC) + union { +#ifdef POWERPC_BOOT_AOUT + struct exec aout; +#endif +#ifdef POWERPC_BOOT_ELF + Elf32_Ehdr elf; #endif -#if defined(EXEC_AOUT) && defined (EXEC_ELF) - && + } hdr; + int rval; + u_int32_t entry; + void *esym; + + rval = 1; + esym = NULL; + + /* Load the header. */ + if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) { + printf("read header: %s\n", strerror(errno)); + goto err; + } + + /* Determine file type, load kernel. */ +#ifdef POWERPC_BOOT_AOUT + if (N_BADMAG(hdr.aout) == 0 && N_GETMID(hdr.aout) == MID_POWERPC) { + rval = aout_exec(fd, &hdr.aout, &entry, &esym); + } else #endif -#if defined (EXEC_ELF) - (((u_int *)&hdr)[0] != 0x7f454c46) /* 0x7f E L F */ +#ifdef POWERPC_BOOT_ELF + if (IS_ELF(hdr.elf)) { + rval = elf_exec(fd, &hdr.elf, &entry, &esym); + } else #endif - ) { - panic("invalid executable format"); + printf("unknown executable format\n"); } -#ifdef EXEC_AOUT - if (N_GETMID(hdr) == MID_POWERPC) { - n = hdr.a_text + hdr.a_data + hdr.a_bss + hdr.a_syms - + sizeof(int); - if ((paddr = OF_claim(addr, n, 0)) == (int *)-1) - panic("cannot claim memory"); - lseek(fd, N_TXTOFF(hdr), SEEK_SET); - if (read(fd, paddr, hdr.a_text + hdr.a_data) != - hdr.a_text + hdr.a_data) - { - panic("short a.out file"); + + if (rval) + goto err; + + printf(" start=0x%x\n", entry); + + close(fd); + + /* XXX this should be replaced w/ a mountroothook. */ + if (floppyboot) { + printf("Please insert root disk and press ENTER "); + getchar(); + printf("\n"); + } + + chain((void *)entry, args, esym); + /* NOTREACHED */ + + err: + close(fd); + return (rval); +} + +#ifdef POWERPC_BOOT_AOUT +int +aout_exec(fd, hdr, entryp, esymp) + int fd; + struct exec *hdr; + u_int32_t *entryp; + void **esymp; +{ + void *addr; + int n, *paddr; + + /* Display the load address (entry point) for a.out. */ + printf("Booting %s @ 0x%lx\n", opened_name, hdr->a_entry); + addr = (void *)(hdr->a_entry); + + /* + * Determine memory needed for kernel and allocate it from + * the firmware. + */ + n = hdr->a_text + hdr->a_data + hdr->a_bss + hdr->a_syms + sizeof(int); + if ((paddr = OF_claim(addr, n, 0)) == (int *)-1) + panic("cannot claim memory"); + + /* Load text. */ + lseek(fd, N_TXTOFF(*hdr), SEEK_SET); + printf("%lu", hdr->a_text); + if (read(fd, paddr, hdr->a_text) != hdr->a_text) { + printf("read text: %s\n", strerror(errno)); + return (1); + } + syncicache((void *)paddr, hdr->a_text); + + /* Load data. */ + printf("+%lu", hdr->a_data); + if (read(fd, (void *)paddr + hdr->a_text, hdr->a_data) != hdr->a_data) { + printf("read data: %s\n", strerror(errno)); + return (1); + } + + /* Zero BSS. */ + printf("+%lu", hdr->a_bss); + bzero((void *)paddr + hdr->a_text + hdr->a_data, hdr->a_bss); + + /* Symbols. */ + *esymp = paddr; + paddr = (int *)((void *)paddr + hdr->a_text + hdr->a_data + hdr->a_bss); + *paddr++ = hdr->a_syms; + if (hdr->a_syms) { + printf(" [%lu", hdr->a_syms); + if (read(fd, paddr, hdr->a_syms) != hdr->a_syms) { + printf("read symbols: %s\n", strerror(errno)); + return (1); } - bzero((void *)paddr + hdr.a_text + hdr.a_data, hdr.a_bss); - paddr = (int *)((void *)paddr + hdr.a_text + hdr.a_data - + hdr.a_bss); - *paddr++ = hdr.a_syms; - if (hdr.a_syms) { - if (read(fd, paddr, hdr.a_syms) != hdr.a_syms) - panic("short a.out file"); - paddr = (int *)((void *)paddr + hdr.a_syms); - if (read(fd, &n, sizeof(int)) != sizeof(int)) - panic("short a.out file"); - if (OF_claim((void *)paddr, n + sizeof(int), 0) == - (void *)-1) - { - panic("cannot claim memory"); - } - *paddr++ = n; - if (read(fd, paddr, n - sizeof(int)) != n - sizeof(int)) - { - panic("short a.out file"); - } + paddr = (int *)((void *)paddr + hdr->a_syms); + if (read(fd, &n, sizeof(int)) != sizeof(int)) { + printf("read symbols: %s\n", strerror(errno)); + return (1); + } + if (OF_claim((void *)paddr, n + sizeof(int), 0) == (void *)-1) + panic("cannot claim memory"); + *paddr++ = n; + if (read(fd, paddr, n - sizeof(int)) != n - sizeof(int)) { + printf("read symbols: %s\n", strerror(errno)); + return (1); } - exec_addr = hdr.a_text; + printf("+%d]", n - sizeof(int)); + *esymp = paddr + (n - sizeof(int)); } -#endif -#ifdef EXEC_ELF - if (((u_int *)&hdr)[0] == 0x7f454c46) /* 0x7f E L F */ { - Elf32_Ehdr ehdr; + + *entryp = hdr->a_entry; + return (0); +} +#endif /* POWERPC_BOOT_AOUT */ + +#ifdef POWERPC_BOOT_ELF +int +elf_exec(fd, elf, entryp, esymp) + int fd; + Elf32_Ehdr *elf; + u_int32_t *entryp; + void **esymp; +{ + Elf32_Shdr *shp; + Elf32_Off off; + void *addr; + size_t size; + int i, first = 1; + int n; + + /* + * Don't display load address for ELF; it's encoded in + * each section. + */ + printf("Booting %s\n", opened_name); + + for (i = 0; i < elf->e_phnum; i++) { Elf32_Phdr phdr; - int loc_phdr; - int i; - - lseek (fd, 0, SEEK_SET); - read (fd, &ehdr, sizeof (ehdr)); - loc_phdr = ehdr.e_phoff; - for (i = 1; i <=ehdr.e_phnum; i++) { - lseek(fd, loc_phdr, SEEK_SET); - read (fd, &phdr, sizeof(phdr)); - loc_phdr += sizeof(phdr); - - if (phdr.p_type == PT_LOAD) { - printf("phseg %d addr %x size %x\n", i, - phdr.p_vaddr, phdr.p_memsz); - lseek(fd, phdr.p_offset, SEEK_SET); - paddr = (int *)phdr.p_vaddr; - n = phdr.p_memsz; - if (OF_claim((void *)paddr, n , 0) == (int *)-1) - panic("cannot claim memory"); - read (fd, paddr, phdr.p_filesz); - if (phdr.p_filesz != phdr.p_memsz) { - bzero (addr + n, - phdr.p_memsz - phdr.p_filesz); - } - } + (void)lseek(fd, elf->e_phoff + sizeof(phdr) * i, SEEK_SET); + if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) { + printf("read phdr: %s\n", strerror(errno)); + return (1); + } + if (phdr.p_type != PT_LOAD || + (phdr.p_flags & (PF_W|PF_X)) == 0) + continue; + + /* Read in segment. */ + printf("%s%lu@0x%lx", first ? "" : "+", phdr.p_filesz, + (u_long)phdr.p_vaddr); + (void)lseek(fd, phdr.p_offset, SEEK_SET); + if (OF_claim((void *)phdr.p_vaddr, phdr.p_memsz, 0) == + (void *)-1) + panic("cannot claim memory"); + if (read(fd, (void *)phdr.p_vaddr, phdr.p_filesz) != + phdr.p_filesz) { + printf("read segment: %s\n", strerror(errno)); + return (1); + } + syncicache((void *)phdr.p_vaddr, phdr.p_filesz); + + /* Zero BSS. */ + if (phdr.p_filesz < phdr.p_memsz) { + printf("+%lu@0x%lx", phdr.p_memsz - phdr.p_filesz, + (u_long)(phdr.p_vaddr + phdr.p_filesz)); + bzero(phdr.p_vaddr + phdr.p_filesz, + phdr.p_memsz - phdr.p_filesz); } - exec_addr = ehdr.e_entry; + first = 0; } -#endif - close(fd); -#if 0 - if (floppyboot) { - printf("Please insert root disk and press ENTER "); - getchar(); - printf("\n"); + + printf(" \n"); + +#if 0 /* I want to rethink this... --thorpej@netbsd.org */ + /* + * Compute the size of the symbol table. + */ + size = sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); + shp = addr = alloc(elf->e_shnum * sizeof(Elf32_Shdr)); + (void)lseek(fd, elf->e_shoff, SEEK_SET); + if (read(fd, addr, elf->e_shnum * sizeof(Elf32_Shdr)) != + elf->e_shnum * sizeof(Elf32_Shdr)) { + printf("read section headers: %s\n", strerror(errno)); + return (1); } -#endif - chain((void *)exec_addr, args); + for (i = 0; i < elf->e_shnum; i++, shp++) { + if (shp->sh_type == Elf32_sht_null) + continue; + if (shp->sh_type != Elf32_sht_symtab + && shp->sh_type != Elf32_sht_strtab) { + shp->sh_offset = 0; + shp->sh_type = Elf32_sht_nobits; + continue; + } + size += shp->sh_size; + } + shp = addr; + + /* + * Reserve memory for the symbols. + */ + if ((addr = OF_claim(0, size, NBPG)) == (void *)-1) + panic("no space for symbol table"); + + /* + * Copy the headers. + */ + elf->e_phoff = 0; + elf->e_shoff = sizeof(Elf32_Ehdr); + elf->e_phentsize = 0; + elf->e_phnum = 0; + bcopy(elf, addr, sizeof(Elf32_Ehdr)); + bcopy(shp, addr + sizeof(Elf32_Ehdr), elf->e_shnum * sizeof(Elf32_Shdr)); + free(shp, elf->e_shnum * sizeof(Elf32_Shdr)); + *ssymp = addr; + + /* + * Now load the symbol sections themselves. + */ + shp = addr + sizeof(Elf32_Ehdr); + addr += sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); + off = sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); + for (first = 1, i = 0; i < elf->e_shnum; i++, shp++) { + if (shp->sh_type == Elf32_sht_symtab + || shp->sh_type == Elf32_sht_strtab) { + if (first) + printf("symbols @ 0x%lx ", (u_long)addr); + printf("%s%d", first ? "" : "+", shp->sh_size); + (void)lseek(fd, shp->sh_offset, SEEK_SET); + if (read(fd, addr, shp->sh_size) != shp->sh_size) { + printf("read symbols: %s\n", strerror(errno)); + return (1); + } + addr += shp->sh_size; + shp->sh_offset = off; + off += shp->sh_size; + first = 0; + } + } + *esymp = addr; +#endif /* 0 */ + + *entryp = elf->e_entry; + return (0); } +#endif /* POWERPC_BOOT_ELF */ -char bootline[512]; void main() { int chosen; + char bootline[512]; /* Should check size? */ char *cp; int fd; - printf(">> OpenBSD BOOT\n"); + printf("\n>> OpenBSD/powerpc Boot\n"); /* * Get the boot arguments from Openfirmware @@ -253,12 +459,11 @@ main() printf("open %s: %s\n", opened_name, strerror(errno)); boothowto |= RB_ASKNAME; } - printf("Booting %s @ 0x%x\n", opened_name, LOADADDR); #ifdef __notyet__ OF_setprop(chosen, "bootpath", opened_name, strlen(opened_name) + 1); cp = bootline; #else - strncpy(bootline, opened_name, 512); + strcpy(bootline, opened_name); cp = bootline + strlen(bootline); *cp++ = ' '; #endif @@ -280,7 +485,8 @@ main() #ifdef __notyet__ OF_setprop(chosen, "bootargs", bootline, strlen(bootline) + 1); #endif - loadfile(fd, LOADADDR, bootline); + /* XXX void, for now */ + (void)loadfile(fd, bootline); _rtt(); } diff --git a/sys/arch/powerpc/stand/boot.mac/Makefile b/sys/arch/powerpc/stand/boot.mac/Makefile index 2ad27f5be94..c2cc55417c5 100644 --- a/sys/arch/powerpc/stand/boot.mac/Makefile +++ b/sys/arch/powerpc/stand/boot.mac/Makefile @@ -1,15 +1,15 @@ -# $OpenBSD: Makefile,v 1.3 1997/04/27 20:56:35 millert Exp $ +# $OpenBSD: Makefile,v 1.4 1998/05/29 04:15:56 rahnds Exp $ # $NetBSD: Makefile,v 1.1 1996/09/30 16:35:05 ws Exp $ R= .. .PATH: $(.CURDIR)/$(R) -RELOC= 4000 -ENTRY= __start -LOADADDR= 4000 +RELOC= 20000 +ENTRY= _entry +LOADADDR= 20000 PROG= boot.mac SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c #CFLAGS+= -DDEBUG -DNETIF_DEBUG -CFLAGS+= -DEXEC_ELF +CFLAGS+= -DEXEC_ELF -DXCOFF_GLUE -DMAC NOMAN= INSTALL_STRIP= MAKEELF= makeelf @@ -19,6 +19,7 @@ OBJCOPY_ARGS= -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment LDFLAGS= -X -Ttext $(RELOC) -e $(ENTRY) -T ${.CURDIR}/ld.script LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep +CLEANFILES= hack-coff $(PROG): $(OBJS) $(LIBS) hack-coff $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o ${.TARGET} @@ -27,6 +28,6 @@ $(PROG): $(OBJS) $(LIBS) hack-coff # ${MAKEELF} $(REAL_VIRT) a.out $(.TARGET) hack-coff: hack-coff.c - ${HOSTCC} -o hack-coff ${.CURDIR}/hack-coff.c + ${HOSTCC} -I${.CURDIR} -o hack-coff ${.CURDIR}/hack-coff.c .include <bsd.prog.mk> diff --git a/sys/arch/powerpc/stand/boot/Makefile b/sys/arch/powerpc/stand/boot/Makefile deleted file mode 100644 index 5329ca5262c..00000000000 --- a/sys/arch/powerpc/stand/boot/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# $OpenBSD: Makefile,v 1.6 1997/05/05 16:49:52 rahnds Exp $ -# $NetBSD: Makefile,v 1.1 1996/09/30 16:35:05 ws Exp $ - -R= .. -.PATH: $(.CURDIR)/$(R) -PROG= boot.ppc -SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c -#CFLAGS+= -DDEBUG -DNETIF_DEBUG -CFLAGS+= -DEXEC_ELF -NOMAN= -INSTALL_STRIP= -MAKEELF= makeelf -BINDIR= /usr/mdec -#OBJS+= note.o -LDFLAGS= -X -N -Ttext $(RELOC) -e $(ENTRY) - -LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep - -$(PROG): $(OBJS) $(LIBS) - $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o ${.TARGET} -# ${MAKEELF} $(REAL_VIRT) a.out $(.TARGET) - -.include <bsd.prog.mk> diff --git a/sys/arch/powerpc/stand/boot/note.s b/sys/arch/powerpc/stand/boot/note.s deleted file mode 100644 index 9d48367bf87..00000000000 --- a/sys/arch/powerpc/stand/boot/note.s +++ /dev/null @@ -1,35 +0,0 @@ -.section ".note" - - ## Note header - these are in target order - - # length of ns.name, including NULL = 8 = strlen("PowerPC") + 1 - # but not including padding - .long 8 - - # Note descriptor size - .long 20 - - # Note type - .long 0x1275 - - # The name of the owner - .asciz "PowerPC" - .balign 4 - - - ## Note descriptor - these are in BE order - - # Real-mode # 0 or -1 (true) - .long 0 - - # real-base - .byte 0xff ; .byte 0xff ; .byte 0xff ; .byte 0xff - # real-size - .byte 0x00 ; .byte 0x00 ; .byte 0x00 ; .byte 0x00 - - # virt-base - .byte 0xff ; .byte 0xff ; .byte 0xff ; .byte 0xff - # virt-size - .byte 0x00 ; .byte 0x00 ; .byte 0x00 ; .byte 0x00 - -.previous diff --git a/sys/arch/powerpc/stand/ofwboot/cache.c b/sys/arch/powerpc/stand/cache.c index c40dead4394..c40dead4394 100644 --- a/sys/arch/powerpc/stand/ofwboot/cache.c +++ b/sys/arch/powerpc/stand/cache.c diff --git a/sys/arch/powerpc/stand/net.c b/sys/arch/powerpc/stand/net.c index dca152abef0..247598e7624 100644 --- a/sys/arch/powerpc/stand/net.c +++ b/sys/arch/powerpc/stand/net.c @@ -1,5 +1,4 @@ -/* $OpenBSD: net.c,v 1.2 1996/12/28 06:31:14 rahnds Exp $ */ -/* $NetBSD: net.c,v 1.1 1996/09/30 16:35:01 ws Exp $ */ +/* $NetBSD: net.c,v 1.1 1997/04/16 20:29:18 thorpej Exp $ */ /* * Copyright (C) 1995 Wolfgang Solfrank. @@ -58,9 +57,9 @@ #include <netinet/if_ether.h> #include <netinet/in_systm.h> -#include "stand.h" -#include "net.h" -#include "netif.h" +#include <lib/libsa/stand.h> +#include <lib/libsa/net.h> +#include <lib/libsa/netif.h> char rootpath[FNAME_SIZE]; diff --git a/sys/arch/powerpc/stand/netif_of.c b/sys/arch/powerpc/stand/netif_of.c index d995a486ac6..71adac09790 100644 --- a/sys/arch/powerpc/stand/netif_of.c +++ b/sys/arch/powerpc/stand/netif_of.c @@ -1,5 +1,4 @@ -/* $OpenBSD: netif_of.c,v 1.2 1996/12/28 06:31:15 rahnds Exp $ */ -/* $NetBSD: netif_of.c,v 1.1 1996/09/30 16:35:02 ws Exp $ */ +/* $NetBSD: netif_of.c,v 1.1 1997/04/16 20:29:19 thorpej Exp $ */ /* * Copyright (C) 1995 Wolfgang Solfrank. @@ -42,8 +41,11 @@ #include <sys/param.h> #include <sys/socket.h> + +#if 0 /* XXX thorpej */ #include <string.h> #include <time.h> +#endif #include <net/if.h> @@ -51,12 +53,12 @@ #include <netinet/if_ether.h> #include <netinet/in_systm.h> -#include "stand.h" -#include "net.h" -#include "netif.h" +#include <lib/libsa/stand.h> +#include <lib/libsa/net.h> +#include <lib/libsa/netif.h> -#include "ofdev.h" -#include "openfirm.h" +#include <powerpc/stand/ofdev.h> +#include <powerpc/stand/openfirm.h> static struct netif netif_of; diff --git a/sys/arch/powerpc/stand/ofdev.c b/sys/arch/powerpc/stand/ofdev.c index 052c084c39d..68416df9910 100644 --- a/sys/arch/powerpc/stand/ofdev.c +++ b/sys/arch/powerpc/stand/ofdev.c @@ -1,5 +1,4 @@ -/* $OpenBSD: ofdev.c,v 1.2 1996/12/28 06:31:17 rahnds Exp $ */ -/* $NetBSD: ofdev.c,v 1.1 1996/09/30 16:35:03 ws Exp $ */ +/* $NetBSD: ofdev.c,v 1.1 1997/04/16 20:29:20 thorpej Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -38,12 +37,12 @@ #include <sys/disklabel.h> #include <netinet/in.h> -#include <stand.h> -#include <ufs.h> -#include <cd9660.h> -#include <nfs.h> +#include <lib/libsa/stand.h> +#include <lib/libsa/ufs.h> +#include <lib/libsa/cd9660.h> +#include <lib/libsa/nfs.h> -#include "ofdev.h" +#include <powerpc/stand/ofdev.h> extern char bootdev[]; @@ -149,13 +148,14 @@ static struct fs_ops file_system_ufs = { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat }; static struct fs_ops file_system_cd9660 = { - cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, cd9660_stat + cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, + cd9660_stat }; static struct fs_ops file_system_nfs = { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat }; -struct fs_ops file_system[2]; +struct fs_ops file_system[3]; int nfsys; static struct of_dev ofdev = { @@ -186,7 +186,7 @@ search_label(devp, off, buf, lp, off0) u_long off0; { size_t read; - struct mbr_partition *p; + struct dos_partition *p; int i; u_long poff; static int recursion; @@ -200,10 +200,11 @@ search_label(devp, off, buf, lp, off0) if (recursion++ <= 1) off0 += off; - for (p = (struct mbr_partition *)(buf + MBRPARTOFF), i = 4; + for (p = (struct dos_partition *)(buf + DOSPARTOFF), i = 4; --i >= 0; p++) { - if (p->mbr_type == MBR_NETBSD) { - poff = get_long(&p->mbr_start) + off0; + if (p->dp_typ == DOSPTYP_OPENBSD || + p->dp_typ == DOSPTYP_NETBSD) { + poff = get_long(&p->dp_start) + off0; if (strategy(devp, F_READ, poff + LABELSECTOR, DEV_BSIZE, buf, &read) == 0 && read == DEV_BSIZE) { @@ -217,8 +218,8 @@ search_label(devp, off, buf, lp, off0) recursion--; return ERDLAB; } - } else if (p->mbr_type == MBR_EXTENDED) { - poff = get_long(&p->mbr_start); + } else if (p->dp_typ == DOSPTYP_EXTEND) { + poff = get_long(&p->dp_start); if (!search_label(devp, poff, buf, lp, off0)) { recursion--; return 0; @@ -270,8 +271,10 @@ devopen(of, name, file) *cp++ = partition; *cp = 0; } +#if 0 if (*buf != '/') strcat(opened_name, "/"); +#endif strcat(opened_name, buf); *file = opened_name + strlen(fname) + 1; if ((handle = OF_finddevice(fname)) == -1) @@ -316,7 +319,8 @@ devopen(of, name, file) of->f_dev = devsw; of->f_devdata = &ofdev; bcopy(&file_system_ufs, file_system, sizeof file_system[0]); - bcopy(&file_system_cd9660, file_system + 1, sizeof file_system[0]); + bcopy(&file_system_cd9660, file_system + 1, + sizeof file_system[0]); nfsys = 2; return 0; } diff --git a/sys/arch/powerpc/stand/ofdev.h b/sys/arch/powerpc/stand/ofdev.h index 64b1a944a3f..2910ac51460 100644 --- a/sys/arch/powerpc/stand/ofdev.h +++ b/sys/arch/powerpc/stand/ofdev.h @@ -1,5 +1,4 @@ -/* $OpenBSD: ofdev.h,v 1.2 1996/12/28 06:09:32 rahnds Exp $ */ -/* $NetBSD: ofdev.h,v 1.1 1996/09/30 16:35:04 ws Exp $ */ +/* $NetBSD: ofdev.h,v 1.1 1997/04/16 20:29:22 thorpej Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -45,7 +44,11 @@ struct of_dev { #define OFDEV_NET 1 #define OFDEV_DISK 2 +#ifdef MAC +#define DEFAULT_KERNEL ":bsd" +#else #define DEFAULT_KERNEL "/bsd" +#endif extern char opened_name[]; extern int floppyboot; diff --git a/sys/arch/powerpc/stand/ofwboot/Makefile b/sys/arch/powerpc/stand/ofwboot/Makefile index 92a5922ef03..7a136782db5 100644 --- a/sys/arch/powerpc/stand/ofwboot/Makefile +++ b/sys/arch/powerpc/stand/ofwboot/Makefile @@ -5,7 +5,7 @@ R=../ PROG= ofwboot SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c cache.c -.PATH: ${S}/arch/powerpc/powerpc +.PATH: ${S}/arch/powerpc/stand SRCS+= ofwmagic.S #CFLAGS+= -DDEBUG -DNETIF_DEBUG NOMAN= @@ -18,7 +18,7 @@ BINDIR= /usr/mdec NEWVERSWHAT= "OpenFirmware Boot" # For now... -RELOC= 20000 +RELOC= 20074 ENTRY= _start @@ -33,8 +33,5 @@ LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep ${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${LD} -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \ ${OBJS} ${LIBS} -# mv ${PROG} ${PROG}.elf -# ${OBJCOPY} --input-target=elf32-powerpc \ -# --output-target=xcoff-powermac ${PROG}.elf ${PROG}.xcf .include <bsd.prog.mk> diff --git a/sys/arch/powerpc/stand/ofwboot/alloc.c b/sys/arch/powerpc/stand/ofwboot/alloc.c deleted file mode 100644 index 23498613f48..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/alloc.c +++ /dev/null @@ -1,217 +0,0 @@ -/* $NetBSD: alloc.c,v 1.1 1997/04/16 20:29:16 thorpej Exp $ */ - -/* - * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * Copyright (c) 1996 - * Matthias Drochner. All rights reserved. - * Copyright (C) 1995, 1996 Wolfgang Solfrank. - * Copyright (C) 1995, 1996 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ - -/* - * Dynamic memory allocator suitable for use with OpenFirmware. - * - * Compile options: - * - * ALLOC_TRACE enable tracing of allocations/deallocations - * - * ALLOC_FIRST_FIT use a first-fit allocation algorithm, rather than - * the default best-fit algorithm. - * - * DEBUG enable debugging sanity checks. - */ - -#include <sys/param.h> -#include <sys/queue.h> - -#include <lib/libsa/stand.h> - -#include <powerpc/stand/ofwboot/openfirm.h> - -/* - * Each block actually has ALIGN(struct ml) + ALIGN(size) bytes allocated - * to it, as follows: - * - * 0 ... (sizeof(struct ml) - 1) - * allocated or unallocated: holds size of user-data part of block. - * - * sizeof(struct ml) ... (ALIGN(sizeof(struct ml)) - 1) - * allocated: unused - * unallocated: depends on packing of struct fl - * - * ALIGN(sizeof(struct ml)) ... (ALIGN(sizeof(struct ml)) + - * ALIGN(data size) - 1) - * allocated: user data - * unallocated: depends on packing of struct fl - * - * 'next' is only used when the block is unallocated (i.e. on the free list). - * However, note that ALIGN(sizeof(struct ml)) + ALIGN(data size) must - * be at least 'sizeof(struct fl)', so that blocks can be used as structures - * when on the free list. - */ - -/* - * Memory lists. - */ -struct ml { - unsigned size; - LIST_ENTRY(ml) list; -}; - -/* XXX - this is from NetBSD */ -#define LIST_HEAD_INITIALIZER(head) { NULL } - -LIST_HEAD(, ml) freelist = LIST_HEAD_INITIALIZER(freelist); -LIST_HEAD(, ml) allocatedlist = LIST_HEAD_INITIALIZER(allocatedlist); - -#define OVERHEAD ALIGN(sizeof (struct ml)) /* shorthand */ - -void * -alloc(size) - unsigned size; -{ - struct ml *f, *bestf; - unsigned bestsize = 0xffffffff; /* greater than any real size */ - char *help; - int failed; - -#ifdef ALLOC_TRACE - printf("alloc(%u)", size); -#endif - - /* - * Account for overhead now, so that we don't get an - * "exact fit" which doesn't have enough space. - */ - size = ALIGN(size) + OVERHEAD; - -#ifdef ALLOC_FIRST_FIT - /* scan freelist */ - for (f = freelist.lh_first; f != NULL && f->size < size; - f = f->list.le_next) - /* noop */ ; - bestf = f; - failed = (bestf == (struct fl *)0); -#else - /* scan freelist */ - f = freelist.lh_first; - while (f != NULL) { - if (f->size >= size) { - if (f->size == size) /* exact match */ - goto found; - - if (f->size < bestsize) { - /* keep best fit */ - bestf = f; - bestsize = f->size; - } - } - f = f->list.le_next; - } - - /* no match in freelist if bestsize unchanged */ - failed = (bestsize == 0xffffffff); -#endif - - if (failed) { /* nothing found */ - /* - * Allocate memory from the OpenFirmware, rounded - * to page size, and record the chunk size. - */ - size = roundup(size, NBPG); - help = OF_claim(0, size, NBPG); - if (help == (char *)-1) - panic("alloc: out of memory"); - - f = (struct ml *)help; - f->size = size; -#ifdef ALLOC_TRACE - printf("=%lx (new chunk size %u)\n", - (u_long)(help + OVERHEAD), f->f_size); -#endif - goto out; - } - - /* we take the best fit */ - f = bestf; - - found: - /* remove from freelist */ - LIST_REMOVE(f, list); - help = (char *)f; -#ifdef ALLOC_TRACE - printf("=%lx (origsize %u)\n", (u_long)(help + OVERHEAD), f->size); -#endif - out: - /* place on allocated list */ - LIST_INSERT_HEAD(&allocatedlist, f, list); - return (help + OVERHEAD); -} - -void -free(ptr, size) - void *ptr; - unsigned size; /* only for consistenct check */ -{ - register struct ml *a = (struct ml *)((char*)ptr - OVERHEAD); - -#ifdef ALLOC_TRACE - printf("free(%lx, %u) (origsize %u)\n", (u_long)ptr, size, a->size); -#endif -#ifdef DEBUG - if (size > a->size) - printf("free %u bytes @%lx, should be <=%u\n", - size, (u_long)ptr, a->size); -#endif - - /* Remove from allocated list, place on freelist. */ - LIST_REMOVE(a, list); - LIST_INSERT_HEAD(&freelist, a, list); -} - -void -freeall() -{ -#ifdef __notyet__ /* Firmware bug ?! */ - struct ml *m; - - /* Release chunks on freelist... */ - while ((m = freelist.lh_first) != NULL) { - LIST_REMOVE(m, list); - OF_release(m, m->size); - } - - /* ...and allocated list. */ - while ((m = allocatedlist.lh_first) != NULL) { - LIST_REMOVE(m, list); - OF_release(m, m->size); - } -#endif /* __notyet__ */ -} diff --git a/sys/arch/powerpc/stand/ofwboot/boot.c b/sys/arch/powerpc/stand/ofwboot/boot.c deleted file mode 100644 index 2da4a5fe93b..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/boot.c +++ /dev/null @@ -1,492 +0,0 @@ -/* $NetBSD: boot.c,v 1.1 1997/04/16 20:29:17 thorpej Exp $ */ - -/* - * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. - * Copyright (C) 1995, 1996 Wolfgang Solfrank. - * Copyright (C) 1995, 1996 TooLs GmbH. - * All rights reserved. - * - * ELF support derived from NetBSD/alpha's boot loader, written - * by Christopher G. Demetriou. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ - -/* - * First try for the boot code - * - * Input syntax is: - * [promdev[{:|,}partition]]/[filename] [flags] - */ - -#define ELFSIZE 32 /* We use 32-bit ELF. */ - -#include <lib/libkern/libkern.h> -#include <lib/libsa/stand.h> - -#include <sys/param.h> -#include <sys/exec.h> -#include <sys/exec_elf.h> -#include <sys/reboot.h> -#include <sys/disklabel.h> - -#include <machine/cpu.h> -/* -#include <machine/machine_type.h> -*/ - -#include <powerpc/stand/ofwboot/ofdev.h> -#include <powerpc/stand/ofwboot/openfirm.h> - -char bootdev[128]; -char bootfile[128]; -int boothowto; -int debug; - -#ifdef POWERPC_BOOT_ELF -int elf_exec __P((int, Elf32_Ehdr *, u_int32_t *, void **)); -#endif - -#ifdef POWERPC_BOOT_AOUT -int aout_exec __P((int, struct exec *, u_int32_t *, void **)); -#endif - -static void -prom2boot(dev) - char *dev; -{ - char *cp, *lp = 0; - int handle; - char devtype[16]; - - for (cp = dev; *cp; cp++) - if (*cp == ':') - lp = cp; - if (!lp) - lp = cp; - *lp = 0; -} - -static void -parseargs(str, howtop) - char *str; - int *howtop; -{ - char *cp; - - /* Allow user to drop back to the PROM. */ - if (strcmp(str, "exit") == 0) - _rtt(); - - *howtop = 0; - for (cp = str; *cp; cp++) - if (*cp == ' ' || *cp == '-') - break; - if (!*cp) - return; - - *cp++ = 0; - while (*cp) { - switch (*cp++) { - case 'a': - *howtop |= RB_ASKNAME; - break; - case 's': - *howtop |= RB_SINGLE; - break; - case 'd': - *howtop |= RB_KDB; - debug = 1; - break; - } - } -} - -static void -chain(entry, args, esym) - void (*entry)(); - char *args; - void *esym; -{ - extern char end[]; - int l, machine_tag; - - freeall(); - - /* - * Stash pointer to end of symbol table after the argument - * strings. - */ - l = strlen(args) + 1; - bcopy(&esym, args + l, sizeof(esym)); - l += sizeof(esym); - -#ifdef __notyet__ - /* - * Tell the kernel we're an OpenFirmware system. - */ - machine_tag = POWERPC_MACHINE_OPENFIRMWARE; - bcopy(&machine_tag, args + l, sizeof(machine_tag)); - l += sizeof(machine_tag); -#endif - - OF_chain((void *)RELOC, end - (char *)RELOC, entry, args, l); - panic("chain"); -} - -int -loadfile(fd, args) - int fd; - char *args; -{ - union { -#ifdef POWERPC_BOOT_AOUT - struct exec aout; -#endif -#ifdef POWERPC_BOOT_ELF - Elf32_Ehdr elf; -#endif - } hdr; - int rval; - u_int32_t entry; - void *esym; - - rval = 1; - esym = NULL; - - /* Load the header. */ - if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) { - printf("read header: %s\n", strerror(errno)); - goto err; - } - - /* Determine file type, load kernel. */ -#ifdef POWERPC_BOOT_AOUT - if (N_BADMAG(hdr.aout) == 0 && N_GETMID(hdr.aout) == MID_POWERPC) { - rval = aout_exec(fd, &hdr.aout, &entry, &esym); - } else -#endif -#ifdef POWERPC_BOOT_ELF - if (IS_ELF(hdr.elf)) { - rval = elf_exec(fd, &hdr.elf, &entry, &esym); - } else -#endif - { - printf("unknown executable format\n"); - } - - if (rval) - goto err; - - printf(" start=0x%x\n", entry); - - close(fd); - - /* XXX this should be replaced w/ a mountroothook. */ - if (floppyboot) { - printf("Please insert root disk and press ENTER "); - getchar(); - printf("\n"); - } - - chain((void *)entry, args, esym); - /* NOTREACHED */ - - err: - close(fd); - return (rval); -} - -#ifdef POWERPC_BOOT_AOUT -int -aout_exec(fd, hdr, entryp, esymp) - int fd; - struct exec *hdr; - u_int32_t *entryp; - void **esymp; -{ - void *addr; - int n, *paddr; - - /* Display the load address (entry point) for a.out. */ - printf("Booting %s @ 0x%lx\n", opened_name, hdr->a_entry); - addr = (void *)(hdr->a_entry); - - /* - * Determine memory needed for kernel and allocate it from - * the firmware. - */ - n = hdr->a_text + hdr->a_data + hdr->a_bss + hdr->a_syms + sizeof(int); - if ((paddr = OF_claim(addr, n, 0)) == (int *)-1) - panic("cannot claim memory"); - - /* Load text. */ - lseek(fd, N_TXTOFF(*hdr), SEEK_SET); - printf("%lu", hdr->a_text); - if (read(fd, paddr, hdr->a_text) != hdr->a_text) { - printf("read text: %s\n", strerror(errno)); - return (1); - } - syncicache((void *)paddr, hdr->a_text); - - /* Load data. */ - printf("+%lu", hdr->a_data); - if (read(fd, (void *)paddr + hdr->a_text, hdr->a_data) != hdr->a_data) { - printf("read data: %s\n", strerror(errno)); - return (1); - } - - /* Zero BSS. */ - printf("+%lu", hdr->a_bss); - bzero((void *)paddr + hdr->a_text + hdr->a_data, hdr->a_bss); - - /* Symbols. */ - *esymp = paddr; - paddr = (int *)((void *)paddr + hdr->a_text + hdr->a_data + hdr->a_bss); - *paddr++ = hdr->a_syms; - if (hdr->a_syms) { - printf(" [%lu", hdr->a_syms); - if (read(fd, paddr, hdr->a_syms) != hdr->a_syms) { - printf("read symbols: %s\n", strerror(errno)); - return (1); - } - paddr = (int *)((void *)paddr + hdr->a_syms); - if (read(fd, &n, sizeof(int)) != sizeof(int)) { - printf("read symbols: %s\n", strerror(errno)); - return (1); - } - if (OF_claim((void *)paddr, n + sizeof(int), 0) == (void *)-1) - panic("cannot claim memory"); - *paddr++ = n; - if (read(fd, paddr, n - sizeof(int)) != n - sizeof(int)) { - printf("read symbols: %s\n", strerror(errno)); - return (1); - } - printf("+%d]", n - sizeof(int)); - *esymp = paddr + (n - sizeof(int)); - } - - *entryp = hdr->a_entry; - return (0); -} -#endif /* POWERPC_BOOT_AOUT */ - -#ifdef POWERPC_BOOT_ELF -int -elf_exec(fd, elf, entryp, esymp) - int fd; - Elf32_Ehdr *elf; - u_int32_t *entryp; - void **esymp; -{ - Elf32_Shdr *shp; - Elf32_Off off; - void *addr; - size_t size; - int i, first = 1; - int n; - - /* - * Don't display load address for ELF; it's encoded in - * each section. - */ - printf("Booting %s\n", opened_name); - - for (i = 0; i < elf->e_phnum; i++) { - Elf32_Phdr phdr; - (void)lseek(fd, elf->e_phoff + sizeof(phdr) * i, SEEK_SET); - if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) { - printf("read phdr: %s\n", strerror(errno)); - return (1); - } - if (phdr.p_type != PT_LOAD || - (phdr.p_flags & (PF_W|PF_X)) == 0) - continue; - - /* Read in segment. */ - printf("%s%lu@0x%lx", first ? "" : "+", phdr.p_filesz, - (u_long)phdr.p_vaddr); - (void)lseek(fd, phdr.p_offset, SEEK_SET); - if (OF_claim((void *)phdr.p_vaddr, phdr.p_memsz, 0) == - (void *)-1) - panic("cannot claim memory"); - if (read(fd, (void *)phdr.p_vaddr, phdr.p_filesz) != - phdr.p_filesz) { - printf("read segment: %s\n", strerror(errno)); - return (1); - } - syncicache((void *)phdr.p_vaddr, phdr.p_filesz); - - /* Zero BSS. */ - if (phdr.p_filesz < phdr.p_memsz) { - printf("+%lu@0x%lx", phdr.p_memsz - phdr.p_filesz, - (u_long)(phdr.p_vaddr + phdr.p_filesz)); - bzero(phdr.p_vaddr + phdr.p_filesz, - phdr.p_memsz - phdr.p_filesz); - } - first = 0; - } - - printf(" \n"); - -#if 0 /* I want to rethink this... --thorpej@netbsd.org */ - /* - * Compute the size of the symbol table. - */ - size = sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); - shp = addr = alloc(elf->e_shnum * sizeof(Elf32_Shdr)); - (void)lseek(fd, elf->e_shoff, SEEK_SET); - if (read(fd, addr, elf->e_shnum * sizeof(Elf32_Shdr)) != - elf->e_shnum * sizeof(Elf32_Shdr)) { - printf("read section headers: %s\n", strerror(errno)); - return (1); - } - for (i = 0; i < elf->e_shnum; i++, shp++) { - if (shp->sh_type == Elf32_sht_null) - continue; - if (shp->sh_type != Elf32_sht_symtab - && shp->sh_type != Elf32_sht_strtab) { - shp->sh_offset = 0; - shp->sh_type = Elf32_sht_nobits; - continue; - } - size += shp->sh_size; - } - shp = addr; - - /* - * Reserve memory for the symbols. - */ - if ((addr = OF_claim(0, size, NBPG)) == (void *)-1) - panic("no space for symbol table"); - - /* - * Copy the headers. - */ - elf->e_phoff = 0; - elf->e_shoff = sizeof(Elf32_Ehdr); - elf->e_phentsize = 0; - elf->e_phnum = 0; - bcopy(elf, addr, sizeof(Elf32_Ehdr)); - bcopy(shp, addr + sizeof(Elf32_Ehdr), elf->e_shnum * sizeof(Elf32_Shdr)); - free(shp, elf->e_shnum * sizeof(Elf32_Shdr)); - *ssymp = addr; - - /* - * Now load the symbol sections themselves. - */ - shp = addr + sizeof(Elf32_Ehdr); - addr += sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); - off = sizeof(Elf32_Ehdr) + (elf->e_shnum * sizeof(Elf32_Shdr)); - for (first = 1, i = 0; i < elf->e_shnum; i++, shp++) { - if (shp->sh_type == Elf32_sht_symtab - || shp->sh_type == Elf32_sht_strtab) { - if (first) - printf("symbols @ 0x%lx ", (u_long)addr); - printf("%s%d", first ? "" : "+", shp->sh_size); - (void)lseek(fd, shp->sh_offset, SEEK_SET); - if (read(fd, addr, shp->sh_size) != shp->sh_size) { - printf("read symbols: %s\n", strerror(errno)); - return (1); - } - addr += shp->sh_size; - shp->sh_offset = off; - off += shp->sh_size; - first = 0; - } - } - *esymp = addr; -#endif /* 0 */ - - *entryp = elf->e_entry; - return (0); -} -#endif /* POWERPC_BOOT_ELF */ - -void -main() -{ - int chosen; - char bootline[512]; /* Should check size? */ - char *cp; - int fd; - - printf("\n>> OpenBSD/powerpc Boot\n"); - - /* - * Get the boot arguments from Openfirmware - */ - if ((chosen = OF_finddevice("/chosen")) == -1 - || OF_getprop(chosen, "bootpath", bootdev, sizeof bootdev) < 0 - || OF_getprop(chosen, "bootargs", bootline, sizeof bootline) < 0) { - printf("Invalid Openfirmware environment\n"); - exit(); - } - prom2boot(bootdev); - parseargs(bootline, &boothowto); - for (;;) { - if (boothowto & RB_ASKNAME) { - printf("Boot: "); - gets(bootline); - parseargs(bootline, &boothowto); - } - if ((fd = open(bootline, 0)) >= 0) - break; - if (errno) - printf("open %s: %s\n", opened_name, strerror(errno)); - boothowto |= RB_ASKNAME; - } -#ifdef __notyet__ - OF_setprop(chosen, "bootpath", opened_name, strlen(opened_name) + 1); - cp = bootline; -#else - strcpy(bootline, opened_name); - cp = bootline + strlen(bootline); - *cp++ = ' '; -#endif - *cp = '-'; - if (boothowto & RB_ASKNAME) - *++cp = 'a'; - if (boothowto & RB_SINGLE) - *++cp = 's'; - if (boothowto & RB_KDB) - *++cp = 'd'; - if (*cp == '-') -#ifdef __notyet__ - *cp = 0; -#else - *--cp = 0; -#endif - else - *++cp = 0; -#ifdef __notyet__ - OF_setprop(chosen, "bootargs", bootline, strlen(bootline) + 1); -#endif - /* XXX void, for now */ - (void)loadfile(fd, bootline); - - _rtt(); -} diff --git a/sys/arch/powerpc/stand/ofwboot/net.c b/sys/arch/powerpc/stand/ofwboot/net.c deleted file mode 100644 index 247598e7624..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/net.c +++ /dev/null @@ -1,152 +0,0 @@ -/* $NetBSD: net.c,v 1.1 1997/04/16 20:29:18 thorpej Exp $ */ - -/* - * Copyright (C) 1995 Wolfgang Solfrank. - * Copyright (C) 1995 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ - -/* - * This module implements a "raw device" interface suitable for - * use by the stand-alone I/O library NFS code. This interface - * does not support any "block" access, and exists only for the - * purpose of initializing the network interface, getting boot - * parameters, and performing the NFS mount. - * - * At open time, this does: - * - * find interface - netif_open() - * BOOTP - bootp() - * RPC/mountd - nfs_mount() - * - * The root file handle from mountd is saved in a global - * for use by the NFS open code (NFS/lookup). - * - * Note: this is based in part on sys/arch/sparc/stand/net.c - */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <netinet/in_systm.h> - -#include <lib/libsa/stand.h> -#include <lib/libsa/net.h> -#include <lib/libsa/netif.h> - -char rootpath[FNAME_SIZE]; - -static int netdev_sock = -1; -static int open_count; - -/* - * Called by devopen after it sets f->f_dev to our devsw entry. - * This opens the low-level device and sets f->f_devdata. - */ -int -net_open(op) - struct of_dev *op; -{ - int error = 0; - - /* - * On first open, do netif open, mount, etc. - */ - if (open_count == 0) { - /* Find network interface. */ - if ((netdev_sock = netif_open(op)) < 0) { - error = errno; - goto bad; - } - if ((error = net_mountroot()) != 0) - goto bad; - } - open_count++; -bad: - if (netdev_sock >= 0 && open_count == 0) { - netif_close(netdev_sock); - netdev_sock = -1; - } - return error; -} - -int -net_close(op) - struct of_dev *op; -{ - /* - * On last close, do netif close, etc. - */ - if (open_count > 0) - if (--open_count == 0) { - netif_close(netdev_sock); - netdev_sock = -1; - } -} - -int -net_mountroot() -{ - -#ifdef DEBUG - printf("net_mountroot\n"); -#endif - - /* - * Get info for NFS boot: our IP address, out hostname, - * server IP address, and our root path on the server. - * We use BOOTP (RFC951, RFC1532) exclusively as mandated - * by PowerPC Reference Platform Specification I.4.2 - */ - - bootp(netdev_sock); - - if (myip.s_addr == 0) - return ETIMEDOUT; - - printf("Using IP address: %s\n", inet_ntoa(myip)); - -#ifdef DEBUG - printf("myip: %s (%s)", hostname, inet_ntoa(myip)); - if (gateip.s_addr) - printf(", gateip: %s", inet_ntoa(gateip)); - if (netmask) - printf(", netmask: %s", intoa(netmask)); - printf("\n"); -#endif - printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath); - - /* - * Get the NFS file handle (mount). - */ - if (nfs_mount(netdev_sock, rootip, rootpath) < 0) - return errno; - return 0; -} diff --git a/sys/arch/powerpc/stand/ofwboot/netif_of.c b/sys/arch/powerpc/stand/ofwboot/netif_of.c deleted file mode 100644 index 27df48e0eb0..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/netif_of.c +++ /dev/null @@ -1,244 +0,0 @@ -/* $NetBSD: netif_of.c,v 1.1 1997/04/16 20:29:19 thorpej Exp $ */ - -/* - * Copyright (C) 1995 Wolfgang Solfrank. - * Copyright (C) 1995 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ - -/* - * Open Firmware does most of the job for interfacing to the hardware, - * so it is easiest to just replace the netif module with - * this adaptation to the PROM network interface. - * - * Note: this is based in part on sys/arch/sparc/stand/netif_sun.c - */ - -#include <sys/param.h> -#include <sys/socket.h> - -#if 0 /* XXX thorpej */ -#include <string.h> -#include <time.h> -#endif - -#include <net/if.h> - -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <netinet/in_systm.h> - -#include <lib/libsa/stand.h> -#include <lib/libsa/net.h> -#include <lib/libsa/netif.h> - -#include <powerpc/stand/ofwboot/ofdev.h> -#include <powerpc/stand/ofwboot/openfirm.h> - -static struct netif netif_of; - -struct iodesc sockets[SOPEN_MAX]; - -struct iodesc * -socktodesc(sock) - int sock; -{ - if (sock != 0) - return NULL; - return sockets; -} - -int -netif_open(machdep_hint) - void *machdep_hint; -{ - struct of_dev *op = machdep_hint; - struct iodesc *io; - int fd, error; - char addr[32]; - -#ifdef NETIF_DEBUG - printf("netif_open..."); -#endif - /* find a free socket */ - io = sockets; - if (io->io_netif) { -#ifdef NETIF_DEBUG - printf("device busy\n"); -#endif - errno = ENFILE; - return -1; - } - bzero(io, sizeof *io); - - netif_of.nif_devdata = op; - io->io_netif = &netif_of; - - /* Put our ethernet address in io->myea */ - OF_getprop(OF_instance_to_package(op->handle), - "mac-address", io->myea, sizeof io->myea); - -#ifdef NETIF_DEBUG - printf("OK\n"); -#endif - return 0; -} - -int -netif_close(fd) - int fd; -{ - struct iodesc *io; - struct netif *ni; - -#ifdef NETIF_DEBUG - printf("netif_close(%x)...", fd); -#endif - if (fd != 0) { -#ifdef NETIF_DEBUG - printf("EBADF\n"); -#endif - errno = EBADF; - return -1; - } - - io = &sockets[fd]; - ni = io->io_netif; - if (ni != NULL) { - ni->nif_devdata = NULL; - io->io_netif = NULL; - } -#ifdef NETIF_DEBUG - printf("OK\n"); -#endif - return 0; -} - -/* - * Send a packet. The ether header is already there. - * Return the length sent (or -1 on error). - */ -ssize_t -netif_put(desc, pkt, len) - struct iodesc *desc; - void *pkt; - size_t len; -{ - struct of_dev *op; - ssize_t rv; - size_t sendlen; - - op = desc->io_netif->nif_devdata; - -#ifdef NETIF_DEBUG - { - struct ether_header *eh; - - printf("netif_put: desc=0x%x pkt=0x%x len=%d\n", - desc, pkt, len); - eh = pkt; - printf("dst: %s ", ether_sprintf(eh->ether_dhost)); - printf("src: %s ", ether_sprintf(eh->ether_shost)); - printf("type: 0x%x\n", eh->ether_type & 0xFFFF); - } -#endif - - sendlen = len; - if (sendlen < 60) { - sendlen = 60; -#ifdef NETIF_DEBUG - printf("netif_put: length padded to %d\n", sendlen); -#endif - } - - rv = OF_write(op->handle, pkt, sendlen); - -#ifdef NETIF_DEBUG - printf("netif_put: xmit returned %d\n", rv); -#endif - - return rv; -} - -/* - * Receive a packet, including the ether header. - * Return the total length received (or -1 on error). - */ -ssize_t -netif_get(desc, pkt, maxlen, timo) - struct iodesc *desc; - void *pkt; - size_t maxlen; - time_t timo; -{ - struct of_dev *op; - int tick0, tmo_ms; - int len; - - op = desc->io_netif->nif_devdata; - -#ifdef NETIF_DEBUG - printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n", - pkt, maxlen, timo); -#endif - - tmo_ms = timo * 1000; - tick0 = OF_milliseconds(); - - do { - len = OF_read(op->handle, pkt, maxlen); - } while ((len == -2) && ((OF_milliseconds() - tick0) < tmo_ms)); - -#ifdef NETIF_DEBUG - printf("netif_get: received len=%d\n", len); -#endif - - if (len < 12) - return -1; - -#ifdef NETIF_DEBUG - { - struct ether_header *eh = pkt; - - printf("dst: %s ", ether_sprintf(eh->ether_dhost)); - printf("src: %s ", ether_sprintf(eh->ether_shost)); - printf("type: 0x%x\n", eh->ether_type & 0xFFFF); - } -#endif - - return len; -} - -/* - * Shouldn't really be here, but is used solely for networking, so... - */ -time_t -getsecs() -{ - return OF_milliseconds() / 1000; -} diff --git a/sys/arch/powerpc/stand/ofwboot/ofdev.c b/sys/arch/powerpc/stand/ofwboot/ofdev.c deleted file mode 100644 index 17ad77692db..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/ofdev.c +++ /dev/null @@ -1,340 +0,0 @@ -/* $NetBSD: ofdev.c,v 1.1 1997/04/16 20:29:20 thorpej Exp $ */ - -/* - * Copyright (C) 1995, 1996 Wolfgang Solfrank. - * Copyright (C) 1995, 1996 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ -/* - * Device I/O routines using Open Firmware - */ -#include <sys/param.h> -#include <sys/disklabel.h> -#include <netinet/in.h> - -#include <lib/libsa/stand.h> -#include <lib/libsa/ufs.h> -#include <lib/libsa/cd9660.h> -#include <lib/libsa/nfs.h> - -#include <powerpc/stand/ofwboot/ofdev.h> - -extern char bootdev[]; - -static char * -filename(str, ppart) - char *str; - char *ppart; -{ - char *cp, *lp; - char savec; - int dhandle; - char devtype[16]; - - lp = str; - devtype[0] = 0; - *ppart = 0; - for (cp = str; *cp; lp = cp) { - /* For each component of the path name... */ - while (*++cp && *cp != '/'); - savec = *cp; - *cp = 0; - /* ...look whether there is a device with this name */ - dhandle = OF_finddevice(str); - *cp = savec; - if (dhandle == -1) { - /* if not, lp is the delimiter between device and path */ - /* if the last component was a block device... */ - if (!strcmp(devtype, "block")) { - /* search for arguments */ - for (cp = lp; - --cp >= str && *cp != '/' && *cp != ':';); - if (cp >= str && *cp == ':') { - /* found arguments, make firmware ignore them */ - *cp = 0; - for (cp = lp; *--cp && *cp != ',';); - if (*++cp >= 'a' && *cp <= 'a' + MAXPARTITIONS) - *ppart = *cp; - } - } - return lp; - } else if (OF_getprop(dhandle, "device_type", devtype, sizeof devtype) < 0) - devtype[0] = 0; - } - return 0; -} - -static int -strategy(devdata, rw, blk, size, buf, rsize) - void *devdata; - int rw; - daddr_t blk; - size_t size; - void *buf; - size_t *rsize; -{ - struct of_dev *dev = devdata; - u_quad_t pos; - int n; - - if (rw != F_READ) - return EPERM; - if (dev->type != OFDEV_DISK) - panic("strategy"); - - pos = (u_quad_t)(blk + dev->partoff) * dev->bsize; - - for (;;) { - if (OF_seek(dev->handle, pos) < 0) - break; - n = OF_read(dev->handle, buf, size); - if (n == -2) - continue; - if (n < 0) - break; - *rsize = n; - return 0; - } - return EIO; -} - -static int -devclose(of) - struct open_file *of; -{ - struct of_dev *op = of->f_devdata; - - if (op->type == OFDEV_NET) - net_close(op); - OF_close(op->handle); - op->handle = -1; -} - -static struct devsw devsw[1] = { - "OpenFirmware", - strategy, - (int (*)__P((struct open_file *, ...)))nodev, - devclose, - noioctl -}; -int ndevs = sizeof devsw / sizeof devsw[0]; - -static struct fs_ops file_system_ufs = { - ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat -}; -static struct fs_ops file_system_cd9660 = { - cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, - cd9660_stat -}; -static struct fs_ops file_system_nfs = { - nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat -}; - -struct fs_ops file_system[3]; -int nfsys; - -static struct of_dev ofdev = { - -1, -}; - -char opened_name[256]; -int floppyboot; - -static u_long -get_long(p) - const void *p; -{ - const unsigned char *cp = p; - - return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24); -} - -/* - * Find a valid disklabel. - */ -static int -search_label(devp, off, buf, lp, off0) - struct of_dev *devp; - u_long off; - char *buf; - struct disklabel *lp; - u_long off0; -{ - size_t read; - struct dos_partition *p; - int i; - u_long poff; - static int recursion; - - if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read) - || read != DEV_BSIZE) - return ERDLAB; - - if (buf[510] != 0x55 || buf[511] != 0xaa) - return ERDLAB; - - if (recursion++ <= 1) - off0 += off; - for (p = (struct dos_partition *)(buf + DOSPARTOFF), i = 4; - --i >= 0; p++) { - if (p->dp_typ == DOSPTYP_OPENBSD || - p->dp_typ == DOSPTYP_NETBSD) { - poff = get_long(&p->dp_start) + off0; - if (strategy(devp, F_READ, poff + LABELSECTOR, - DEV_BSIZE, buf, &read) == 0 - && read == DEV_BSIZE) { - if (!getdisklabel(buf, lp)) { - recursion--; - return 0; - } - } - if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read) - || read != DEV_BSIZE) { - recursion--; - return ERDLAB; - } - } else if (p->dp_typ == DOSPTYP_EXTEND) { - poff = get_long(&p->dp_start); - if (!search_label(devp, poff, buf, lp, off0)) { - recursion--; - return 0; - } - if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read) - || read != DEV_BSIZE) { - recursion--; - return ERDLAB; - } - } - } - recursion--; - return ERDLAB; -} - -int -devopen(of, name, file) - struct open_file *of; - const char *name; - char **file; -{ - char *cp; - char partition; - char fname[256]; - char buf[DEV_BSIZE]; - struct disklabel label; - int handle, part; - size_t read; - int error = 0; - - if (ofdev.handle != -1) - panic("devopen"); - if (of->f_flags != F_READ) - return EPERM; - strcpy(fname, name); - cp = filename(fname, &partition); - if (cp) { - strcpy(buf, cp); - *cp = 0; - } - if (!cp || !*buf) - strcpy(buf, DEFAULT_KERNEL); - if (!*fname) - strcpy(fname, bootdev); - strcpy(opened_name, fname); - if (partition) { - cp = opened_name + strlen(opened_name); - *cp++ = ':'; - *cp++ = partition; - *cp = 0; - } - if (*buf != '/') - strcat(opened_name, "/"); - strcat(opened_name, buf); - *file = opened_name + strlen(fname) + 1; - if ((handle = OF_finddevice(fname)) == -1) - return ENOENT; - if (OF_getprop(handle, "name", buf, sizeof buf) < 0) - return ENXIO; - floppyboot = !strcmp(buf, "floppy"); - if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0) - return ENXIO; - if (!strcmp(buf, "block")) - /* For block devices, indicate raw partition (:0 in OpenFirmware) */ - strcat(fname, ":0"); - if ((handle = OF_open(fname)) == -1) - return ENXIO; - bzero(&ofdev, sizeof ofdev); - ofdev.handle = handle; - if (!strcmp(buf, "block")) { - ofdev.type = OFDEV_DISK; - ofdev.bsize = DEV_BSIZE; - /* First try to find a disklabel without MBR partitions */ - if (strategy(&ofdev, F_READ, - LABELSECTOR, DEV_BSIZE, buf, &read) != 0 - || read != DEV_BSIZE - || getdisklabel(buf, &label)) { - /* Else try MBR partitions */ - error = search_label(&ofdev, 0, buf, &label, 0); - if (error && error != ERDLAB) - goto bad; - } - - if (error == ERDLAB) { - if (partition) - /* User specified a parititon, but there is none */ - goto bad; - /* No, label, just use complete disk */ - ofdev.partoff = 0; - } else { - part = partition ? partition - 'a' : 0; - ofdev.partoff = label.d_partitions[part].p_offset; - } - - of->f_dev = devsw; - of->f_devdata = &ofdev; - bcopy(&file_system_ufs, file_system, sizeof file_system[0]); - bcopy(&file_system_cd9660, file_system + 1, - sizeof file_system[0]); - nfsys = 2; - return 0; - } - if (!strcmp(buf, "network")) { - ofdev.type = OFDEV_NET; - of->f_dev = devsw; - of->f_devdata = &ofdev; - bcopy(&file_system_nfs, file_system, sizeof file_system[0]); - nfsys = 1; - if (error = net_open(&ofdev)) - goto bad; - return 0; - } - error = EFTYPE; -bad: - OF_close(handle); - ofdev.handle = -1; - return error; -} diff --git a/sys/arch/powerpc/stand/ofwboot/ofdev.h b/sys/arch/powerpc/stand/ofwboot/ofdev.h deleted file mode 100644 index 63349eaad03..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/ofdev.h +++ /dev/null @@ -1,52 +0,0 @@ -/* $NetBSD: ofdev.h,v 1.1 1997/04/16 20:29:22 thorpej Exp $ */ - -/* - * Copyright (C) 1995, 1996 Wolfgang Solfrank. - * Copyright (C) 1995, 1996 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ -#ifndef _STAND_DEV_H_ -#define _STAND_DEV_H_ - -struct of_dev { - int handle; - int type; - u_long partoff; - int bsize; -}; - -/* Known types: */ -#define OFDEV_NET 1 -#define OFDEV_DISK 2 - -#define DEFAULT_KERNEL "/bsd" - -extern char opened_name[]; -extern int floppyboot; - -#endif diff --git a/sys/arch/powerpc/stand/ofwboot/openfirm.h b/sys/arch/powerpc/stand/ofwboot/openfirm.h deleted file mode 100644 index 3bbcd737378..00000000000 --- a/sys/arch/powerpc/stand/ofwboot/openfirm.h +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: openfirm.h,v 1.1 1997/04/16 20:29:23 thorpej Exp $ */ - -/* - * Copyright (C) 1995, 1996 Wolfgang Solfrank. - * Copyright (C) 1995, 1996 TooLs GmbH. - * All rights reserved. - * - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. - */ -/* - * Prototypes for Openfirmware Interface Routines - */ - -#include <sys/cdefs.h> -#include <sys/types.h> - -int OF_finddevice __P((char *name)); -int OF_instance_to_package __P((int ihandle)); -int OF_getprop __P((int handle, char *prop, void *buf, int buflen)); -#ifdef __notyet__ -int OF_setprop __P((int handle, char *prop, void *buf, int len)); -#endif -int OF_open __P((char *dname)); -void OF_close __P((int handle)); -int OF_write __P((int handle, void *addr, int len)); -int OF_read __P((int handle, void *addr, int len)); -int OF_seek __P((int handle, u_quad_t pos)); -void *OF_claim __P((void *virt, u_int size, u_int align)); -void OF_release __P((void *virt, u_int size)); -int OF_milliseconds __P((void)); -void OF_chain __P((void *addr, u_int size, void (*entry)(), void *parm, u_int parmlen)); - diff --git a/sys/arch/powerpc/stand/ofwboot/ofwmagic.S b/sys/arch/powerpc/stand/ofwmagic.S index 4851e50eb99..4851e50eb99 100644 --- a/sys/arch/powerpc/stand/ofwboot/ofwmagic.S +++ b/sys/arch/powerpc/stand/ofwmagic.S diff --git a/sys/arch/powerpc/stand/openfirm.h b/sys/arch/powerpc/stand/openfirm.h index 781519670c2..3bbcd737378 100644 --- a/sys/arch/powerpc/stand/openfirm.h +++ b/sys/arch/powerpc/stand/openfirm.h @@ -1,5 +1,4 @@ -/* $OpenBSD: openfirm.h,v 1.2 1996/12/28 06:31:19 rahnds Exp $ */ -/* $NetBSD: openfirm.h,v 1.1 1996/09/30 16:35:04 ws Exp $ */ +/* $NetBSD: openfirm.h,v 1.1 1997/04/16 20:29:23 thorpej Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. |