Index: head/sys/boot/ofw/common/main.c =================================================================== --- head/sys/boot/ofw/common/main.c (revision 84616) +++ head/sys/boot/ofw/common/main.c (revision 84617) @@ -1,202 +1,195 @@ /*- * Copyright (c) 2000 Benno Rice * Copyright (c) 2000 Stephane Potvin * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include "openfirm.h" #include "libofw.h" #include "bootstrap.h" struct ofw_devdesc currdev; /* our current device */ struct arch_switch archsw; /* MI/MD interface boundary */ extern char end[]; extern char bootprog_name[]; extern char bootprog_rev[]; extern char bootprog_date[]; extern char bootprog_maker[]; -struct ofw_reg -{ - uint32_t base; - uint32_t size; -}; +phandle_t chosen; +#define HEAP_SIZE 0x40000 + void init_heap(void) { - ihandle_t meminstance; - phandle_t chosen, memory; - struct ofw_reg available; - void * aligned_end; + void *base; - chosen = OF_finddevice("/chosen"); - OF_getprop(chosen, "memory", &meminstance, sizeof(meminstance)); - memory = OF_instance_to_package(meminstance); - OF_getprop(memory, "available", &available, sizeof(available)); - printf("available.base = 0x%08x\n", available.base); - printf("available.size = 0x%08x\n", available.size); - - if (OF_claim((void *)available.base, 0x00040000, 0) == - (void *) 0xffffffff) { + if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) { printf("Heap memory claim failed!\n"); OF_enter(); } - aligned_end = (void *)(((int)end + sizeof(int) - 1) & - ~(sizeof(int) - 1)); - printf("end = 0x%08x, aligned_end = 0x%08x\n", (uint32_t)end, - (uint32_t)aligned_end); - setheap((void *)aligned_end, (void *)(available.base + available.size)); + setheap(base, base + (HEAP_SIZE / sizeof(base))); } uint32_t memsize(void) { ihandle_t meminstance; - phandle_t chosen, memory; + phandle_t memory; struct ofw_reg reg; - chosen = OF_finddevice("/chosen"); OF_getprop(chosen, "memory", &meminstance, sizeof(meminstance)); memory = OF_instance_to_package(meminstance); OF_getprop(memory, "reg", ®, sizeof(reg)); return (reg.size); } int main(int (*openfirm)(void *)) { int i; - phandle_t chosen; char bootpath[64]; char *ch; /* * Initalise the OpenFirmware routines by giving them the entry point. */ OF_init(openfirm); + chosen = OF_finddevice("/chosen"); + /* * Set up console. */ cons_probe(); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ init_heap(); /* * Initialise the block cache */ bcache_init(32, 512); /* 16k XXX tune this */ /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); printf("Memory: %dKB\n", memsize() / 1024); - chosen = OF_finddevice("/chosen"); OF_getprop(chosen, "bootpath", bootpath, 64); ch = index(bootpath, ':'); *ch = '\0'; printf("Booted from: %s\n", bootpath); printf("\n"); switch (ofw_devicetype(bootpath)) { case DEVT_DISK: currdev.d_dev = &ofwdisk; currdev.d_type = DEVT_DISK; strncpy(currdev.d_kind.ofwdisk.path, bootpath, 64); currdev.d_kind.ofwdisk.unit = ofwd_getunit(bootpath); if (currdev.d_kind.ofwdisk.unit == -1) { printf("Could not locate boot device.\n"); OF_exit(); } break; case DEVT_NET: currdev.d_dev = &netdev; currdev.d_type = DEVT_NET; strncpy(currdev.d_kind.netif.path, bootpath, 64); /* XXX Only works when we only look for one net device */ currdev.d_kind.netif.unit = 0; break; case DEVT_NONE: default: printf("\n"); printf("Could not establish type of boot device.\n"); OF_exit(); /* NOTREACHED */ break; } env_setenv("currdev", EV_VOLATILE, ofw_fmtdev(&currdev), ofw_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, ofw_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ archsw.arch_getdev = ofw_getdev; archsw.arch_copyin = ofw_copyin; archsw.arch_copyout = ofw_copyout; archsw.arch_readin = ofw_readin; + archsw.arch_autoload = ofw_autoload; interact(); /* doesn't return */ OF_exit(); return 0; } COMMAND_SET(halt, "halt", "halt the system", command_halt); static int command_halt(int argc, char *argv[]) { OF_exit(); + return (CMD_OK); +} + +COMMAND_SET(memmap, "memmap", "print memory map", command_memmap); + +int +command_memmap(int argc, char **argv) +{ + + ofw_memmap(); return (CMD_OK); } Index: head/sys/boot/ofw/libofw/Makefile =================================================================== --- head/sys/boot/ofw/libofw/Makefile (revision 84616) +++ head/sys/boot/ofw/libofw/Makefile (revision 84617) @@ -1,33 +1,34 @@ # $FreeBSD$ LIB= ofw NOPIC= true NOPROFILE= true INTERNALLIB= true INTERNALSTATICLIB= true -SRCS= devicename.c ofw_copy.c ofw_module.c ofw_disk.c ofw_net.c \ - ofw_console.c ofw_time.c ofw_devsearch.c ofw_reboot.c openfirm.c +SRCS= devicename.c elf_freebsd.c ofw_console.c ofw_copy.c ofw_devsearch.c \ + ofw_disk.c ofw_memory.c ofw_module.c ofw_net.c ofw_reboot.c \ + ofw_time.c openfirm.c CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ # Pick up the bootstrap header for some interface items CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I. .if ${MACHINE_ARCH} == "powerpc" CFLAGS+= -msoft-float .endif .ifdef(BOOT_DISK_DEBUG) # Make the disk code more talkative CFLAGS+= -DDISK_DEBUG .endif machine: ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine CLEANFILES+= machine .include beforedepend ${OBJS}: machine Index: head/sys/boot/ofw/libofw/libofw.h =================================================================== --- head/sys/boot/ofw/libofw/libofw.h (revision 84616) +++ head/sys/boot/ofw/libofw/libofw.h (revision 84617) @@ -1,87 +1,105 @@ /* * Copyright (C) 2000 Benno Rice. * 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. * * THIS SOFTWARE IS PROVIDED BY Benno Rice ``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. * * $FreeBSD$ */ /* Note: Must match the 'struct devdesc' in bootstrap.h */ struct ofw_devdesc { struct devsw *d_dev; int d_type; union { struct { int unit; char path[64]; int partition; int slice; int bsize; } ofwdisk; struct { int unit; char path[64]; void *dmabuf; } netif; } d_kind; /* * Keeping this around so I know what came from the NetBSD stuff. * I've made a wild guess as to what goes where, but I have no idea if it's * right. * * u_long partoff; * int bsize; * void *dmabuf; */ }; #define MAXDEV 31 /* Maximum number of devices. */ /* Known types. Use the same as alpha for consistancy. */ #define DEVT_NONE 0 #define DEVT_DISK 1 #define DEVT_NET 2 extern int ofw_getdev(void **vdev, const char *devspec, const char **path); extern char *ofw_fmtdev(void *vdev); extern int ofw_setcurrdev(struct env_var *ev, int flags, void *value); extern struct devsw ofwdisk; extern struct netif_driver ofwnet; int ofwd_getunit(const char *); int ofwn_getunit(const char *); ssize_t ofw_copyin(const void *src, vm_offset_t dest, const size_t len); ssize_t ofw_copyout(const vm_offset_t src, void *dest, const size_t len); ssize_t ofw_readin(const int fd, vm_offset_t dest, const size_t len); void ofw_devsearch_init(void); int ofw_devsearch(const char *, char *); int ofw_devicetype(char *); extern int ofw_boot(void); extern int ofw_autoload(void); +void ofw_memmap(void); +void *ofw_alloc_heap(unsigned int); +void ofw_release_heap(void); + +struct preloaded_file; +struct file_format; + +int ofw_elf_loadfile(char *, vm_offset_t, struct preloaded_file **); +int ofw_elf_exec(struct preloaded_file *); + +extern struct file_format ofw_elf; + extern void reboot(void); extern int main(int (*openfirm)(void *)); + +struct ofw_reg +{ + uint32_t base; + uint32_t size; +}; Index: head/sys/boot/ofw/libofw/ofw_copy.c =================================================================== --- head/sys/boot/ofw/libofw/ofw_copy.c (revision 84616) +++ head/sys/boot/ofw/libofw/ofw_copy.c (revision 84617) @@ -1,57 +1,84 @@ /*- * Copyright (c) 1998 Michael Smith * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ /* * MD primitives supporting placement of module data * * XXX should check load address/size against memory top. */ #include #include "libofw.h" +#define READIN_BUF (4 * 1024) + ssize_t ofw_copyin(const void *src, vm_offset_t dest, const size_t len) { bcopy(src, (void *)dest, len); return(len); } ssize_t ofw_copyout(const vm_offset_t src, void *dest, const size_t len) { bcopy((void *)src, dest, len); return(len); } ssize_t ofw_readin(const int fd, vm_offset_t dest, const size_t len) { - return(read(fd, (void *) dest, len)); -} + void *buf; + size_t resid, chunk, get; + ssize_t got; + vm_offset_t p; - + p = dest; + + chunk = min(READIN_BUF, len); + buf = malloc(chunk); + if (buf == NULL) { + printf("ofw_readin: buf malloc failed\n"); + return(0); + } + + for (resid = len; resid > 0; resid -= got, p += got) { + get = min(chunk, resid); + got = read(fd, buf, get); + + if (got <= 0) { + printf("ofw_readin: read failed\n"); + break; + } + + bcopy(buf, (void *)p, got); + } + + free(buf); + return(len - resid); +} Index: head/sys/boot/ofw/libofw/ofw_net.c =================================================================== --- head/sys/boot/ofw/libofw/ofw_net.c (revision 84616) +++ head/sys/boot/ofw/libofw/ofw_net.c (revision 84617) @@ -1,251 +1,253 @@ /* - * Copyright (c) 2000 Benno Rice + * Copyright (c) 2000-2001 Benno Rice * 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. * * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include "openfirm.h" static int ofwn_probe(struct netif *, void *); static int ofwn_match(struct netif *, void *); static void ofwn_init(struct iodesc *, void *); -static int ofwn_get(struct iodesc *, void *, int, time_t); -static int ofwn_put(struct iodesc *, void *, int); +static int ofwn_get(struct iodesc *, void *, size_t, time_t); +static int ofwn_put(struct iodesc *, void *, size_t); static void ofwn_end(struct netif *); extern struct netif_stats ofwn_stats[]; struct netif_dif ofwn_ifs[] = { /* dif_unit dif_nsel dif_stats dif_private */ { 0, 1, &ofwn_stats[0], 0, }, }; struct netif_stats ofwn_stats[NENTS(ofwn_ifs)]; struct netif_driver ofwnet = { "net", /* netif_bname */ ofwn_match, /* netif_match */ ofwn_probe, /* netif_probe */ ofwn_init, /* netif_init */ ofwn_get, /* netif_get */ ofwn_put, /* netif_put */ ofwn_end, /* netif_end */ ofwn_ifs, /* netif_ifs */ NENTS(ofwn_ifs) /* netif_nifs */ }; static phandle_t netdevice; static ihandle_t netinstance; static ihandle_t memory; static void *dmabuf; static int ofwn_match(struct netif *nif, void *machdep_hint) { return 1; } static int ofwn_probe(struct netif *nif, void *machdep_hint) { return 0; } static int -ofwn_put(struct iodesc *desc, void *pkt, int len) +ofwn_put(struct iodesc *desc, void *pkt, size_t len) { struct ether_header *eh; size_t sendlen; ssize_t rv; #if defined(NETIF_DEBUG) 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; #if defined(NETIF_DEBUG) printf("netif_put: length padded to %d\n", sendlen); #endif } if (dmabuf) { bcopy(pkt, dmabuf, sendlen); pkt = dmabuf; } rv = OF_write(netinstance, pkt, len); #if defined(NETIF_DEBUG) printf("netif_put: OF_write returned %d\n", rv); #endif return rv; } static int -ofwn_get(struct iodesc *desc, void *pkt, int len, time_t timeout) +ofwn_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout) { time_t t; int length; #if defined(NETIF_DEBUG) printf("netif_get: pkt=%p, maxlen=%d, timeout=%d\n", pkt, len, timeout); #endif t = getsecs(); do { length = OF_read(netinstance, pkt, len); } while ((length == -2 || length == 0) && (getsecs() - t < timeout)); #if defined(NETIF_DEBUG) printf("netif_get: received length=%d (%x)\n", length, length); #endif if (length < 12) return -1; #if defined(NETIF_VERBOSE_DEBUG) { char *ch = pkt; int i; for(i = 0; i < 96; i += 4) { printf("%02x%02x%02x%02x ", ch[i], ch[i+1], ch[i+2], ch[i+3]); } printf("\n"); } #endif #if defined(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 length; } extern char *strchr(); static void ofwn_init(struct iodesc *desc, void *machdep_hint) { phandle_t chosen, netdev; char path[64]; char *ch; int pathlen; chosen = OF_finddevice("/chosen"); OF_getprop(chosen, "memory", &memory, sizeof(memory)); pathlen = OF_getprop(chosen, "bootpath", path, 64); ch = index(path, ':'); *ch = '\0'; netdev = OF_finddevice(path); if (OF_getprop(netdev, "local-mac-address", desc->myea, 6) == -1) goto punt; printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea)); - if ((netinstance = OF_open(path)) == -1) + if ((netinstance = OF_open(path)) == -1) { + printf("Could not open network device.\n"); goto punt; + } #if defined(NETIF_DEBUG) printf("ofwn_init: OpenFirmware instance handle: %08x\n", netinstance); #endif if (OF_call_method("dma-alloc", netinstance, 1, 1, NULL, &dmabuf) < 0) { printf("Failed to allocate DMA buffer (got %08x).\n", dmabuf); goto punt; } #if defined(NETIF_DEBUG) printf("ofwn_init: allocated DMA buffer: %08x\n", dmabuf); #endif return; punt: printf("\n"); printf("Could not boot from %s.\n", path); - OF_exit(); + OF_enter(); } static void ofwn_end(struct netif *nif) { OF_call_method("dma-free", netinstance, 2, 0, dmabuf, MAXPHYS); OF_close(netinstance); } #if 0 int ofwn_getunit(const char *path) { int i; char newpath[255]; OF_canon(path, newpath, 254); for (i = 0; i < nofwninfo; i++) { printf(">>> test =\t%s\n", ofwninfo[i].ofwn_path); if (strcmp(path, ofwninfo[i].ofwn_path) == 0) return i; if (strcmp(newpath, ofwninfo[i].ofwn_path) == 0) return i; } return -1; } #endif Index: head/sys/boot/ofw/libofw/openfirm.c =================================================================== --- head/sys/boot/ofw/libofw/openfirm.c (revision 84616) +++ head/sys/boot/ofw/libofw/openfirm.c (revision 84617) @@ -1,747 +1,760 @@ /* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai 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. */ /* * Copyright (C) 2000 Benno Rice. * 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. * * THIS SOFTWARE IS PROVIDED BY Benno Rice ``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. * * $FreeBSD$ */ #include #include #include "openfirm.h" static int (*openfirmware)(void *); static ihandle_t stdin; static ihandle_t stdout; +static ihandle_t mmu; +static ihandle_t memory; + /* Initialiaser */ void OF_init(int (*openfirm)(void *)) { + phandle_t chosen; + openfirmware = openfirm; + + chosen = OF_finddevice("/chosen"); + OF_getprop(chosen, "memory", &memory, sizeof(memory)); + if (memory == 0) + panic("failed to get memory ihandle"); + OF_getprop(chosen, "mmu", &mmu, sizeof(mmu)); + if (mmu == 0) + panic("failed to get mmu ihandle"); } /* * Generic functions */ /* Test to see if a service exists. */ int OF_test(char *name) { static struct { char *name; int nargs; int nreturns; char *service; int missing; } args = { "test", 1, 1, }; args.service = name; if (openfirmware(&args) == -1) return -1; return args.missing; } /* Return firmware millisecond count. */ int OF_milliseconds() { static struct { char *name; int nargs; int nreturns; int ms; } args = { "milliseconds", 0, 1, }; openfirmware(&args); return args.ms; } /* * Device tree functions */ /* Return the next sibling of this node or 0. */ phandle_t OF_peer(phandle_t node) { static struct { char *name; int nargs; int nreturns; phandle_t node; phandle_t next; } args = { "peer", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return -1; return args.next; } /* Return the first child of this node or 0. */ phandle_t OF_child(phandle_t node) { static struct { char *name; int nargs; int nreturns; phandle_t node; phandle_t child; } args = { "child", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return -1; return args.child; } /* Return the parent of this node or 0. */ phandle_t OF_parent(phandle_t node) { static struct { char *name; int nargs; int nreturns; phandle_t node; phandle_t parent; } args = { "parent", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return -1; return args.parent; } /* Return the package handle that corresponds to an instance handle. */ phandle_t OF_instance_to_package(ihandle_t instance) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; phandle_t package; } args = { "instance-to-package", 1, 1, }; args.instance = instance; if (openfirmware(&args) == -1) return -1; return args.package; } /* Get the length of a property of a package. */ int OF_getproplen(phandle_t package, char *propname) { static struct { char *name; int nargs; int nreturns; phandle_t package; char *propname; int proplen; } args = { "getproplen", 2, 1, }; args.package = package; args.propname = propname; if (openfirmware(&args) == -1) return -1; return args.proplen; } /* Get the value of a property of a package. */ int OF_getprop(phandle_t package, char *propname, void *buf, int buflen) { static struct { char *name; int nargs; int nreturns; phandle_t package; char *propname; void *buf; int buflen; int size; } args = { "getprop", 4, 1, }; args.package = package; args.propname = propname; args.buf = buf; args.buflen = buflen; if (openfirmware(&args) == -1) return -1; return args.size; } /* Get the next property of a package. */ int OF_nextprop(phandle_t package, char *previous, char *buf) { static struct { char *name; int nargs; int nreturns; phandle_t package; char *previous; char *buf; int flag; } args = { "nextprop", 3, 1, }; args.package = package; args.previous = previous; args.buf = buf; if (openfirmware(&args) == -1) return -1; return args.flag; } /* Set the value of a property of a package. */ /* XXX Has a bug on FirePower */ int OF_setprop(phandle_t package, char *propname, void *buf, int len) { static struct { char *name; int nargs; int nreturns; phandle_t package; char *propname; void *buf; int len; int size; } args = { "setprop", 4, 1, }; args.package = package; args.propname = propname; args.buf = buf; args.len = len; if (openfirmware(&args) == -1) return -1; return args.size; } /* Convert a device specifier to a fully qualified pathname. */ int OF_canon(const char *device, char *buf, int len) { static struct { char *name; int nargs; int nreturns; char *device; char *buf; int len; int size; } args = { "canon", 3, 1, }; args.device = (char *)(uintptr_t *)device; args.buf = buf; args.len = len; if (openfirmware(&args) == -1) return -1; return args.size; } /* Return a package handle for the specified device. */ phandle_t OF_finddevice(const char *device) { static struct { char *name; int nargs; int nreturns; char *device; phandle_t package; } args = { "finddevice", 1, 1, }; args.device = (char *)(uintptr_t *)device; if (openfirmware(&args) == -1) return -1; return args.package; } /* Return the fully qualified pathname corresponding to an instance. */ int OF_instance_to_path(ihandle_t instance, char *buf, int len) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; char *buf; int len; int size; } args = { "instance-to-path", 3, 1, }; args.instance = instance; args.buf = buf; args.len = len; if (openfirmware(&args) == -1) return -1; return(args.size); } /* Return the fully qualified pathname corresponding to a package. */ int OF_package_to_path(phandle_t package, char *buf, int len) { static struct { char *name; int nargs; int nreturns; phandle_t package; char *buf; int len; int size; } args = { "package-to-path", 3, 1, }; args.package = package; args.buf = buf; args.len = len; if (openfirmware(&args) == -1) return -1; return(args.size); } /* Call the method in the scope of a given instance. */ int OF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...) { va_list ap; static struct { char *name; int nargs; int nreturns; char *method; ihandle_t instance; int args_n_results[12]; } args = { "call-method", 2, 1, }; int *ip, n; if (nargs > 6) return -1; args.nargs = nargs + 2; args.nreturns = nreturns + 1; args.method = method; args.instance = instance; va_start(ap, nreturns); for (ip = args.args_n_results + (n = nargs); --n >= 0;) *--ip = va_arg(ap, int); if (openfirmware(&args) == -1) return -1; 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; } /* * Device I/O functions. */ /* Open an instance for a device. */ ihandle_t OF_open(char *device) { static struct { char *name; int nargs; int nreturns; char *device; ihandle_t instance; } args = { "open", 1, 1, }; args.device = device; if (openfirmware(&args) == -1 || args.instance == 0) { return -1; } return args.instance; } /* Close an instance. */ void OF_close(ihandle_t instance) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; } args = { "close", 1, 0, }; args.instance = instance; openfirmware(&args); } /* Read from an instance. */ int OF_read(ihandle_t instance, void *addr, int len) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; void *addr; int len; int actual; } args = { "read", 3, 1, }; args.instance = instance; args.addr = addr; args.len = len; #if defined(OPENFIRM_DEBUG) printf("OF_read: called with instance=%08x, addr=%p, len=%d\n", args.instance, args.addr, args.len); #endif if (openfirmware(&args) == -1) return -1; #if defined(OPENFIRM_DEBUG) printf("OF_read: returning instance=%d, addr=%p, len=%d, actual=%d\n", args.instance, args.addr, args.len, args.actual); #endif return args.actual; } /* Write to an instance. */ int OF_write(ihandle_t instance, void *addr, int len) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; void *addr; int len; int actual; } args = { "write", 3, 1, }; args.instance = instance; args.addr = addr; args.len = len; if (openfirmware(&args) == -1) return -1; return args.actual; } /* Seek to a position. */ int OF_seek(ihandle_t instance, u_int64_t pos) { static struct { char *name; int nargs; int nreturns; ihandle_t instance; int poshi; int poslo; int status; } args = { "seek", 3, 1, }; args.instance = instance; args.poshi = (int)(pos >> 32); args.poslo = (int)pos; if (openfirmware(&args) == -1) return -1; return args.status; } /* * Memory functions. */ /* Claim an area of memory. */ void * OF_claim(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, }; args.virt = virt; args.size = size; args.align = align; if (openfirmware(&args) == -1) return (void *)-1; return args.baseaddr; } /* Release an area of memory. */ void OF_release(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); } /* * Control transfer functions. */ /* Reset the system and call "boot ". */ void OF_boot(char *bootspec) { static struct { char *name; int nargs; int nreturns; char *bootspec; } args = { "boot", 1, 0, }; args.bootspec = bootspec; openfirmware(&args); for (;;); /* just in case */ } /* Suspend and drop back to the OpenFirmware interface. */ void OF_enter() { static struct { char *name; int nargs; int nreturns; } args = { "enter", 0, 0 }; openfirmware(&args); return; /* We may come back. */ } /* Shut down and drop back to the OpenFirmware interface. */ void OF_exit() { static struct { char *name; int nargs; int nreturns; } args = { "exit", 0, 0 }; openfirmware(&args); for (;;); /* just in case */ } /* Free bytes starting at , then call with . */ -#ifdef __notyet__ +#if 0 void OF_chain(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(void *virt, u_int size, void (*entry)(), void *arg, u_int len) { /* * This is a REALLY dirty hack till the firmware gets this going */ -#if 0 - OF_release(virt, size); -#endif + if (size > 0) + OF_release(virt, size); + entry(0, 0, openfirmware, arg, len); } #endif Index: head/sys/boot/ofw/libofw/openfirm.h =================================================================== --- head/sys/boot/ofw/libofw/openfirm.h (revision 84616) +++ head/sys/boot/ofw/libofw/openfirm.h (revision 84617) @@ -1,119 +1,121 @@ /* $NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai 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. */ /* * Copyright (C) 2000 Benno Rice. * 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. * * THIS SOFTWARE IS PROVIDED BY Benno Rice ``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. * * $FreeBSD$ */ /* * Prototypes for Openfirmware Interface Routines */ #include #include typedef int ihandle_t; typedef int phandle_t; +extern phandle_t chosen; + /* * This isn't actually an OpenFirmware function, but it seemed like the right * place for it to go. */ void OF_init(int (*openfirm)(void *)); /* Generic functions */ int OF_test(char *); /* Device tree functions */ phandle_t OF_peer(phandle_t); phandle_t OF_child(phandle_t); phandle_t OF_parent(phandle_t); phandle_t OF_instance_to_package(ihandle_t); int OF_getproplen(phandle_t, char *); int OF_getprop(phandle_t, char *, void *, int); int OF_nextprop(phandle_t, char *, char *); int OF_setprop(phandle_t, char *, void *, int); int OF_canon(const char *, char *, int); phandle_t OF_finddevice(const char *); int OF_instance_to_path(ihandle_t, char *, int); int OF_package_to_path(phandle_t, char *, int); int OF_call_method(char *, ihandle_t, int, int, ...); /* Device I/O functions */ ihandle_t OF_open(char *); void OF_close(ihandle_t); int OF_read(ihandle_t, void *, int); int OF_write(ihandle_t, void *, int); int OF_seek(ihandle_t, u_quad_t); /* Memory functions */ void *OF_claim(void *, u_int, u_int); void OF_release(void *, u_int); /* Control transfer functions */ void OF_boot(char *); void OF_enter(void); void OF_exit(void) __attribute__((noreturn)); void OF_chain(void *, u_int, void (*)(), void *, u_int); #if 0 /* User interface functions */ /* OF_interpret */ void *OF_set_callback(void *); void OF_set_symbol_lookup(void *, void *); #endif /* Time function */ int OF_milliseconds(void); Index: head/sys/boot/powerpc/loader/Makefile =================================================================== --- head/sys/boot/powerpc/loader/Makefile (revision 84616) +++ head/sys/boot/powerpc/loader/Makefile (revision 84617) @@ -1,111 +1,115 @@ # $FreeBSD$ BASE= loader PROG= ${BASE} NOMAN= STRIP= NEWVERSWHAT= "bootstrap loader" OpenFirmware/PowerPC BINDIR?= /boot INSTALLFLAGS= -b LOADER_DISK_SUPPORT?= yes LOADER_NET_SUPPORT?= yes +# load address +RELOC?= 0x6c0000 +CFLAGS+= -DRELOC=${RELOC} + # architecture-specific loader code SRCS= conf.c # Pull in common loader code .PATH: ${.CURDIR}/../../ofw/common .include <${.CURDIR}/../../ofw/common/Makefile.inc> .if defined(LOADER_DISK_SUPPORT) CFLAGS+= -DLOADER_DISK_SUPPORT .endif .if defined(LOADER_NET_SUPPORT) CFLAGS+= -DLOADER_NET_SUPPORT .endif .if !defined(NOFORTH) # Enable BootForth BOOT_FORTH= yes CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/powerpc .if exists(${.OBJDIR}/../../ficl/libficl.a) LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .else LIBFICL= ${.CURDIR}/../../ficl/libficl.a .endif .endif # Always add MI sources .PATH: ${.CURDIR}/../../common .include <${.CURDIR}/../../common/Makefile.inc> CFLAGS+= -I${.CURDIR}/../../common CFLAGS+= -I${.CURDIR}/../../.. -I. CLEANFILES+= vers.c vers.o ${BASE}.list ${BASE}.bin ${BASE}.sym ${BASE}.help CFLAGS+= -Wall -LDFLAGS= -nostdlib -static -Ttext 6c0000 +LDFLAGS= -nostdlib -static -Ttext ${RELOC} # OpenFirmware standalone support library LIBOFW= ${.OBJDIR}/../../ofw/libofw/libofw.a CFLAGS+= -I${.CURDIR}/../../ofw/libofw # where to get libstand from #XXX need a better way to do this LIBSTAND= ${.CURDIR}/../../../../lib/libstand/libstand.a #.if !exists(${LIBSTAND}) #LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a #.if !exists(${LIBSTAND}) #LIBSTAND= -lstand #.endif #.endif CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ # OpenFirmware is expecting ELF components CFLAGS+= -elf # Debug me! CFLAGS+= -g LDFLAGS+= -g vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} ${CC} -c vers.c ${BASE}.help: help.common help.ofw cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} beforeinstall: .if exists(${.OBJDIR}/loader.help) ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot .else ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/${BASE}.help ${DESTDIR}/boot .endif .if !exists(${DESTDIR}/boot/loader.rc) ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.rc ${DESTDIR}/boot .endif ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.4th ${DESTDIR}/boot ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/support.4th ${DESTDIR}/boot ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.conf ${DESTDIR}/boot/defaults ${PROG}: ${OBJS} ${LIBOFW} ${LIBSTAND} ${LIBFICL} start.o vers.o ${LD} ${LDFLAGS} -o ${.TARGET} start.o ${OBJS} \ vers.o ${LIBFICL} ${LIBOFW} ${LIBSTAND} machine: ln -sf ${.CURDIR}/../../../powerpc/include machine # Cannot use ${OBJS} above this line .include beforedepend ${OBJS}: machine CLEANFILES+= machine setdefs.h setdef0.c setdef1.c setdef0.o setdef1.o \ start.o Index: head/sys/boot/powerpc/loader/conf.c =================================================================== --- head/sys/boot/powerpc/loader/conf.c (revision 84616) +++ head/sys/boot/powerpc/loader/conf.c (revision 84617) @@ -1,103 +1,109 @@ /*- * Copyright (c) 1999 Michael Smith * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include +#include "bootstrap.h" #include "libofw.h" +#include "openfirm.h" #if defined(LOADER_NET_SUPPORT) #include "dev_net.h" #endif /* * We could use linker sets for some or all of these, but * then we would have to control what ended up linked into * the bootstrap. So it's easier to conditionalise things * here. * * XXX rename these arrays to be consistent and less namespace-hostile */ /* Exported for libstand */ struct devsw *devsw[] = { #if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CDROM_SUPPORT) &ofwdisk, #endif #if defined(LOADER_NET_SUPPORT) &netdev, #endif NULL }; struct fs_ops *file_system[] = { #ifdef LOADER_UFS_SUPPORT &ufs_fsops, #endif #ifdef LOADER_CDROM_SUPPORT &cd9660_fsops, #endif #ifdef LOADER_EXT2FS_SUPPORT &ext2fs_fsops, #endif #ifdef LOADER_NET_SUPPORT &nfs_fsops, #endif &zipfs_fsops, NULL }; struct netif_driver *netif_drivers[] = { #ifdef LOADER_NET_SUPPORT &ofwnet, #endif NULL, }; /* Exported for PowerPC only */ /* * Sort formats so that those that can detect based on arguments * rather than reading the file go first. */ -extern struct file_format powerpc_elf; struct file_format *file_formats[] = { -/* &powerpc_elf,*/ + &ofw_elf, NULL }; /* * Consoles * * We don't prototype these in libalpha.h because they require * data structures from bootstrap.h as well. */ extern struct console ofwconsole; struct console *consoles[] = { &ofwconsole, NULL }; + +/* + * reloc - our load address + */ +vm_offset_t reloc = RELOC; Index: head/sys/boot/powerpc/loader/start.c =================================================================== --- head/sys/boot/powerpc/loader/start.c (revision 84616) +++ head/sys/boot/powerpc/loader/start.c (revision 84617) @@ -1,102 +1,104 @@ /* $FreeBSD$ */ /* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai 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. */ #include #include "libofw.h" void startup(void *, int, int (*)(void *), char *, int); -static int stack[8192/4 + 4]; - #ifdef XCOFF_GLUE asm(" .text .globl _entry _entry: .long _start,0,0 "); #endif -asm(" +__asm(" + .data +stack: + .space 16388 + .text .globl _start _start: li 8,0 li 9,0x100 mtctr 9 1: dcbf 0,8 icbi 0,8 addi 8,8,0x20 bdnz 1b sync isync lis 1,stack@ha addi 1,1,stack@l addi 1,1,8192 mfmsr 8 li 0,0 mtmsr 0 isync mtibatu 0,0 mtibatu 1,0 mtibatu 2,0 mtibatu 3,0 mtdbatu 0,0 mtdbatu 1,0 mtdbatu 2,0 mtdbatu 3,0 li 9,0x12 /* BATL(0, BAT_M, BAT_PP_RW) */ mtibatl 0,9 mtdbatl 0,9 li 9,0x1ffe /* BATU(0, BAT_BL_256M, BAT_Vs) */ mtibatu 0,9 mtdbatu 0,9 isync mtmsr 8 isync b startup "); void startup(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl) { main(openfirm); } Index: head/sys/boot/powerpc/ofw/Makefile =================================================================== --- head/sys/boot/powerpc/ofw/Makefile (revision 84616) +++ head/sys/boot/powerpc/ofw/Makefile (revision 84617) @@ -1,111 +1,115 @@ # $FreeBSD$ BASE= loader PROG= ${BASE} NOMAN= STRIP= NEWVERSWHAT= "bootstrap loader" OpenFirmware/PowerPC BINDIR?= /boot INSTALLFLAGS= -b LOADER_DISK_SUPPORT?= yes LOADER_NET_SUPPORT?= yes +# load address +RELOC?= 0x6c0000 +CFLAGS+= -DRELOC=${RELOC} + # architecture-specific loader code SRCS= conf.c # Pull in common loader code .PATH: ${.CURDIR}/../../ofw/common .include <${.CURDIR}/../../ofw/common/Makefile.inc> .if defined(LOADER_DISK_SUPPORT) CFLAGS+= -DLOADER_DISK_SUPPORT .endif .if defined(LOADER_NET_SUPPORT) CFLAGS+= -DLOADER_NET_SUPPORT .endif .if !defined(NOFORTH) # Enable BootForth BOOT_FORTH= yes CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/powerpc .if exists(${.OBJDIR}/../../ficl/libficl.a) LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .else LIBFICL= ${.CURDIR}/../../ficl/libficl.a .endif .endif # Always add MI sources .PATH: ${.CURDIR}/../../common .include <${.CURDIR}/../../common/Makefile.inc> CFLAGS+= -I${.CURDIR}/../../common CFLAGS+= -I${.CURDIR}/../../.. -I. CLEANFILES+= vers.c vers.o ${BASE}.list ${BASE}.bin ${BASE}.sym ${BASE}.help CFLAGS+= -Wall -LDFLAGS= -nostdlib -static -Ttext 6c0000 +LDFLAGS= -nostdlib -static -Ttext ${RELOC} # OpenFirmware standalone support library LIBOFW= ${.OBJDIR}/../../ofw/libofw/libofw.a CFLAGS+= -I${.CURDIR}/../../ofw/libofw # where to get libstand from #XXX need a better way to do this LIBSTAND= ${.CURDIR}/../../../../lib/libstand/libstand.a #.if !exists(${LIBSTAND}) #LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a #.if !exists(${LIBSTAND}) #LIBSTAND= -lstand #.endif #.endif CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ # OpenFirmware is expecting ELF components CFLAGS+= -elf # Debug me! CFLAGS+= -g LDFLAGS+= -g vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} ${CC} -c vers.c ${BASE}.help: help.common help.ofw cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} beforeinstall: .if exists(${.OBJDIR}/loader.help) ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot .else ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/${BASE}.help ${DESTDIR}/boot .endif .if !exists(${DESTDIR}/boot/loader.rc) ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.rc ${DESTDIR}/boot .endif ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.4th ${DESTDIR}/boot ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/support.4th ${DESTDIR}/boot ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/../../forth/loader.conf ${DESTDIR}/boot/defaults ${PROG}: ${OBJS} ${LIBOFW} ${LIBSTAND} ${LIBFICL} start.o vers.o ${LD} ${LDFLAGS} -o ${.TARGET} start.o ${OBJS} \ vers.o ${LIBFICL} ${LIBOFW} ${LIBSTAND} machine: ln -sf ${.CURDIR}/../../../powerpc/include machine # Cannot use ${OBJS} above this line .include beforedepend ${OBJS}: machine CLEANFILES+= machine setdefs.h setdef0.c setdef1.c setdef0.o setdef1.o \ start.o Index: head/sys/boot/powerpc/ofw/conf.c =================================================================== --- head/sys/boot/powerpc/ofw/conf.c (revision 84616) +++ head/sys/boot/powerpc/ofw/conf.c (revision 84617) @@ -1,103 +1,109 @@ /*- * Copyright (c) 1999 Michael Smith * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include +#include "bootstrap.h" #include "libofw.h" +#include "openfirm.h" #if defined(LOADER_NET_SUPPORT) #include "dev_net.h" #endif /* * We could use linker sets for some or all of these, but * then we would have to control what ended up linked into * the bootstrap. So it's easier to conditionalise things * here. * * XXX rename these arrays to be consistent and less namespace-hostile */ /* Exported for libstand */ struct devsw *devsw[] = { #if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CDROM_SUPPORT) &ofwdisk, #endif #if defined(LOADER_NET_SUPPORT) &netdev, #endif NULL }; struct fs_ops *file_system[] = { #ifdef LOADER_UFS_SUPPORT &ufs_fsops, #endif #ifdef LOADER_CDROM_SUPPORT &cd9660_fsops, #endif #ifdef LOADER_EXT2FS_SUPPORT &ext2fs_fsops, #endif #ifdef LOADER_NET_SUPPORT &nfs_fsops, #endif &zipfs_fsops, NULL }; struct netif_driver *netif_drivers[] = { #ifdef LOADER_NET_SUPPORT &ofwnet, #endif NULL, }; /* Exported for PowerPC only */ /* * Sort formats so that those that can detect based on arguments * rather than reading the file go first. */ -extern struct file_format powerpc_elf; struct file_format *file_formats[] = { -/* &powerpc_elf,*/ + &ofw_elf, NULL }; /* * Consoles * * We don't prototype these in libalpha.h because they require * data structures from bootstrap.h as well. */ extern struct console ofwconsole; struct console *consoles[] = { &ofwconsole, NULL }; + +/* + * reloc - our load address + */ +vm_offset_t reloc = RELOC; Index: head/sys/boot/powerpc/ofw/start.c =================================================================== --- head/sys/boot/powerpc/ofw/start.c (revision 84616) +++ head/sys/boot/powerpc/ofw/start.c (revision 84617) @@ -1,102 +1,104 @@ /* $FreeBSD$ */ /* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai 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. */ #include #include "libofw.h" void startup(void *, int, int (*)(void *), char *, int); -static int stack[8192/4 + 4]; - #ifdef XCOFF_GLUE asm(" .text .globl _entry _entry: .long _start,0,0 "); #endif -asm(" +__asm(" + .data +stack: + .space 16388 + .text .globl _start _start: li 8,0 li 9,0x100 mtctr 9 1: dcbf 0,8 icbi 0,8 addi 8,8,0x20 bdnz 1b sync isync lis 1,stack@ha addi 1,1,stack@l addi 1,1,8192 mfmsr 8 li 0,0 mtmsr 0 isync mtibatu 0,0 mtibatu 1,0 mtibatu 2,0 mtibatu 3,0 mtdbatu 0,0 mtdbatu 1,0 mtdbatu 2,0 mtdbatu 3,0 li 9,0x12 /* BATL(0, BAT_M, BAT_PP_RW) */ mtibatl 0,9 mtdbatl 0,9 li 9,0x1ffe /* BATU(0, BAT_BL_256M, BAT_Vs) */ mtibatu 0,9 mtdbatu 0,9 isync mtmsr 8 isync b startup "); void startup(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl) { main(openfirm); }