diff options
| author | garbled <garbled@NetBSD.org> | 2008-01-09 19:34:44 +0000 |
|---|---|---|
| committer | garbled <garbled@NetBSD.org> | 2008-01-09 19:34:44 +0000 |
| commit | dc535894e11d0b97e531cee366df25cebb7dbc1c (patch) | |
| tree | 8268b5286fb13254e2af09467a634a0770c07a33 | |
| parent | b2fb3432e42f01ddb02d117a316fba5818e148b5 (diff) | |
Changes to the ofppc ofwboot to make it boot on an IBM CHRP RS/6000.
Tested on a pegasos II and a 7044-270. Also, switch away from the hacked
up alloc.c we were using, and use the stock libsa one.
| -rw-r--r-- | sys/arch/ofppc/include/loadfile_machdep.h | 3 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/Locore.c | 91 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/Makefile | 7 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/alloc.c | 252 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/boot.c | 4 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/ofwstart.S | 150 | ||||
| -rw-r--r-- | sys/arch/ofppc/stand/ofwboot/version | 3 |
7 files changed, 205 insertions, 305 deletions
diff --git a/sys/arch/ofppc/include/loadfile_machdep.h b/sys/arch/ofppc/include/loadfile_machdep.h index 7cbe10d9a99..4f339c6af36 100644 --- a/sys/arch/ofppc/include/loadfile_machdep.h +++ b/sys/arch/ofppc/include/loadfile_machdep.h @@ -1,4 +1,4 @@ -/* $NetBSD: loadfile_machdep.h,v 1.3 2006/01/25 18:28:27 christos Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.4 2008/01/09 19:34:44 garbled Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -36,7 +36,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#define BOOT_AOUT #define BOOT_ELF32 #define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) diff --git a/sys/arch/ofppc/stand/ofwboot/Locore.c b/sys/arch/ofppc/stand/ofwboot/Locore.c index b46e31ab6aa..529ced6e920 100644 --- a/sys/arch/ofppc/stand/ofwboot/Locore.c +++ b/sys/arch/ofppc/stand/ofwboot/Locore.c @@ -1,4 +1,4 @@ -/* $NetBSD: Locore.c,v 1.17 2007/11/24 15:49:32 jmmv Exp $ */ +/* $NetBSD: Locore.c,v 1.18 2008/01/09 19:34:44 garbled Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #include "openfirm.h" - +#include <sys/param.h> #include <lib/libsa/stand.h> #include <machine/cpu.h> @@ -40,48 +40,13 @@ static int (*openfirmware_entry)(void *); static int openfirmware(void *); -static void startup(void *, int, int (*)(void *), char *, int) - __attribute__((__used__)); +void startup(void *, int, int (*)(void *), char *, int) + __attribute__((__used__)); static void setup(void); -static int stack[8192/4 + 4] __attribute__((__used__)); - -__asm( -" .text \n" -" .globl _start \n" -"_start: \n" -" li %r8,0 \n" -" li %r9,0x100 \n" -" mtctr %r9 \n" -"1: \n" -" dcbf 0,%r8 \n" -" icbi 0,%r8 \n" -" addi %r8,%r8,0x20 \n" -" bdnz 1b \n" -" sync \n" -" isync \n" -" lis %r1,stack@ha \n" -" addi %r1,%r1,stack@l \n" -" addi %r1,%r1,8192 \n" -" \n" - /* - * Make sure that .bss is zeroed - */ -" \n" -" li %r0,0 \n" -" lis %r8,_edata@ha \n" -" addi %r8,%r8,_edata@l \n" -" lis %r9,_end@ha \n" -" addi %r9,%r9,_end@l \n" -" \n" -"2: cmpw 0,%r8,%r9 \n" -" bge 3f \n" -" stw %r0,0(%r8) \n" -" addi %r8,%r8,4 \n" -" b 2b \n" -" \n" -"3: b startup \n" -); +int stack[8192/4 + 4] __attribute__((__used__)); +char *heapspace; +char altheap[0x20000]; static int openfirmware(void *arg) @@ -95,7 +60,7 @@ openfirmware(void *arg) return r; } -static void +void startup(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl) { @@ -402,6 +367,35 @@ OF_seek(int handle, u_quad_t pos) } void * +OF_alloc_mem(u_int size) +{ + static struct { + char *name; + int nargs; + int nreturns; + u_int size; + void *baseaddr; + } args = { + "alloc-mem", + 1, + 1, + }; +#ifdef OFW_DEBUG + printf("alloc-mem %x -> ", size); +#endif + if (openfirmware(&args) == -1) { +#ifdef OFW_DEBUG + printf("lose\n"); +#endif + return (void *)-1; + } +#ifdef OFW_DEBUG + printf("%p\n", args.baseaddr); +#endif + return args.baseaddr; +} + +void * OF_claim(void *virt, u_int size, u_int align) { static struct { @@ -510,7 +504,7 @@ OF_chain(void *virt, u_int size, boot_entry_t entry, void *arg, u_int len) /* * This is a REALLY dirty hack till the firmware gets this going */ -#if 1 +#if 0 OF_release(virt, size); #endif entry(0, 0, openfirmware_entry, arg, len); @@ -519,6 +513,7 @@ OF_chain(void *virt, u_int size, boot_entry_t entry, void *arg, u_int len) static int stdin; static int stdout; +static int memory; static void setup(void) @@ -532,6 +527,14 @@ setup(void) OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) != sizeof(stdout)) OF_exit(); + + printf("Allocating 0x20000 bytes of ram for boot\n"); + heapspace = OF_claim(0, 0x20000, NBPG); + if (heapspace == (char *)-1) { + printf("WARNING: Failed to alloc ram, using bss\n"); + setheap(&altheap, &altheap[0x20000]); + } else + setheap(heapspace, heapspace+0x20000); } void diff --git a/sys/arch/ofppc/stand/ofwboot/Makefile b/sys/arch/ofppc/stand/ofwboot/Makefile index e3a5a32e690..6e3bf18b374 100644 --- a/sys/arch/ofppc/stand/ofwboot/Makefile +++ b/sys/arch/ofppc/stand/ofwboot/Makefile @@ -1,12 +1,13 @@ -# $NetBSD: Makefile,v 1.20 2007/10/17 19:56:13 garbled Exp $ +# $NetBSD: Makefile,v 1.21 2008/01/09 19:34:44 garbled Exp $ S!= cd ${.CURDIR}/../../../.. ; pwd PROG= ofwboot -SRCS= Locore.c alloc.c boot.c ofdev.c net.c netif_of.c vers.c +SRCS= ofwstart.S Locore.c boot.c ofdev.c net.c netif_of.c vers.c CFLAGS+= -msoft-float -Wno-main -ffreestanding -#CPPFLAGS+= -DDEBUG -DNETIF_DEBUG +#CPPFLAGS+= -g -DALLOC_TRACE -DDEBUG #-DOFW_DEBUG -DNETIF_DEBUG CPPFLAGS+= -D_STANDALONE -DSUPPORT_DHCP -I${.CURDIR} +CPPFLAGS+= -DHEAP_VARIABLE DBG= -Os -mmultiple SRCS+= ofwmagic.S diff --git a/sys/arch/ofppc/stand/ofwboot/alloc.c b/sys/arch/ofppc/stand/ofwboot/alloc.c deleted file mode 100644 index 3c1b4c065b7..00000000000 --- a/sys/arch/ofppc/stand/ofwboot/alloc.c +++ /dev/null @@ -1,252 +0,0 @@ -/* $NetBSD: alloc.c,v 1.7 2006/01/27 04:18:39 uwe Exp $ */ - -/*- - * Copyright (c) 1997 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * 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 "alloc.h" -#include "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; -}; - -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_t size) -{ - struct ml *f, *bestf; -#ifndef ALLOC_FIRST_FIT - unsigned bestsize = 0xffffffff; /* greater than any real size */ -#endif - char *help; - int failed; - -#ifdef ALLOC_TRACE - printf("alloc(%zu)", 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 && (size_t)f->size < size; - f = f->list.le_next) - /* noop */ ; - bestf = f; - failed = (bestf == NULL); -#else - /* scan freelist */ - bestf = NULL; /* XXXGCC: -Wuninitialized */ - f = freelist.lh_first; - while (f != NULL) { - if ((size_t)f->size >= size) { - if ((size_t)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(NULL, (unsigned)size, NBPG); - if (help == (char *)-1) - panic("alloc: out of memory"); - - f = (struct ml *)help; - f->size = (unsigned)size; -#ifdef ALLOC_TRACE - printf("=%lx (new chunk size %u)\n", - (u_long)(help + OVERHEAD), f->size); -#endif - goto out; - } - - /* we take the best fit */ - f = bestf; - -#ifndef ALLOC_FIRST_FIT - found: -#endif - /* 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 -dealloc(void *ptr, size_t size) -{ - register struct ml *a = (struct ml *)((char*)ptr - OVERHEAD); - -#ifdef ALLOC_TRACE - printf("dealloc(%lx, %zu) (origsize %u)\n", (u_long)ptr, size, a->size); -#endif -#ifdef DEBUG - if (size > (size_t)a->size) - printf("dealloc %zu 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(void) -{ -#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/ofppc/stand/ofwboot/boot.c b/sys/arch/ofppc/stand/ofwboot/boot.c index 05ebbf7d2a3..32b8788d5fd 100644 --- a/sys/arch/ofppc/stand/ofwboot/boot.c +++ b/sys/arch/ofppc/stand/ofwboot/boot.c @@ -1,4 +1,4 @@ -/* $NetBSD: boot.c,v 1.16 2007/10/18 19:58:54 garbled Exp $ */ +/* $NetBSD: boot.c,v 1.17 2008/01/09 19:34:45 garbled Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -158,8 +158,6 @@ chain(boot_entry_t entry, char *args, void *ssym, void *esym) extern char end[], *cp; u_int l, magic = 0x19730224; - freeall(); - /* * Stash pointer to start and end of symbol table after the argument * strings. diff --git a/sys/arch/ofppc/stand/ofwboot/ofwstart.S b/sys/arch/ofppc/stand/ofwboot/ofwstart.S new file mode 100644 index 00000000000..55888ce656c --- /dev/null +++ b/sys/arch/ofppc/stand/ofwboot/ofwstart.S @@ -0,0 +1,150 @@ +/* $NetBSD: ofwstart.S,v 1.1 2008/01/09 19:34:45 garbled Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Tim Rightnour + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef XCOFF_GLUE + .text + .globl _entry +_entry: + .long _start,0,0 +#endif /* XCOFF_GLUE */ + + .text + .globl _start + /* This is the magical note section that IBM machines require + * to boot. This should be a note, but gnu ld will not let us + * position it at the start of the file. + */ + # length of name + .long 8 + # note descriptor size + .long 24 + # note type (IEEE 1275) + .long 0x1275 + # name of owner + .asciz "PowerPC" + .balign 4 + + # note descriptor + # real mode (-1) or virtual mode (0) + .long 0 + # real-base + .long -1 + # real-size + .long -1 + # virt-base + .long -1 + # virt-size + .long -1 + # load-base + .long 0x4000 + + /* note for dealing with IBM LPARs */ + # length of name + .long 24 + # note descriptor size + .long 28 + # note type + .long 0x12759999 + # name of owner + .asciz "IBM,RPA-Client-Config" + .balign 4 + + # lpar affinity + .long 0 + # minimum size in megabytes + .long 64 + # minimum percentage size + .long 0 + # max pft size ( 2^48 bytes ) + .long 48 + # splpar + .long 1 + # min load ? + .long -1 + # new mem def ? + .long 0 + +_start: + sync + isync + lis %r1,stack@ha + addi %r1,%r1,stack@l + addi %r1,%r1,8192 + + mfmsr %r8 + li %r0,0 + mtmsr %r0 + isync + + mtibatu 0,%r0 + mtibatu 1,%r0 + mtibatu 2,%r0 + mtibatu 3,%r0 + mtdbatu 0,%r0 + mtdbatu 1,%r0 + mtdbatu 2,%r0 + mtdbatu 3,%r0 + + li %r9,0x12 /* BATL(0, BAT_M, BAT_PP_RW) */ + mtibatl 0,%r9 + mtdbatl 0,%r9 + li %r9,0x1ffe /* BATU(0, BAT_BL_256M, BAT_Vs) */ + mtibatu 0,%r9 + mtdbatu 0,%r9 + isync + + mtmsr %r8 + isync + + /* + * Make sure that .bss is zeroed + */ + + li %r0,0 + lis %r8,_edata@ha + addi %r8,%r8,_edata@l + lis %r9,_end@ha + addi %r9,%r9,_end@l + +5: cmpw 0,%r8,%r9 + bge 6f + stw %r0,0(%r8) + addi %r8,%r8,4 + b 5b + +6: b startup diff --git a/sys/arch/ofppc/stand/ofwboot/version b/sys/arch/ofppc/stand/ofwboot/version index 041d8cfda34..eeda54d9c7b 100644 --- a/sys/arch/ofppc/stand/ofwboot/version +++ b/sys/arch/ofppc/stand/ofwboot/version @@ -1,4 +1,4 @@ -$NetBSD: version,v 1.7 2008/01/03 06:40:02 mrg Exp $ +$NetBSD: version,v 1.8 2008/01/09 19:34:45 garbled Exp $ 1.1: Boot program for OpenFirmware; initial revision 1.2: Boot program rearrangement @@ -7,3 +7,4 @@ $NetBSD: version,v 1.7 2008/01/03 06:40:02 mrg Exp $ 1.5: Support for proper DDB symbol loading and MS-DOS file systems 1.6: Change how symbol table is conveyed to kernel 1.7: Support RAID partitions +1.8: Support IBM RS/6000, switch to stock libsa alloc |
