diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-01-10 00:25:04 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-01-10 00:25:04 +0000 |
commit | f00edbac75fc774516649a7bc94e5d6e3f579cc4 (patch) | |
tree | c152eec63e70afb401d372e47928c74a8eeaacb7 | |
parent | b6c39ce7790cf6c5cb8b6689bef53e0b0195ea48 (diff) |
third generation boot blocks from the zaurus
zaurus# stand/zboot/obj.i386.zaurus/zboot
probing: ux0
>> OpenBSD/zaurus BOOT 2.06
boot> b
b
booting /dev/hda4:/bsd: [cross fingers here]
written by dragos at first, more work by drahn, and now increasingly
polished by uwe
-rw-r--r-- | sys/arch/zaurus/stand/Makefile | 5 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/Makefile.inc | 1 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/TODO | 11 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/Makefile | 52 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/alloc.c | 230 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/compat_linux.h | 66 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/conf.c | 109 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/devopen.c | 170 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/exec.c | 24 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/exit.c | 65 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/libsa.h | 33 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/loadfile.c | 680 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/machdep.c | 57 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/pathnames.h | 17 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/unixdev.c | 191 | ||||
-rw-r--r-- | sys/arch/zaurus/stand/zboot/unixsys.S | 56 |
16 files changed, 1767 insertions, 0 deletions
diff --git a/sys/arch/zaurus/stand/Makefile b/sys/arch/zaurus/stand/Makefile new file mode 100644 index 00000000000..9e2516fbc42 --- /dev/null +++ b/sys/arch/zaurus/stand/Makefile @@ -0,0 +1,5 @@ +.if ${MACHINE} == "zaurus" +SUBDIR= zbsdmod zboot +.endif + +.include <bsd.subdir.mk> diff --git a/sys/arch/zaurus/stand/Makefile.inc b/sys/arch/zaurus/stand/Makefile.inc new file mode 100644 index 00000000000..86352275f36 --- /dev/null +++ b/sys/arch/zaurus/stand/Makefile.inc @@ -0,0 +1 @@ +BINDIR= /usr/mdec diff --git a/sys/arch/zaurus/stand/TODO b/sys/arch/zaurus/stand/TODO new file mode 100644 index 00000000000..b88d927615f --- /dev/null +++ b/sys/arch/zaurus/stand/TODO @@ -0,0 +1,11 @@ +LKM: + * Shut down cleanly before rebooting, like Dragos' module did. + + * Accept boot arguments from the userland. + +Userland: + * Load kernel files from Linux file systems, too. (That can now + be achieved with `cp bsd /dev/zboot'.) + + * Create crt0.S which defines _start(), so that ld doesn't depend + on the order of object files. diff --git a/sys/arch/zaurus/stand/zboot/Makefile b/sys/arch/zaurus/stand/zboot/Makefile new file mode 100644 index 00000000000..d8282e719a1 --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/Makefile @@ -0,0 +1,52 @@ +#MAN= zboot.8 +NOMAN= + +.if ${MACHINE} == "zaurus" +PROG= zboot +LDFLAGS+=-nostdlib -Bstatic +INSTALL_STRIP= + +#LDFLAGS+=-Ttext $(LINKADDR) -N -x -noinhibit-exec +#CLEANFILES+= crt0.o +#SRCS= srt0.S + +S= ${.CURDIR}/../../../.. + +CLEANFILES+= arm machine +.if !make(libdep) && !make(sadep) && !make(salibdir) && !make(kernlibdir) && !make(obj) +.BEGIN: + @([ X$(S) = X -o -h arm ] || ln -s $(S)/arch/arm/include arm) + @([ X$(S) = X -o -h machine ] || ln -s $(S)/arch/zaurus/include machine) +.endif + +# stand/boot +SRCS+= boot.c cmd.c vars.c bootarg.c conf.c + +# libsa +SRCS+= close.c closeall.c cons.c ctime.c disklabel.c dkcksum.c fstat.c \ + lseek.c memcmp.c memcpy.c memset.c open.c printf.c read.c \ + readdir.c snprintf.c stat.c strerror.c strtol.c ufs.c + +# libkern +SRCS+= strcmp.c strlcpy.c strlen.c strncmp.c strncpy.c write.c \ + ashrdi3.c divsi3.S + +# local overrides for Linux/zaurus +SRCS+= alloc.c devopen.c exec.c exit.c loadfile.c machdep.c \ + unixdev.c unixsys.S + +.PATH: ${S}/stand/boot +.PATH: ${S}/lib/libsa +.PATH: ${S}/lib/libkern +.PATH: ${S}/lib/libkern/arch/arm + +.else +NOPROG= +.endif + +.include <bsd.prog.mk> + +AFLAGS+=-D_LOCORE +CPPFLAGS+=-D_STANDALONE +CPPFLAGS+=-I${S}/stand/boot -I${S}/lib/libsa -I. -I${.CURDIR} -I${S} +CFLAGS+=-fno-stack-protector -fno-builtin -fpack-struct diff --git a/sys/arch/zaurus/stand/zboot/alloc.c b/sys/arch/zaurus/stand/zboot/alloc.c new file mode 100644 index 00000000000..bcb94800754 --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/alloc.c @@ -0,0 +1,230 @@ +/* $OpenBSD: alloc.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ +/* $NetBSD: alloc.c,v 1.6 1997/02/04 18:36:33 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1996 + * Matthias Drochner. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. Neither the name of the University 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 REGENTS 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 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. + * + * @(#)alloc.c 8.1 (Berkeley) 6/11/93 + * + * + * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Author: Alessandro Forin + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * Dynamic memory allocator. + * + * 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. + * + * HEAP_LIMIT heap limit address (defaults to "no limit"). + * + * HEAP_START start address of heap (defaults to '&end'). + * + * DEBUG enable debugging sanity checks. + */ + +#include <sys/param.h> + +/* + * Each block actually has ALIGN(unsigned) + ALIGN(size) bytes allocated + * to it, as follows: + * + * 0 ... (sizeof(unsigned) - 1) + * allocated or unallocated: holds size of user-data part of block. + * + * sizeof(unsigned) ... (ALIGN(sizeof(unsigned)) - 1) + * allocated: unused + * unallocated: depends on packing of struct fl + * + * ALIGN(sizeof(unsigned)) ... (ALIGN(sizeof(unsigned)) + 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(unsigned)) + ALIGN(data size) must + * be at least 'sizeof(struct fl)', so that blocks can be used as structures + * when on the free list. + */ + +#include <lib/libsa/stand.h> + +struct fl { + unsigned size; + struct fl *next; +} *freelist = (struct fl *)0; + +static char heap[4 * 1024 * 1024]; +#define HEAP_START (heap) +#define HEAP_LIMIT (&heap[sizeof(heap)]) + +#ifdef HEAP_START +static char *top = (char *)HEAP_START; +#else +extern char end[]; +static char *top = end; +#endif + +void * +alloc(unsigned int size) +{ + struct fl **f = &freelist, **bestf = NULL; +#ifndef ALLOC_FIRST_FIT + unsigned bestsize = 0xffffffff; /* greater than any real size */ +#endif + char *help; + int failed; + +#ifdef ALLOC_TRACE + printf("alloc(%u)", size); +#endif + +#ifdef ALLOC_FIRST_FIT + while (*f != (struct fl *)0 && (*f)->size < size) + f = &((*f)->next); + bestf = f; + failed = (*bestf == (struct fl *)0); +#else + /* scan freelist */ + while (*f) { + 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)->next); + } + + /* no match in freelist if bestsize unchanged */ + failed = (bestsize == 0xffffffff); +#endif + + if (failed) { /* nothing found */ + /* + * allocate from heap, keep chunk len in + * first word + */ + help = top; + + /* make _sure_ the region can hold a struct fl. */ + if (size < ALIGN(sizeof (struct fl *))) + size = ALIGN(sizeof (struct fl *)); + top += ALIGN(sizeof(unsigned)) + ALIGN(size); +#ifdef HEAP_LIMIT + if (top > (char *)HEAP_LIMIT) + panic("heap full (0x%lx+%u)", help, size); +#endif + *(unsigned *)help = ALIGN(size); +#ifdef ALLOC_TRACE + printf("=%p\n", help + ALIGN(sizeof(unsigned))); +#endif + return(help + ALIGN(sizeof(unsigned))); + } + + /* we take the best fit */ + f = bestf; + +#ifndef ALLOC_FIRST_FIT +found: +#endif + /* remove from freelist */ + help = (char *)*f; + *f = (*f)->next; +#ifdef ALLOC_TRACE + printf("=%p (origsize %u)\n", help + ALIGN(sizeof(unsigned)), + *(unsigned *)help); +#endif + return(help + ALIGN(sizeof(unsigned))); +} + +void +free(void *ptr, unsigned int size) +{ + struct fl *f = (struct fl *)((char *)ptr - + ALIGN(sizeof(unsigned))); + +#ifdef ALLOC_TRACE + printf("free(%p, %u) (origsize %u)\n", ptr, size, f->size); +#endif +#ifdef DEBUG + if (size > f->size) + printf("free %u bytes @%p, should be <=%u\n", + size, ptr, f->size); +#ifdef HEAP_START + if (ptr < (void *)HEAP_START) +#else + if (ptr < (void *)end) +#endif + printf("free: %lx before start of heap.\n", (u_long)ptr); + +#ifdef HEAP_LIMIT + if (ptr > (void *)HEAP_LIMIT) + printf("free: %lx beyond end of heap.\n", (u_long)ptr); +#endif +#endif /* DEBUG */ + /* put into freelist */ + f->next = freelist; + freelist = f; +} diff --git a/sys/arch/zaurus/stand/zboot/compat_linux.h b/sys/arch/zaurus/stand/zboot/compat_linux.h new file mode 100644 index 00000000000..b19e4d151ce --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/compat_linux.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _TEST + +/* This file must be included late, for redefinitions to take effect. */ + +#ifndef _LOCORE +#include <compat/linux/linux_types.h> +#include <compat/linux/linux_fcntl.h> +#endif + +#undef O_RDONLY +#undef O_WRONLY +#undef SEEK_SET + +#define O_RDONLY LINUX_O_RDONLY +#define O_WRONLY LINUX_O_WRONLY +#define SEEK_SET 0 + +/* linux/asm/unistd.h */ +#define __NR_SYSCALL_BASE 0x900000 +#define __NR_exit (__NR_SYSCALL_BASE+ 1) +#define __NR_read (__NR_SYSCALL_BASE+ 3) +#define __NR_write (__NR_SYSCALL_BASE+ 4) +#define __NR_open (__NR_SYSCALL_BASE+ 5) +#define __NR_close (__NR_SYSCALL_BASE+ 6) +#define __NR_lseek (__NR_SYSCALL_BASE+ 19) +#define __NR_ioctl (__NR_SYSCALL_BASE+ 54) +#define __NR__new_select (__NR_SYSCALL_BASE+142) +#define __NR_select __NR__new_select /* XXX */ +#define __NR_syscall (__NR_SYSCALL_BASE+113) +#define linux__sys2(x) #x +#define linux__sys1(x) linux__sys2(x) +#define linux__syscall(name) "swi\t" linux__sys1(__NR_##name) "\n\t" +#define linux__syscall_return(type, res) \ +do { \ + if ((unsigned long)(res) >= (unsigned long)(-125)) { \ + errno = -(res); \ + res = -1; \ + } \ + return (type) (res); \ +} while (0) + +#undef SYS_select +#define SYS_select __NR__new_select + +#else + +#include <fcntl.h> +#include <unistd.h> + +#endif /* _TEST */ diff --git a/sys/arch/zaurus/stand/zboot/conf.c b/sys/arch/zaurus/stand/zboot/conf.c new file mode 100644 index 00000000000..32394a0f0be --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/conf.c @@ -0,0 +1,109 @@ +/* $OpenBSD: conf.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ + +/* + * Copyright (c) 1996 Michael Shalayeff + * 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 ``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. + * + */ + +#include <sys/types.h> +#include <netinet/in.h> +#include <libsa.h> +#include <lib/libsa/ufs.h> +#ifdef notdef +#include <lib/libsa/cd9660.h> +#include <lib/libsa/fat.h> +#include <lib/libsa/nfs.h> +#include <lib/libsa/tftp.h> +#include <lib/libsa/netif.h> +#endif +#include <lib/libsa/unixdev.h> +#include <dev/cons.h> +#if 0 +#include "debug.h" +#endif + +const char version[] = "2.06"; +#if 0 +int debug = 1; +#endif + +void (*zaurus_probe1[])(void) = { + cninit +}; +#if 0 +void (*zaurus_probe2[])(void) = { + diskprobe +}; +#endif + +struct zaurus_boot_probes probe_list[] = { + { "probing", zaurus_probe1, NENTS(zaurus_probe1) }, +#if 0 + { "disk", zaurus_probe2, NENTS(zaurus_probe2) } +#endif +}; +int nibprobes = NENTS(probe_list); + + +void (*sa_cleanup)(void) = NULL; + +struct fs_ops file_system[] = { + { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, + ufs_stat, ufs_readdir }, +#ifdef notdef + { fat_open, fat_close, fat_read, fat_write, fat_seek, + fat_stat, fat_readdir }, + { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, + nfs_stat, nfs_readdir }, + { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, + cd9660_stat, cd9660_readdir }, +#endif +#ifdef _TEST + { null_open, null_close, null_read, null_write, null_seek, + null_stat, null_readdir } +#endif +}; +int nfsys = NENTS(file_system); + +struct devsw devsw[] = { + { "UNIX", unixstrategy, unixopen, unixclose, unixioctl }, +#if 0 + { "TFTP", tftpstrategy, tftpopen, tftpclose, tftpioctl }, +#endif +}; +int ndevs = NENTS(devsw); + +#ifdef notdef +struct netif_driver *netif_drivers[] = { + NULL +}; +int n_netif_drivers = NENTS(netif_drivers); +#endif + +struct consdev constab[] = { + { unix_probe, unix_init, unix_getc, unix_putc }, + { NULL } +}; +struct consdev *cn_tab = constab; diff --git a/sys/arch/zaurus/stand/zboot/devopen.c b/sys/arch/zaurus/stand/zboot/devopen.c new file mode 100644 index 00000000000..609b8ac58b2 --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/devopen.c @@ -0,0 +1,170 @@ +/* $OpenBSD: devopen.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ + +/* + * Copyright (c) 1996-1999 Michael Shalayeff + * 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 ``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 HIS RELATIVES 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 MIND, 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 "libsa.h" +#include <sys/param.h> +#include <dev/cons.h> + +extern int debug; + +/* XXX use slot for 'rd' for 'hd' pseudo-device */ +const char bdevs[][4] = { + "wd", "", "fd", "wt", "sd", "st", "cd", "mcd", + "", "", "", "", "", "", "", "scd", "", "hd", "" + +}; +const int nbdevs = NENTS(bdevs); + +const char cdevs[][4] = { + "cn", "", "", "", "", "", "", "", + "com", "", "", "", "pc" +}; +const int ncdevs = NENTS(cdevs); + +/* pass dev_t to the open routines */ +int +devopen(struct open_file *f, const char *fname, char **file) +{ + struct devsw *dp = devsw; + register int i, rc = 1; + + *file = (char *)fname; + +#ifdef DEBUG + if (debug) + printf("devopen:"); +#endif + + for (i = 0; i < ndevs && rc != 0; dp++, i++) { +#ifdef DEBUG + if (debug) + printf(" %s: ", dp->dv_name); +#endif + if ((rc = (*dp->dv_open)(f, file)) == 0) { + f->f_dev = dp; + return 0; + } +#ifdef DEBUG + else if (debug) + printf("%d", rc); +#endif + + } +#ifdef DEBUG + if (debug) + putchar('\n'); +#endif + + if ((f->f_flags & F_NODEV) == 0) + f->f_dev = dp; + + return rc; +} + +void +devboot(dev_t bootdev, char *p) +{ + /* XXX */ + strlcpy(p, "/dev/hda4", 10); +} + +int pch_pos = 0; + +void +putchar(int c) +{ + switch (c) { + case '\177': /* DEL erases */ + cnputc('\b'); + cnputc(' '); + case '\b': + cnputc('\b'); + if (pch_pos) + pch_pos--; + break; + case '\t': + do + cnputc(' '); + while (++pch_pos % 8); + break; + case '\n': + case '\r': + cnputc(c); + pch_pos=0; + break; + default: + cnputc(c); + pch_pos++; + break; + } +} + +int +getchar(void) +{ + register int c = cngetc(); + + if (c == '\r') + c = '\n'; + + if ((c < ' ' && c != '\n') || c == '\177') + return c; + +#if 0 + putchar(c); +#endif + + return c; +} + +char ttyname_buf[8]; + +char * +ttyname(int fd) +{ + snprintf(ttyname_buf, sizeof ttyname_buf, "%s%d", + cdevs[major(cn_tab->cn_dev)], minor(cn_tab->cn_dev)); + + return ttyname_buf; +} + +dev_t +ttydev(char *name) +{ + int i, unit = -1; + char *no = name + strlen(name) - 1; + + while (no >= name && *no >= '0' && *no <= '9') + unit = (unit < 0 ? 0 : (unit * 10)) + *no-- - '0'; + if (no < name || unit < 0) + return NODEV; + for (i = 0; i < ncdevs; i++) + if (strncmp(name, cdevs[i], no - name + 1) == 0) + return (makedev(i, unit)); + return NODEV; +} diff --git a/sys/arch/zaurus/stand/zboot/exec.c b/sys/arch/zaurus/stand/zboot/exec.c new file mode 100644 index 00000000000..1eb03c8f23b --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/exec.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "libsa.h" +#include <lib/libsa/loadfile.h> + +void +run_loadfile(u_long *marks, int howto) +{ + panic("run_loadfile"); +} diff --git a/sys/arch/zaurus/stand/zboot/exit.c b/sys/arch/zaurus/stand/zboot/exit.c new file mode 100644 index 00000000000..e6a93defbad --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/exit.c @@ -0,0 +1,65 @@ +/* $OpenBSD: exit.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ +/* $NetBSD: exit.c,v 1.11 1996/12/01 20:22:19 pk Exp $ */ + +/*- + * Copyright (c) 1993 John Brezak + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 <sys/stdarg.h> + +#include <lib/libsa/stand.h> + +__dead void +panic(const char *fmt, ...) +{ + extern __dead void uexit(int); + extern void closeall(void); + va_list ap; + static int paniced; + + if (!paniced) { + paniced = 1; + closeall(); + } + + va_start(ap, fmt); + vprintf(fmt, ap); + printf("\n"); + va_end(ap); +#if 0 + _rtt(); +#else + uexit(0); +#endif + /*NOTREACHED*/ +} + +void +exit(void) +{ + panic("exit"); +} diff --git a/sys/arch/zaurus/stand/zboot/libsa.h b/sys/arch/zaurus/stand/zboot/libsa.h new file mode 100644 index 00000000000..6d3fc896a8e --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/libsa.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <lib/libsa/stand.h> + +#define EXEC_ELF + +#define DEFAULT_KERNEL_ADDRESS 0xa0200000 + +struct zaurus_boot_probes { + char *name; + void (**probes)(void); + int count; +}; + +extern struct zaurus_boot_probes probe_list[]; +extern int nibprobes; +extern void (*devboot_p)(dev_t, char *); + +#include "compat_linux.h" diff --git a/sys/arch/zaurus/stand/zboot/loadfile.c b/sys/arch/zaurus/stand/zboot/loadfile.c new file mode 100644 index 00000000000..a9e2bcbc9ff --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/loadfile.c @@ -0,0 +1,680 @@ +/* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */ +/* $OpenBSD: loadfile.c,v 1.1 2005/01/10 00:25:03 deraadt 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 of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center and by Christos Zoulas. + * + * 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) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * 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. Neither the name of the University 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 REGENTS 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 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. + * + * @(#)boot.c 8.1 (Berkeley) 6/10/93 + */ + +#ifdef _STANDALONE +#include <lib/libkern/libkern.h> +#include <lib/libsa/stand.h> +#else +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <err.h> +#endif + +#include <sys/param.h> +#include <sys/exec.h> + +#include "compat_linux.h" +#include "pathnames.h" +#include <lib/libsa/loadfile.h> + +#define BOOT_ZBOOT + +#ifdef BOOT_ECOFF +#include <sys/exec_ecoff.h> +static int coff_exec(int, struct ecoff_exechdr *, u_long *, int); +#endif +#ifdef BOOT_ELF +#include <sys/exec_elf.h> +static int elf_exec(int, Elf_Ehdr *, u_long *, int); +#endif +#ifdef BOOT_AOUT +#include <sys/exec_aout.h> +static int aout_exec(int, struct exec *, u_long *, int); +#endif +#ifdef BOOT_ZBOOT +static int zboot_exec(int, u_long *, int); +#endif + +/* + * Open 'filename', read in program and and return 0 if ok 1 on error. + * Fill in marks + */ +int +loadfile(const char *fname, u_long *marks, int flags) +{ + union { +#ifdef BOOT_ECOFF + struct ecoff_exechdr coff; +#endif +#ifdef BOOT_ELF + Elf_Ehdr elf; +#endif +#ifdef BOOT_AOUT + struct exec aout; +#endif + + } hdr; + ssize_t nr; + int fd, rval; + + /* Open the file. */ + if ((fd = open(fname, 0)) < 0) { + WARN(("open %s", fname ? fname : "<default>")); + return -1; + } + + /* Read the exec header. */ + if ((nr = read(fd, &hdr, sizeof(hdr))) != sizeof(hdr)) { + WARN(("read header")); + goto err; + } + +#ifdef BOOT_ECOFF + if (!ECOFF_BADMAG(&hdr.coff)) { + rval = coff_exec(fd, &hdr.coff, marks, flags); + } else +#endif +#ifdef BOOT_ELF + if (memcmp(hdr.elf.e_ident, ELFMAG, SELFMAG) == 0 && + hdr.elf.e_ident[EI_CLASS] == ELFCLASS) { +#ifdef BOOT_ZBOOT + rval = zboot_exec(fd, marks, flags); +#else + rval = elf_exec(fd, &hdr.elf, marks, flags); +#endif + } else +#endif +#ifdef BOOT_AOUT + if (OKMAGIC(N_GETMAGIC(hdr.aout)) +#ifndef NO_MID_CHECK + && N_GETMID(hdr.aout) == MID_MACHINE +#endif + ) { + rval = aout_exec(fd, &hdr.aout, marks, flags); + } else +#endif + { + rval = 1; + errno = EFTYPE; + WARN(("%s", fname ? fname : "<default>")); + } + + if (rval == 0) { + PROGRESS(("=0x%lx\n", marks[MARK_END] - marks[MARK_START])); + return fd; + } +err: + (void)close(fd); + return -1; +} + +#ifdef BOOT_ECOFF +static int +coff_exec(int fd, struct ecoff_exechdr *coff, u_long *marks, int flags) +{ + paddr_t offset = marks[MARK_START]; + paddr_t minp = ~0, maxp = 0, pos; + + /* Read in text. */ + if (lseek(fd, ECOFF_TXTOFF(coff), SEEK_SET) == -1) { + WARN(("lseek text")); + return 1; + } + + if (coff->a.tsize != 0) { + if (flags & LOAD_TEXT) { + PROGRESS(("%lu", coff->a.tsize)); + if (READ(fd, coff->a.text_start, coff->a.tsize) != + coff->a.tsize) { + return 1; + } + } + else { + if (lseek(fd, coff->a.tsize, SEEK_CUR) == -1) { + WARN(("read text")); + return 1; + } + } + if (flags & (COUNT_TEXT|LOAD_TEXT)) { + pos = coff->a.text_start; + if (minp > pos) + minp = pos; + pos += coff->a.tsize; + if (maxp < pos) + maxp = pos; + } + } + + /* Read in data. */ + if (coff->a.dsize != 0) { + if (flags & LOAD_DATA) { + PROGRESS(("+%lu", coff->a.dsize)); + if (READ(fd, coff->a.data_start, coff->a.dsize) != + coff->a.dsize) { + WARN(("read data")); + return 1; + } + } + if (flags & (COUNT_DATA|LOAD_DATA)) { + pos = coff->a.data_start; + if (minp > pos) + minp = pos; + pos += coff->a.dsize; + if (maxp < pos) + maxp = pos; + } + } + + /* Zero out bss. */ + if (coff->a.bsize != 0) { + if (flags & LOAD_BSS) { + PROGRESS(("+%lu", coff->a.bsize)); + BZERO(coff->a.bss_start, coff->a.bsize); + } + if (flags & (COUNT_BSS|LOAD_BSS)) { + pos = coff->a.bss_start; + if (minp > pos) + minp = pos; + pos = coff->a.bsize; + if (maxp < pos) + maxp = pos; + } + } + + marks[MARK_START] = LOADADDR(minp); + marks[MARK_ENTRY] = LOADADDR(coff->a.entry); + marks[MARK_NSYM] = 1; /* XXX: Kernel needs >= 0 */ + marks[MARK_SYM] = LOADADDR(maxp); + marks[MARK_END] = LOADADDR(maxp); + return 0; +} +#endif /* BOOT_ECOFF */ + +#ifdef BOOT_ELF +static int +elf_exec(int fd, Elf_Ehdr *elf, u_long *marks, int flags) +{ + Elf_Shdr *shp; + Elf_Phdr *phdr; + Elf_Off off; + int i; + size_t sz; + int first; + int havesyms; + paddr_t minp = ~0, maxp = 0, pos = 0; + paddr_t offset = marks[MARK_START], shpp, elfp; + + sz = elf->e_phnum * sizeof(Elf_Phdr); + phdr = ALLOC(sz); + + if (lseek(fd, elf->e_phoff, SEEK_SET) == -1) { + WARN(("lseek phdr")); + FREE(phdr, sz); + return 1; + } + if (read(fd, phdr, sz) != sz) { + WARN(("read program headers")); + FREE(phdr, sz); + return 1; + } + + for (first = 1, i = 0; i < elf->e_phnum; i++) { + + if (phdr[i].p_type != PT_LOAD || + (phdr[i].p_flags & (PF_W|PF_R|PF_X)) == 0) + continue; + +#define IS_TEXT(p) (p.p_flags & PF_X) +#define IS_DATA(p) ((p.p_flags & PF_X) == 0) +#define IS_BSS(p) (p.p_filesz < p.p_memsz) + /* + * XXX: Assume first address is lowest + */ + if ((IS_TEXT(phdr[i]) && (flags & LOAD_TEXT)) || + (IS_DATA(phdr[i]) && (flags & LOAD_DATA))) { + + /* Read in segment. */ + PROGRESS(("%s%lu", first ? "" : "+", + (u_long)phdr[i].p_filesz)); + + if (lseek(fd, phdr[i].p_offset, SEEK_SET) == -1) { + WARN(("lseek text")); + FREE(phdr, sz); + return 1; + } + if (READ(fd, phdr[i].p_vaddr, phdr[i].p_filesz) != + phdr[i].p_filesz) { + WARN(("read text")); + FREE(phdr, sz); + return 1; + } + first = 0; + + } + if ((IS_TEXT(phdr[i]) && (flags & (LOAD_TEXT|COUNT_TEXT))) || + (IS_DATA(phdr[i]) && (flags & (LOAD_DATA|COUNT_TEXT)))) { + pos = phdr[i].p_vaddr; + if (minp > pos) + minp = pos; + pos += phdr[i].p_filesz; + if (maxp < pos) + maxp = pos; + } + + /* Zero out bss. */ + if (IS_BSS(phdr[i]) && (flags & LOAD_BSS)) { + PROGRESS(("+%lu", + (u_long)(phdr[i].p_memsz - phdr[i].p_filesz))); + BZERO((phdr[i].p_vaddr + phdr[i].p_filesz), + phdr[i].p_memsz - phdr[i].p_filesz); + } + if (IS_BSS(phdr[i]) && (flags & (LOAD_BSS|COUNT_BSS))) { + pos += phdr[i].p_memsz - phdr[i].p_filesz; + if (maxp < pos) + maxp = pos; + } + } + FREE(phdr, sz); + + /* + * Copy the ELF and section headers. + */ + elfp = maxp = roundup(maxp, sizeof(long)); + if (flags & (LOAD_HDR|COUNT_HDR)) + maxp += sizeof(Elf_Ehdr); + + if (flags & (LOAD_SYM|COUNT_SYM)) { + if (lseek(fd, elf->e_shoff, SEEK_SET) == -1) { + WARN(("lseek section headers")); + return 1; + } + sz = elf->e_shnum * sizeof(Elf_Shdr); + shp = ALLOC(sz); + + if (read(fd, shp, sz) != sz) { + WARN(("read section headers")); + return 1; + } + + shpp = maxp; + maxp += roundup(sz, sizeof(long)); + + /* + * Now load the symbol sections themselves. Make sure the + * sections are aligned. Don't bother with string tables if + * there are no symbol sections. + */ + off = roundup((sizeof(Elf_Ehdr) + sz), sizeof(long)); + + for (havesyms = i = 0; i < elf->e_shnum; i++) + if (shp[i].sh_type == SHT_SYMTAB) + havesyms = 1; + + for (first = 1, i = 0; i < elf->e_shnum; i++) { + if (shp[i].sh_type == SHT_SYMTAB || + shp[i].sh_type == SHT_STRTAB) { + if (havesyms && (flags & LOAD_SYM)) { + PROGRESS(("%s%ld", first ? " [" : "+", + (u_long)shp[i].sh_size)); + if (lseek(fd, shp[i].sh_offset, + SEEK_SET) == -1) { + WARN(("lseek symbols")); + FREE(shp, sz); + return 1; + } + if (READ(fd, maxp, shp[i].sh_size) != + shp[i].sh_size) { + WARN(("read symbols")); + FREE(shp, sz); + return 1; + } + } + maxp += roundup(shp[i].sh_size, + sizeof(long)); + shp[i].sh_offset = off; + off += roundup(shp[i].sh_size, sizeof(long)); + first = 0; + } + } + if (flags & LOAD_SYM) { + BCOPY(shp, shpp, sz); + + if (havesyms && first == 0) + PROGRESS(("]")); + } + FREE(shp, sz); + } + + /* + * Frob the copied ELF header to give information relative + * to elfp. + */ + if (flags & LOAD_HDR) { + elf->e_phoff = 0; + elf->e_shoff = sizeof(Elf_Ehdr); + elf->e_phentsize = 0; + elf->e_phnum = 0; + BCOPY(elf, elfp, sizeof(*elf)); + } + + marks[MARK_START] = LOADADDR(minp); + marks[MARK_ENTRY] = LOADADDR(elf->e_entry); + marks[MARK_NSYM] = 1; /* XXX: Kernel needs >= 0 */ + marks[MARK_SYM] = LOADADDR(elfp); + marks[MARK_END] = LOADADDR(maxp); + return 0; +} +#endif /* BOOT_ELF */ + +#ifdef BOOT_AOUT +static int +aout_exec(int fd, struct exec *x, u_long *marks, int flags) +{ + u_long entry = x->a_entry; + paddr_t aoutp = 0; + paddr_t minp, maxp; + int cc; + paddr_t offset = marks[MARK_START]; + u_long magic = N_GETMAGIC(*x); + int sub; + + /* In OMAGIC and NMAGIC, exec header isn't part of text segment */ + if (magic == OMAGIC || magic == NMAGIC) + sub = 0; + else + sub = sizeof(*x); + + minp = maxp = ALIGNENTRY(entry); + + if (lseek(fd, sizeof(*x), SEEK_SET) == -1) { + WARN(("lseek text")); + return 1; + } + + /* + * Leave a copy of the exec header before the text. + * The kernel may use this to verify that the + * symbols were loaded by this boot program. + */ + if (magic == OMAGIC || magic == NMAGIC) { + if (flags & LOAD_HDR && maxp >= sizeof(*x)) + BCOPY(x, maxp - sizeof(*x), sizeof(*x)); + } + else { + if (flags & LOAD_HDR) + BCOPY(x, maxp, sizeof(*x)); + if (flags & (LOAD_HDR|COUNT_HDR)) + maxp += sizeof(*x); + } + + /* + * Read in the text segment. + */ + if (flags & LOAD_TEXT) { + PROGRESS(("%ld", x->a_text)); + + if (READ(fd, maxp, x->a_text - sub) != x->a_text - sub) { + WARN(("read text")); + return 1; + } + } else { + if (lseek(fd, x->a_text - sub, SEEK_CUR) == -1) { + WARN(("seek text")); + return 1; + } + } + if (flags & (LOAD_TEXT|COUNT_TEXT)) + maxp += x->a_text - sub; + + /* + * Provide alignment if required + */ + if (magic == ZMAGIC || magic == NMAGIC) { + int size = -(unsigned int)maxp & (__LDPGSZ - 1); + + if (flags & LOAD_TEXTA) { + PROGRESS(("/%d", size)); + BZERO(maxp, size); + } + + if (flags & (LOAD_TEXTA|COUNT_TEXTA)) + maxp += size; + } + + /* + * Read in the data segment. + */ + if (flags & LOAD_DATA) { + PROGRESS(("+%ld", x->a_data)); + + if (READ(fd, maxp, x->a_data) != x->a_data) { + WARN(("read data")); + return 1; + } + } + else { + if (lseek(fd, x->a_data, SEEK_CUR) == -1) { + WARN(("seek data")); + return 1; + } + } + if (flags & (LOAD_DATA|COUNT_DATA)) + maxp += x->a_data; + + /* + * Zero out the BSS section. + * (Kernel doesn't care, but do it anyway.) + */ + if (flags & LOAD_BSS) { + PROGRESS(("+%ld", x->a_bss)); + + BZERO(maxp, x->a_bss); + } + + if (flags & (LOAD_BSS|COUNT_BSS)) + maxp += x->a_bss; + + /* + * Read in the symbol table and strings. + * (Always set the symtab size word.) + */ + if (flags & LOAD_SYM) + BCOPY(&x->a_syms, maxp, sizeof(x->a_syms)); + + if (flags & (LOAD_SYM|COUNT_SYM)) { + maxp += sizeof(x->a_syms); + aoutp = maxp; + } + + if (x->a_syms > 0) { + /* Symbol table and string table length word. */ + + if (flags & LOAD_SYM) { + PROGRESS(("+[%ld", x->a_syms)); + + if (READ(fd, maxp, x->a_syms) != x->a_syms) { + WARN(("read symbols")); + return 1; + } + } else { + if (lseek(fd, x->a_syms, SEEK_CUR) == -1) { + WARN(("seek symbols")); + return 1; + } + } + if (flags & (LOAD_SYM|COUNT_SYM)) + maxp += x->a_syms; + + if (read(fd, &cc, sizeof(cc)) != sizeof(cc)) { + WARN(("read string table")); + return 1; + } + + if (flags & LOAD_SYM) { + BCOPY(&cc, maxp, sizeof(cc)); + + /* String table. Length word includes itself. */ + + PROGRESS(("+%d]", cc)); + } + if (flags & (LOAD_SYM|COUNT_SYM)) + maxp += sizeof(cc); + + cc -= sizeof(int); + if (cc <= 0) { + WARN(("symbol table too short")); + return 1; + } + + if (flags & LOAD_SYM) { + if (READ(fd, maxp, cc) != cc) { + WARN(("read strings")); + return 1; + } + } else { + if (lseek(fd, cc, SEEK_CUR) == -1) { + WARN(("seek strings")); + return 1; + } + } + if (flags & (LOAD_SYM|COUNT_SYM)) + maxp += cc; + } + + marks[MARK_START] = LOADADDR(minp); + marks[MARK_ENTRY] = LOADADDR(entry); + marks[MARK_NSYM] = x->a_syms; + marks[MARK_SYM] = LOADADDR(aoutp); + marks[MARK_END] = LOADADDR(maxp); + return 0; +} +#endif /* BOOT_AOUT */ + +#ifdef BOOT_ZBOOT +static int +zboot_exec(int fd, u_long *marks, int flags) +{ + char buf[512]; + int tofd; + int sz; + int total = 0; + + tofd = uopen(_PATH_ZBOOT, O_WRONLY); + if (tofd == -1) { + printf("%s: can't open (errno %d)\n", _PATH_ZBOOT, errno); + return 1; + } + + if (lseek(fd, 0, SEEK_SET) != 0) { + printf("%s: seek error\n", _PATH_ZBOOT); + goto err; + } + + while ((sz = read(fd, buf, sizeof(buf))) == sizeof(buf)) { + if ((sz = uwrite(tofd, buf, sz)) != sizeof(buf)) { + printf("%s: write error\n", _PATH_ZBOOT); + goto err; + } + total += sz; + } + + if (sz < 0) { + printf("zboot_exec: read error\n"); + goto err; + } + + if (sz >= 0 && uwrite(tofd, buf, sz) != sz) { + printf("zboot_exec: write error\n"); + goto err; + } + total += sz; + + /* + * Module is now armed. Reboot is triggered in run_loadfile(). + */ + + printf("zboot_exec: %d bytes written\n", total); + + close(tofd); + return 0; + +err: + close(tofd); + return 1; +} +#endif /* BOOT_ZBOOT */ diff --git a/sys/arch/zaurus/stand/zboot/machdep.c b/sys/arch/zaurus/stand/zboot/machdep.c new file mode 100644 index 00000000000..a8db8cb0dd5 --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/machdep.c @@ -0,0 +1,57 @@ +/* $OpenBSD: machdep.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ + +/* + * Copyright (c) 2004 Tom Cosgrove + * Copyright (c) 1997-1999 Michael Shalayeff + * 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 ``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 HIS RELATIVES 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 MIND, 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 "libsa.h" + +char _alloc_heap[4 * 1024 * 1024]; + +int debug; + +void +machdep(void) +{ + int i, j; + struct zaurus_boot_probes *pr; + + /* + * The list of probe routines is now in conf.c. + */ + for (i = 0; i < nibprobes; i++) { + pr = &probe_list[i]; + if (pr != NULL) { + printf("%s: ", pr->name); + + for (j = 0; j < pr->count; j++) { + (*(pr->probes)[j])(); + } + + printf("\n"); + } + } +} diff --git a/sys/arch/zaurus/stand/zboot/pathnames.h b/sys/arch/zaurus/stand/zboot/pathnames.h new file mode 100644 index 00000000000..401c8952d75 --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/pathnames.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define _PATH_ZBOOT "/dev/zboot" diff --git a/sys/arch/zaurus/stand/zboot/unixdev.c b/sys/arch/zaurus/stand/zboot/unixdev.c new file mode 100644 index 00000000000..36f1ab9220f --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/unixdev.c @@ -0,0 +1,191 @@ +/* $OpenBSD: unixdev.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $ */ + +/* + * Copyright (c) 1996-1998 Michael Shalayeff + * 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 ``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. + * + */ + +#include <sys/param.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/syscall.h> +#define open uopen +#include <sys/fcntl.h> +#include <dev/cons.h> +#undef open +#include "libsa.h" +#include <lib/libsa/unixdev.h> + +int +unixstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf, + size_t *rsize) +{ + int rc = 0; + +#ifdef UNIX_DEBUG + printf("unixstrategy: %s %d bytes @ %d\n", + (rw==F_READ?"reading":"writing"), size, blk); +#endif + if ((rc = ulseek((int)devdata, blk * DEV_BSIZE, 0)) >= 0) + rc = (rw==F_READ) ? uread((int)devdata, buf, size) : + uwrite((int)devdata, buf, size); + + if (rc >= 0) { + *rsize = (size_t)rc; + rc = 0; + } else + rc = errno; + + return rc; +} + +int +unixopen(struct open_file *f, ...) +{ + char **file, *p = NULL; + va_list ap; + int fd; + + va_start(ap, f); + file = va_arg(ap, char **); + va_end(ap); + +#ifdef UNIX_DEBUG + printf("unixopen: %s\n", *file); +#endif + + if (strncmp("/dev/", *file, 5) == 0) { + /* p = strchr(p + 5, '/') */ + for (p = *file + 5; *p != '\0' && *p != '/'; p++) + ; + if (*(p-1) == ':') + *(p-1) = '\0'; + if (*p == '/') + *p = '\0'; + } + +#if 0 + f->f_devdata = (void *)(fd = uopen(*file, O_RDWR, 0)); +#else + f->f_devdata = (void *)(fd = uopen(*file, O_RDONLY, 0)); +#endif + + *file = p; + if (p != NULL) + *p = '/'; + + return fd < 0 ? -1 : 0; +} + +int +unixclose(struct open_file *f) +{ + return uclose((int)f->f_devdata); +} + +int +unixioctl(struct open_file *f, u_long cmd, void *data) +{ + return uioctl((int)f->f_devdata, cmd, data); +} + +#if 0 +off_t +ulseek(int fd, off_t off, int wh) +{ + return __syscall((quad_t)SYS_lseek, fd, 0, off, wh); +} +#endif + + +void +unix_probe(struct consdev *cn) +{ + cn->cn_pri = CN_INTERNAL; + cn->cn_dev = makedev(0,0); + printf("ux%d ", minor(cn->cn_dev)); +} + +void +unix_init(struct consdev *cn) +{ +} + +void +unix_putc(dev_t dev, int c) +{ + uwrite(1, &c, 1); +} + +int +unix_getc(dev_t dev) +{ + if (dev & 0x80) { + struct timeval tv; + fd_set fdset; + int rc; + + tv.tv_sec = 0; + tv.tv_usec = 100000; + FD_ZERO(&fdset); + FD_SET(0, &fdset); + + if ((rc = syscall(SYS_select, 1, &fdset, NULL, NULL, &tv)) <= 0) + return 0; + else + return 1; + } else { + char c; + + return uread(0, &c, 1)<1? -1: c; + } +} + +time_t +getsecs(void) +{ + return 1; +} + +void +time_print(void) +{ +} + +void +atexit(void) +{ +} + +int +cnspeed(dev_t dev, int sp) +{ + return 9600; +} + +void +__main(void) +{ +} diff --git a/sys/arch/zaurus/stand/zboot/unixsys.S b/sys/arch/zaurus/stand/zboot/unixsys.S new file mode 100644 index 00000000000..16665d5bb3f --- /dev/null +++ b/sys/arch/zaurus/stand/zboot/unixsys.S @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <machine/asm.h> + +#include "compat_linux.h" + + .text + +#define RSYSCALL(x) \ + ENTRY(u##x); \ + swi __NR_##x; \ + b 1f + +RSYSCALL(open) +RSYSCALL(read) +RSYSCALL(write) +RSYSCALL(lseek) +RSYSCALL(ioctl) +RSYSCALL(close) +RSYSCALL(exit) + +1: + cmn r0, #4096 + movcc pc, lr + rsb r0, r0, #0 + ldr r1, Lerrno /* XXX clobbers arg1 */ + str r0, [r1] + mvn r0, #0 + mov pc, lr + +Lerrno: + .word errno + +ENTRY(__syscall) +ENTRY(syscall) + swi __NR_syscall + b 1b + + .data + .global errno +errno: + .word 0 |