diff options
Diffstat (limited to 'sys/boot/arc/lib')
-rw-r--r-- | sys/boot/arc/lib/Makefile | 35 | ||||
-rw-r--r-- | sys/boot/arc/lib/abort.c | 38 | ||||
-rw-r--r-- | sys/boot/arc/lib/arcconsole.c | 107 | ||||
-rw-r--r-- | sys/boot/arc/lib/arcdisk.c | 361 | ||||
-rw-r--r-- | sys/boot/arc/lib/arch/alpha/copy.c | 71 | ||||
-rw-r--r-- | sys/boot/arc/lib/arch/alpha/rpb.c | 196 | ||||
-rw-r--r-- | sys/boot/arc/lib/arch/alpha/setjmp.S | 95 | ||||
-rw-r--r-- | sys/boot/arc/lib/arch/alpha/start.S | 63 | ||||
-rw-r--r-- | sys/boot/arc/lib/bootinfo.c | 203 | ||||
-rw-r--r-- | sys/boot/arc/lib/delay.c | 38 | ||||
-rw-r--r-- | sys/boot/arc/lib/devicename.c | 235 | ||||
-rw-r--r-- | sys/boot/arc/lib/elf_freebsd.c | 143 | ||||
-rw-r--r-- | sys/boot/arc/lib/module.c | 48 | ||||
-rw-r--r-- | sys/boot/arc/lib/prom.c | 39 | ||||
-rw-r--r-- | sys/boot/arc/lib/setjmperr.c | 38 | ||||
-rw-r--r-- | sys/boot/arc/lib/time.c | 41 |
16 files changed, 1751 insertions, 0 deletions
diff --git a/sys/boot/arc/lib/Makefile b/sys/boot/arc/lib/Makefile new file mode 100644 index 0000000..7944374 --- /dev/null +++ b/sys/boot/arc/lib/Makefile @@ -0,0 +1,35 @@ +# $FreeBSD$ + +LIB= arc +INTERNALLIB= true + +CFLAGS+= -ffreestanding +.PATH: ${.CURDIR}/arch/${MACHINE_ARCH} +# XXX hack to pick up stand.h +LIBSTANDDIR= ${.CURDIR}/../../../../lib/libstand +CFLAGS+= -I${LIBSTANDDIR} +CFLAGS+= -DDEBUG + +# Pick up the bootstrap header for some interface items +CFLAGS+= -I${.CURDIR}/../../common -mno-fp-regs \ + -I${.CURDIR}/../../.. -I${.CURDIR}/../include + +#CFLAGS+= -DDISK_DEBUG +#CPPFLAGS+= -DNO_DISKLABEL +#CPPFLAGS+= -DSAVE_MEMORY + +SRCS= delay.c time.c abort.c setjmperr.c copy.c devicename.c module.c \ + arcconsole.c arcdisk.c elf_freebsd.c bootinfo.c + +.if ${MACHINE_ARCH} == "alpha" +SRCS+= rpb.c +.endif + +CLEANFILES+= machine + +machine: + ln -sf ${.CURDIR}/../../../alpha/include machine + +.include <bsd.lib.mk> + +beforedepend ${OBJS}: machine diff --git a/sys/boot/arc/lib/abort.c b/sys/boot/arc/lib/abort.c new file mode 100644 index 0000000..4e5951b --- /dev/null +++ b/sys/boot/arc/lib/abort.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +abort() +{ + FwReboot(); +} diff --git a/sys/boot/arc/lib/arcconsole.c b/sys/boot/arc/lib/arcconsole.c new file mode 100644 index 0000000..9607b6b --- /dev/null +++ b/sys/boot/arc/lib/arcconsole.c @@ -0,0 +1,107 @@ +/* $FreeBSD$ */ +/* $NetBSD: prom.c,v 1.3 1997/09/06 14:03:58 drochner Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * 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 Mellon + * the rights to redistribute these changes. + */ + +#include <sys/types.h> + +#include "bootstrap.h" +#include "arctypes.h" +#include "arcfuncs.h" + +int console; + +static void arc_probe(struct console *cp); +static int arc_init(int); +static void arc_putchar(int); +static int arc_getchar(void); +static int arc_poll(void); + +struct console arcconsole = { + "arc", + "ARC firmware console", + 0, + arc_probe, + arc_init, + arc_putchar, + arc_getchar, + arc_poll, +}; + +static void +arc_probe(struct console *cp) +{ + cp->c_flags |= C_PRESENTIN|C_PRESENTOUT; +} + +static int +arc_init(int arg) +{ + return 0; +} + +static void +arc_putchar(int c) +{ + char cbuf = c; + u_int32_t count; + + Write(StandardOut, &cbuf, 1, &count); +} + +static int saved_char = -1; + +int +arc_getchar() +{ + char cbuf; + u_int32_t count; + + arc_putchar('_'); + arc_putchar('\b'); + Read(StandardIn, &cbuf, 1, &count); + arc_putchar(' '); + arc_putchar('\b'); + if (count == 1) + return cbuf; + else + return -1; +} + +int +arc_poll() +{ + return GetReadStatus(StandardIn) == ESUCCESS; +} + +int +arc_open(dev, len) + char *dev; + int len; +{ + return 0; +} diff --git a/sys/boot/arc/lib/arcdisk.c b/sys/boot/arc/lib/arcdisk.c new file mode 100644 index 0000000..4171505 --- /dev/null +++ b/sys/boot/arc/lib/arcdisk.c @@ -0,0 +1,361 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * Copyright (c) 1998 Doug Rabson <dfr@freebsd.org> + * 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$ + */ + +/* + * ARC disk device handling. + * + * Ideas and algorithms from: + * + * - NetBSD libi386/biosdisk.c + * - FreeBSD biosboot/disk.c + * + */ + +#include <stand.h> + + +#include <machine/stdarg.h> + +#include "bootstrap.h" +#include "libarc.h" +#include "arctypes.h" +#include "arcfuncs.h" + +#define ARCDISK_SECSIZE 512 + +#define BUFSIZE (1 * ARCDISK_SECSIZE) +#define MAXBDDEV MAXDEV + +#ifdef DISK_DEBUG +# define D(x) x +#else +# define D(x) +#endif + +static int bd_init(void); +static int bd_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); +static int bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); +static int bd_open(struct open_file *f, ...); +static int bd_close(struct open_file *f); +static void bd_print(int verbose); + +struct open_disk { + int od_fd; + int od_unit; /* our unit number */ + int od_boff; /* block offset from beginning of ARC disk */ + int od_flags; +#define BD_FLOPPY (1<<2) + u_char od_buf[BUFSIZE]; /* transfer buffer (do we want/need this?) */ +}; + +struct devsw arcdisk = { + "disk", + DEVT_DISK, + bd_init, + bd_strategy, + bd_open, + bd_close, + noioctl, + bd_print +}; + +/* + * List of ARC devices, translation from disk unit number to + * ARC unit number. + */ +static struct +{ + char bd_name[64]; + int bd_unit; /* ARC unit number */ + int bd_namelen; + int bd_flags; +} bdinfo [MAXBDDEV]; +static int nbdinfo = 0; + +/* + * Quiz ARC for disk devices, save a little info about them. + */ +static int +bd_init(void) +{ + nbdinfo++; + + return (0); +} + +/* + * Print information about disks + */ +static void +bd_print(int verbose) +{ + int i; + char line[80]; + + for (i = 0; i < nbdinfo; i++) { + sprintf(line, " disk%d: ARC drive %s", i, bdinfo[i].bd_name); + pager_output(line); + /* XXX more detail? */ + pager_output("\n"); + } +} + +/* + * Attempt to open the disk described by (dev) for use by (f). + * + * Note that the philosophy here is "give them exactly what + * they ask for". This is necessary because being too "smart" + * about what the user might want leads to complications. + * (eg. given no slice or partition value, with a disk that is + * sliced - are they after the first BSD slice, or the DOS + * slice before it?) + */ +static int +bd_open(struct open_file *f, ...) +{ + struct arc_devdesc *dev; + struct dos_partition *dptr; + struct open_disk *od; + struct disklabel *lp; + int sector, slice, i; + int error; + int unit; + u_int32_t fd; + va_list ap; + + va_start(ap, f); + dev = va_arg(ap, struct arc_devdesc *); + va_end(ap); + + unit = dev->d_kind.arcdisk.unit; + if (unit >= nbdinfo) { + D(printf("attempt to open nonexistent disk\n")); + return(ENXIO); + } + + if (Open("scsi(0)disk(0)rdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + if (Open("scsi(0)disk(1)rdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + if (Open("multi(0)disk(0)fdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + return(ENXIO); + + od = (struct open_disk *) malloc(sizeof(struct open_disk)); + if (!od) { + D(printf("arcdiskopen: no memory\n")); + return (ENOMEM); + } + + /* Look up ARC unit number, intialise open_disk structure */ + od->od_fd = fd; + od->od_unit = dev->d_kind.arcdisk.unit; + od->od_flags = bdinfo[od->od_unit].bd_flags; + od->od_boff = 0; + error = 0; + +#if 0 + /* Get geometry for this open (removable device may have changed) */ + if (set_geometry(&od->od_ll)) { + D(printf("bd_open: can't get geometry\n")); + error = ENXIO; + goto out; + } +#endif + + /* + * Following calculations attempt to determine the correct value + * for d->od_boff by looking for the slice and partition specified, + * or searching for reasonable defaults. + */ + +#if 0 + /* + * Find the slice in the DOS slice table. + */ + if (readsects(&od->od_ll, 0, 1, od->od_buf, 0)) { + D(printf("bd_open: error reading MBR\n")); + error = EIO; + goto out; + } + + /* + * Check the slice table magic. + */ + if ((od->od_buf[0x1fe] != 0xff) || (od->od_buf[0x1ff] != 0xaa)) { + /* If a slice number was explicitly supplied, this is an error */ + if (dev->d_kind.arcdisk.slice > 0) { + D(printf("bd_open: no slice table/MBR (no magic)\n")); + error = ENOENT; + goto out; + } + sector = 0; + goto unsliced; /* may be a floppy */ + } + dptr = (struct dos_partition *) & od->od_buf[DOSPARTOFF]; + + /* + * XXX No support here for 'extended' slices + */ + if (dev->d_kind.arcdisk.slice <= 0) { + /* + * Search for the first FreeBSD slice; this also works on "unsliced" + * disks, as they contain a "historically bogus" MBR. + */ + for (i = 0; i < NDOSPART; i++, dptr++) + if (dptr->dp_typ == DOSPTYP_386BSD) { + sector = dptr->dp_start; + break; + } + /* Did we find something? */ + if (sector == -1) { + error = ENOENT; + goto out; + } + } else { + /* + * Accept the supplied slice number unequivocally (we may be looking + * for a DOS partition) if we can handle it. + */ + if ((dev->d_kind.arcdisk.slice > NDOSPART) || (dev->d_kind.arcdisk.slice < 1)) { + error = ENOENT; + goto out; + } + dptr += (dev->d_kind.arcdisk.slice - 1); + sector = dptr->dp_start; + } + unsliced: + +#else + sector = 0; +#endif + /* + * Now we have the slice, look for the partition in the disklabel if we have + * a partition to start with. + */ + if (dev->d_kind.arcdisk.partition < 0) { + od->od_boff = sector; /* no partition, must be after the slice */ + } else { + if (bd_strategy(od, F_READ, sector + LABELSECTOR, 512, od->od_buf, 0)) { + D(printf("bd_open: error reading disklabel\n")); + error = EIO; + goto out; + } + lp = (struct disklabel *) (od->od_buf + LABELOFFSET); + if (lp->d_magic != DISKMAGIC) { + D(printf("bd_open: no disklabel\n")); + error = ENOENT; + goto out; + + } else if (dev->d_kind.arcdisk.partition >= lp->d_npartitions) { + + /* + * The partition supplied is out of bounds; this is fatal. + */ + D(printf("partition '%c' exceeds partitions in table (a-'%c')\n", + 'a' + dev->d_kind.arcdisk.partition, 'a' + lp->d_npartitions)); + error = EPART; + goto out; + + } else { + + /* + * Complain if the partition type is wrong and it shouldn't be, but + * regardless accept this partition. + */ + D(if ((lp->d_partitions[dev->d_kind.arcdisk.partition].p_fstype == FS_UNUSED) && + !(od->od_flags & BD_FLOPPY)) /* Floppies often have bogus fstype */ + printf("bd_open: warning, partition marked as unused\n");); + + od->od_boff = lp->d_partitions[dev->d_kind.arcdisk.partition].p_offset; + } + } + /* + * Save our context + */ + f->f_devdata = od; + + out: + if (error) + free(od); + return(error); +} + +static int +bd_close(struct open_file *f) +{ + struct open_disk *od = f->f_devdata; + + Close(od->od_fd); + + free(od); + f->f_devdata = NULL; + return(0); +} + +static int +bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) +{ + struct bcache_devdata bcd; + struct arc_devdesc *dev = (struct arc_devdesc *)devdata; + + bcd.dv_strategy = bd_realstrategy; + bcd.dv_devdata = devdata; + return(bcache_strategy(&bcd, dev->d_kind.arcdisk.unit, rw, dblk, size, + buf, rsize)); +} + +static int +bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize) +{ + struct open_disk *od = (struct open_disk *)devdata; + fpos_t seek; + u_int32_t count; + + if (size % ARCDISK_SECSIZE) + panic("bd_strategy: I/O not block multiple"); + + if (flag != F_READ) + return(EROFS); + + if (rsize) + *rsize = 0; + + seek = 512 * (dblk + od->od_boff); + Seek(od->od_fd, &seek, SeekAbsolute); + if (Read(od->od_fd, buf, size, &count) != ESUCCESS) { + D(printf("read error\n")); + return (EIO); + } + + if (rsize) + *rsize = count; + return (0); +} + diff --git a/sys/boot/arc/lib/arch/alpha/copy.c b/sys/boot/arc/lib/arch/alpha/copy.c new file mode 100644 index 0000000..2847812 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/copy.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 <stand.h> +#include <machine/alpha_cpu.h> + +#include "libarc.h" + +/* + * Convert from a 64bit superpage address to a 32bit arc superpage address. + */ +static void * +convert_superpage(vm_offset_t p) +{ + if (p < ALPHA_K0SEG_BASE || p >= ALPHA_K0SEG_END) { + printf("stupid address %p\n", (void *)p); + panic("broken"); + } + return (void *) (0xffffffff80000000 + (p - ALPHA_K0SEG_BASE)); +} + +int +arc_copyin(void *src, vm_offset_t dest, size_t len) +{ + bcopy(src, convert_superpage(dest), len); + return(len); +} + +int +arc_copyout(vm_offset_t src, void *dest, size_t len) +{ + bcopy(convert_superpage(src), dest, len); + return(len); +} + +int +arc_readin(int fd, vm_offset_t dest, size_t len) +{ + return(read(fd, convert_superpage(dest), len)); +} + + diff --git a/sys/boot/arc/lib/arch/alpha/rpb.c b/sys/boot/arc/lib/arch/alpha/rpb.c new file mode 100644 index 0000000..4923461 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/rpb.c @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 <stand.h> +#include <machine/rpb.h> +#include "arctypes.h" +#include "arcfuncs.h" + +struct rpb RPB = { + 0, /* rpb_phys */ + {"HWRPB"}, /* rpb_magic */ + HWRPB_DSRDB_MINVERS, /* rpb_version */ + sizeof(struct rpb), /* rpb_size */ + 0, /* rpb_primary_cpu_id */ + 8192, /* rpb_page_size */ + 43, /* rpb_phys_addr_size */ + 0, /* rpb_max_asn */ + {0}, /* rpb_ssn */ + ST_EB164, /* rpb_type */ + SV_ST_ALPHAPC164LX_533, /* rpb_variation */ + {"0000"}, /* rpb_revision */ + 1024*4096, /* rpb_intr_freq */ + 533*1024*1024, /* rpb_cc_freq */ + 0, /* rpb_vptb */ + 0, /* rpb_reserved_arch */ + 0, /* rpb_tbhint_off */ + 0, /* rpb_pcs_cnt */ + 0, /* rpb_pcs_size */ + 0, /* rpb_pcs_off */ + 0, /* rpb_ctb_cnt */ + 0, /* rpb_ctb_size */ + 0, /* rpb_ctb_off */ + 0, /* rpb_crb_off */ + 0, /* rpb_memdat_off */ + 0, /* rpb_condat_off */ + 0, /* rpb_fru_off */ + 0, /* rpb_save_term */ + 0, /* rpb_save_term_val */ + 0, /* rpb_rest_term */ + 0, /* rpb_rest_term_val */ + 0, /* rpb_restart */ + 0, /* rpb_restart_val */ + 0, /* rpb_reserve_os */ + 0, /* rpb_reserve_hw */ + 0, /* rpb_checksum */ + 0, /* rpb_rxrdy */ + 0, /* rpb_txrdy */ + 0, /* rpb_dsrdb_off */ + {0}, /* rpb_rpb_tbhint */ +}; + +#define ROUNDUP(x) (((x) + sizeof(u_int64_t) - 1) \ + & ~(sizeof(u_int64_t) - 1)) + +u_int64_t +checksum(void *p, size_t size) +{ + u_int64_t sum = 0; + u_int64_t *lp = (u_int64_t *)p; + int i; + + printf("checksum(%p, %d)\n", p, size); + size = ROUNDUP(size) / sizeof(u_int64_t); + for (i = 0; i < size; i++) + sum += lp[i]; +} + +size_t +size_mddt() +{ + int count = 0; + MEMORY_DESCRIPTOR *desc; + + for (desc = GetMemoryDescriptor(NULL); desc; + desc = GetMemoryDescriptor(desc)) { + count++; + } + + return ROUNDUP(sizeof(struct mddt) + + (count - 1) * sizeof(struct mddt_cluster)); +} + +void +write_mddt(struct mddt *mddt, size_t size) +{ + int count = 0, i; + MEMORY_DESCRIPTOR *desc; + u_int64_t *p; + + memset(mddt, 0, sizeof(struct mddt)); + for (desc = GetMemoryDescriptor(NULL); desc; + desc = GetMemoryDescriptor(desc)) { + struct mddt_cluster *mc; + mc = &mddt->mddt_clusters[count]; + mc->mddt_pfn = desc->BasePage; + mc->mddt_pg_cnt = desc->PageCount; + mc->mddt_pg_test = 0; + mc->mddt_v_bitaddr = 0; + mc->mddt_p_bitaddr = 0; + mc->mddt_bit_cksum = 0; + + /* + * Not sure about the FirmwareTemporary bit but my 164LX has + * about 60Mb marked this way. + */ + if (desc->Type == MemoryFree || desc->Type == MemoryFirmwareTemporary) + mc->mddt_usage = MDDT_SYSTEM; + else if (desc->Type == MemorySpecialMemory) + mc->mddt_usage = MDDT_NONVOLATILE; /* ?? */ + else + mc->mddt_usage = MDDT_PALCODE; + count++; + } + mddt->mddt_cluster_cnt = count; + mddt->mddt_cksum = checksum(mddt, size); +} + +size_t +size_rpb() +{ + return sizeof(struct rpb) + size_mddt(); +} + +void +write_rpb(struct rpb *rpb) +{ + EXTENDED_SYSTEM_INFORMATION sysinfo; + SYSTEM_ID *sysid; + + ReturnExtendedSystemInformation(&sysinfo); + + memset(rpb, 0, sizeof(struct rpb)); + rpb->rpb_phys = 0; /* XXX */ + strcpy(rpb->rpb_magic, "HWRPB"); + rpb->rpb_version = HWRPB_DSRDB_MINVERS; + rpb->rpb_size = sizeof(struct rpb); + rpb->rpb_primary_cpu_id = 0; /* XXX */ + rpb->rpb_page_size = sysinfo.ProcessorPageSize; + rpb->rpb_phys_addr_size = sysinfo.NumberOfPhysicalAddressBits; + rpb->rpb_max_asn = sysinfo.MaximumAddressSpaceNumber; + rpb->rpb_type = ST_EB164; /* XXX */ + rpb->rpb_variation = SV_ST_ALPHAPC164LX_533; /* XXX */ + rpb->rpb_intr_freq = 1024*4096; /* XXX */ + rpb->rpb_cc_freq = 533000000; /* XXX */ + rpb->rpb_memdat_off = sizeof(struct rpb); + write_mddt((struct mddt *)((caddr_t) rpb + rpb->rpb_memdat_off), + size_mddt()); + rpb->rpb_checksum = checksum(rpb, 280); /* only sum first 280 bytes */ +} + +struct rpb * +make_rpb() +{ + EXTENDED_SYSTEM_INFORMATION sysinfo; + struct rpb *rpb; + + ReturnExtendedSystemInformation(&sysinfo); + printf("sysinfo.ProcessorId = %x\n", sysinfo.ProcessorId); + printf("sysinfo.ProcessorRevision = %d\n", sysinfo.ProcessorRevision); + printf("sysinfo.ProcessorPageSize = %d\n", sysinfo.ProcessorPageSize); + printf("sysinfo.NumberOfPhysicalAddressBits = %d\n", sysinfo.NumberOfPhysicalAddressBits); + printf("sysinfo.MaximumAddressSpaceNumber = %d\n", sysinfo.MaximumAddressSpaceNumber); + printf("sysinfo.ProcessorCycleCounterPeriod = %d\n", sysinfo.ProcessorCycleCounterPeriod); + printf("sysinfo.SystemRevision = %d\n", sysinfo.SystemRevision); + printf("sysinfo.SystemSerialNumber = %s\n", sysinfo.SystemSerialNumber); + printf("sysinfo.FirmwareVersion = %s\n", sysinfo.FirmwareVersion); + + rpb = malloc(size_rpb()); + write_rpb(rpb); + return rpb; +} diff --git a/sys/boot/arc/lib/arch/alpha/setjmp.S b/sys/boot/arc/lib/arch/alpha/setjmp.S new file mode 100644 index 0000000..8e153f7 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/setjmp.S @@ -0,0 +1,95 @@ +/* $FreeBSD$ */ +/* + * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * 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. + */ + +#include <machine/asm.h> + + .text +/* + * Kernel setjmp and longjmp. Rather minimalist. + * + * longjmp(label_t *a) + * will generate a "return (1)" from the last call to + * setjmp(label_t *a) + * by restoring registers from the stack, + */ + + .set noreorder + +LEAF(setjmp, 1) + LDGP(pv) + + stq ra, (0 * 8)(a0) /* return address */ + stq s0, (1 * 8)(a0) /* callee-saved registers */ + stq s1, (2 * 8)(a0) + stq s2, (3 * 8)(a0) + stq s3, (4 * 8)(a0) + stq s4, (5 * 8)(a0) + stq s5, (6 * 8)(a0) + stq s6, (7 * 8)(a0) + stq sp, (8 * 8)(a0) + + ldiq t0, 0xbeeffedadeadbabe /* set magic number */ + stq t0, (9 * 8)(a0) + + mov zero, v0 /* return zero */ + RET +END(setjmp) + +LEAF(longjmp, 1) + LDGP(pv) + + ldiq t0, 0xbeeffedadeadbabe /* check magic number */ + ldq t1, (9 * 8)(a0) + cmpeq t0, t1, t0 + beq t0, longjmp_botch /* if bad, punt */ + + ldq ra, (0 * 8)(a0) /* return address */ + ldq s0, (1 * 8)(a0) /* callee-saved registers */ + ldq s1, (2 * 8)(a0) + ldq s2, (3 * 8)(a0) + ldq s3, (4 * 8)(a0) + ldq s4, (5 * 8)(a0) + ldq s5, (6 * 8)(a0) + ldq s6, (7 * 8)(a0) + ldq sp, (8 * 8)(a0) + + ldiq v0, 1 + RET + +longjmp_botch: + lda a0, longjmp_botchmsg + mov ra, a1 + CALL(panic) + call_pal PAL_bugchk + + .data +longjmp_botchmsg: + .asciz "longjmp botch from %p" + .text + +END(longjmp) diff --git a/sys/boot/arc/lib/arch/alpha/start.S b/sys/boot/arc/lib/arch/alpha/start.S new file mode 100644 index 0000000..1b4fc59 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/start.S @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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 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$ + * + */ + +/* + * Based on /sys/boot/alpha/libalpha/start.S + * Copyright (c) 1992 Carnegie Mellon University + */ + +#include <machine/asm.h> + + .text + +#define ENTRY_FRAME 32 + +NESTED(_start, 1, ENTRY_FRAME, ra, 0, 0) + br pv,Lstartgp +Lstartgp: + LDGP(pv) + + lda a0,_edata + lda a1,_end + subq a1,a0,a1 + CALL(bzero) + + lda sp, -8(sp) + stq ra, 0(sp) + + CALL(main) /* transfer to C */ + + ldq ra, 0(sp) + lda sp, 8(sp) + RET /* XXX */ + +XLEAF(_rtt, 0) +XLEAF(halt, 0) + call_pal PAL_halt /* halt if we ever return */ +END(_start) diff --git a/sys/boot/arc/lib/bootinfo.c b/sys/boot/arc/lib/bootinfo.c new file mode 100644 index 0000000..cea3b1b --- /dev/null +++ b/sys/boot/arc/lib/bootinfo.c @@ -0,0 +1,203 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 <stand.h> +#include <string.h> +#include <sys/param.h> +#include <sys/linker.h> +#include <machine/elf.h> +#include <machine/prom.h> +#include <machine/rpb.h> +#include <machine/bootinfo.h> +#include "bootstrap.h" + +/* + * Copy the environment into the load area starting at (addr). + * Each variable is formatted as <name>=<value>, with a single nul + * separating each variable, and a double nul terminating the environment. + */ +vm_offset_t +bi_copyenv(vm_offset_t addr) +{ + struct env_var *ep; + + /* traverse the environment */ + for (ep = environ; ep != NULL; ep = ep->ev_next) { + alpha_copyin(ep->ev_name, addr, strlen(ep->ev_name)); + addr += strlen(ep->ev_name); + alpha_copyin("=", addr, 1); + addr++; + if (ep->ev_value != NULL) { + alpha_copyin(ep->ev_value, addr, strlen(ep->ev_value)); + addr += strlen(ep->ev_value); + } + alpha_copyin("", addr, 1); + addr++; + } + alpha_copyin("", addr, 1); + addr++; + return(addr); +} + +/* + * Copy module-related data into the load area, where it can be + * used as a directory for loaded modules. + * + * Module data is presented in a self-describing format. Each datum + * is preceded by a 32-bit identifier and a 32-bit size field. + * + * Currently, the following data are saved: + * + * MOD_NAME (variable) module name (string) + * MOD_TYPE (variable) module type (string) + * MOD_ADDR sizeof(vm_offset_t) module load address + * MOD_SIZE sizeof(size_t) module size + * MOD_METADATA (variable) type-specific metadata + */ +#define COPY32(v, a) { \ + u_int32_t x = (v); \ + alpha_copyin(&x, a, sizeof(x)); \ + a += sizeof(x); \ +} + +#define MOD_STR(t, a, s) { \ + COPY32(t, a); \ + COPY32(strlen(s) + 1, a); \ + alpha_copyin(s, a, strlen(s) + 1); \ + a += roundup(strlen(s) + 1, sizeof(u_int64_t));\ +} + +#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s) +#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s) + +#define MOD_VAR(t, a, s) { \ + COPY32(t, a); \ + COPY32(sizeof(s), a); \ + alpha_copyin(&s, a, sizeof(s)); \ + a += roundup(sizeof(s), sizeof(u_int64_t)); \ +} + +#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s) +#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s) + +#define MOD_METADATA(a, mm) { \ + COPY32(MODINFO_METADATA | mm->md_type, a); \ + COPY32(mm->md_size, a); \ + alpha_copyin(mm->md_data, a, mm->md_size); \ + a += roundup(mm->md_size, sizeof(u_int64_t));\ +} + +#define MOD_END(a) { \ + COPY32(MODINFO_END, a); \ + COPY32(0, a); \ +} + +vm_offset_t +bi_copymodules(vm_offset_t addr) +{ + struct preloaded_file *fp; + struct file_metadata *md; + + /* start with the first module on the list, should be the kernel */ + for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) { + + MOD_NAME(addr, fp->f_name); /* this field must come first */ + MOD_TYPE(addr, fp->f_type); + MOD_ADDR(addr, fp->f_addr); + MOD_SIZE(addr, fp->f_size); + for (md = fp->f_metadata; md != NULL; md = md->md_next) + if (!(md->md_type & MODINFOMD_NOCOPY)) + MOD_METADATA(addr, md); + } + MOD_END(addr); + return(addr); +} + +/* + * Load the information expected by an alpha kernel. + * + * - The kernel environment is copied into kernel space. + * - Module metadata are formatted and placed in kernel space. + */ +int +bi_load(struct bootinfo_v1 *bi, vm_offset_t *ffp_save, + struct preloaded_file *fp) +{ + struct preloaded_file *xp; + vm_offset_t addr, bootinfo_addr; + u_int pad; + vm_offset_t ssym, esym; + struct file_metadata *md; + + ssym = esym = 0; + if ((md = file_findmetadata(fp, MODINFOMD_SSYM)) != NULL) + ssym = *((vm_offset_t *)&(md->md_data)); + if ((md = file_findmetadata(fp, MODINFOMD_ESYM)) != NULL) + esym = *((vm_offset_t *)&(md->md_data)); + if (ssym == 0 || esym == 0) + ssym = esym = 0; /* sanity */ + + bi->ssym = ssym; + bi->esym = esym; + + /* find the last module in the chain */ + addr = 0; + for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) { + if (addr < (xp->f_addr + xp->f_size)) + addr = xp->f_addr + xp->f_size; + } + /* pad to a page boundary */ + pad = (u_int)addr & PAGE_MASK; + if (pad != 0) { + pad = PAGE_SIZE - pad; + addr += pad; + } + + /* copy our environment */ + bi->envp = (char *)addr; + addr = bi_copyenv(addr); + + /* pad to a page boundary */ + pad = (u_int)addr & PAGE_MASK; + if (pad != 0) { + pad = PAGE_SIZE - pad; + addr += pad; + } + /* copy module list and metadata */ + bi->modptr = addr; + addr = bi_copymodules(addr); + + /* all done copying stuff in, save end of loaded object space */ + bi->kernend = addr; + + *ffp_save = ALPHA_K0SEG_TO_PHYS((addr + PAGE_MASK) & ~PAGE_MASK) + >> PAGE_SHIFT; + *ffp_save += 2; /* XXX OSF/1 does this, no idea why. */ + + return(0); +} diff --git a/sys/boot/arc/lib/delay.c b/sys/boot/arc/lib/delay.c new file mode 100644 index 0000000..e897b4e --- /dev/null +++ b/sys/boot/arc/lib/delay.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +delay(int usecs) +{ + StallExecution(usecs); +} diff --git a/sys/boot/arc/lib/devicename.c b/sys/boot/arc/lib/devicename.c new file mode 100644 index 0000000..fba8175 --- /dev/null +++ b/sys/boot/arc/lib/devicename.c @@ -0,0 +1,235 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 <stand.h> +#include <string.h> +#include "bootstrap.h" +#include "libarc.h" + +static int arc_parsedev(struct arc_devdesc **dev, const char *devspec, const char **path); + +/* + * Point (dev) at an allocated device specifier for the device matching the + * path in (devspec). If it contains an explicit device specification, + * use that. If not, use the default device. + */ +int +arc_getdev(void **vdev, const char *devspec, const char **path) +{ + struct arc_devdesc **dev = (struct arc_devdesc **)vdev; + int rv; + + /* + * If it looks like this is just a path and no + * device, go with the current device. + */ + if ((devspec == NULL) || + (devspec[0] == '/') || + (strchr(devspec, ':') == NULL)) { + + if (((rv = arc_parsedev(dev, getenv("currdev"), NULL)) == 0) && + (path != NULL)) + *path = devspec; + return(rv); + } + + /* + * Try to parse the device name off the beginning of the devspec + */ + return(arc_parsedev(dev, devspec, path)); +} + +/* + * Point (dev) at an allocated device specifier matching the string version + * at the beginning of (devspec). Return a pointer to the remaining + * text in (path). + * + * In all cases, the beginning of (devspec) is compared to the names + * of known devices in the device switch, and then any following text + * is parsed according to the rules applied to the device type. + * + * For disk-type devices, the syntax is: + * + * disk<unit>[s<slice>][<partition>]: + * + */ +static int +arc_parsedev(struct arc_devdesc **dev, const char *devspec, const char **path) +{ + struct arc_devdesc *idev; + struct devsw *dv; + int i, unit, slice, partition, err; + char *cp; + const char *np; + + /* minimum length check */ + if (strlen(devspec) < 2) + return(EINVAL); + + /* look for a device that matches */ + for (i = 0, dv = NULL; devsw[i] != NULL; i++) { + if (!strncmp(devspec, devsw[i]->dv_name, strlen(devsw[i]->dv_name))) { + dv = devsw[i]; + break; + } + } + + if (dv == NULL) + return(ENOENT); + idev = malloc(sizeof(struct arc_devdesc)); + err = 0; + np = (devspec + strlen(dv->dv_name)); + + switch(dv->dv_type) { + case DEVT_NONE: /* XXX what to do here? Do we care? */ + break; + + case DEVT_DISK: + unit = -1; + slice = -1; + partition = -1; + if (*np && (*np != ':')) { + unit = strtol(np, &cp, 10); /* next comes the unit number */ + if (cp == np) { + err = EUNIT; + goto fail; + } + if (*cp == 's') { /* got a slice number */ + np = cp + 1; + slice = strtol(np, &cp, 10); + if (cp == np) { + err = ESLICE; + goto fail; + } + } + if (*cp && (*cp != ':')) { + partition = *cp - 'a'; /* get a partition number */ + if ((partition < 0) || (partition >= MAXPARTITIONS)) { + err = EPART; + goto fail; + } + cp++; + } + } + if (*cp && (*cp != ':')) { + err = EINVAL; + goto fail; + } + + idev->d_kind.arcdisk.unit = unit; + idev->d_kind.arcdisk.slice = slice; + idev->d_kind.arcdisk.partition = partition; + if (path != NULL) + *path = (*cp == 0) ? cp : cp + 1; + break; + + case DEVT_NET: + unit = 0; + + if (*np && (*np != ':')) { + unit = strtol(np, &cp, 0); /* get unit number if present */ + if (cp == np) { + err = EUNIT; + goto fail; + } + } + if (*cp && (*cp != ':')) { + err = EINVAL; + goto fail; + } + + idev->d_kind.netif.unit = unit; + if (path != NULL) + *path = (*cp == 0) ? cp : cp + 1; + break; + + default: + err = EINVAL; + goto fail; + } + idev->d_dev = dv; + idev->d_type = dv->dv_type; + if (dev == NULL) { + free(idev); + } else { + *dev = idev; + } + return(0); + + fail: + free(idev); + return(err); +} + + +char * +arc_fmtdev(void *vdev) +{ + struct arc_devdesc *dev = (struct arc_devdesc *)vdev; + static char buf[128]; /* XXX device length constant? */ + char *cp; + + switch(dev->d_type) { + case DEVT_NONE: + strcpy(buf, "(no device)"); + break; + + case DEVT_DISK: + cp = buf; + cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.arcdisk.unit); + if (dev->d_kind.arcdisk.slice > 0) + cp += sprintf(cp, "s%d", dev->d_kind.arcdisk.slice); + if (dev->d_kind.arcdisk.partition >= 0) + cp += sprintf(cp, "%c", dev->d_kind.arcdisk.partition + 'a'); + strcat(cp, ":"); + break; + + case DEVT_NET: + sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit); + break; + } + return(buf); +} + + +/* + * Set currdev to suit the value being supplied in (value) + */ +int +arc_setcurrdev(struct env_var *ev, int flags, void *value) +{ + struct arc_devdesc *ncurr; + int rv; + + if ((rv = arc_parsedev(&ncurr, value, NULL)) != 0) + return(rv); + free(ncurr); + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + return(0); +} + diff --git a/sys/boot/arc/lib/elf_freebsd.c b/sys/boot/arc/lib/elf_freebsd.c new file mode 100644 index 0000000..41cdedb --- /dev/null +++ b/sys/boot/arc/lib/elf_freebsd.c @@ -0,0 +1,143 @@ +/* $FreeBSD$ */ +/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross 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. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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 + */ + +#include <stand.h> +#include <string.h> + +#include <sys/param.h> +#include <sys/linker.h> +#include <machine/elf.h> +#include <machine/prom.h> +#include <machine/rpb.h> +#include <machine/bootinfo.h> + +#include "bootstrap.h" + +#define _KERNEL + +static int elf64_exec(struct preloaded_file *amp); +int bi_load(struct bootinfo_v1 *, vm_offset_t *, + struct preloaded_file *); + +struct file_format alpha_elf = { elf64_loadfile, elf64_exec }; + +vm_offset_t ffp_save, ptbr_save; + +static int +elf64_exec(struct preloaded_file *fp) +{ +#if 0 + static struct bootinfo_v1 bootinfo_v1; + struct file_metadata *md; + Elf_Ehdr *hdr; + int err; + + if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) + return(EFTYPE); /* XXX actually EFUCKUP */ + hdr = (Elf_Ehdr *)&(md->md_data); + + /* XXX ffp_save does not appear to be used in the kernel.. */ + bzero(&bootinfo_v1, sizeof(bootinfo_v1)); + err = bi_load(&bootinfo_v1, &ffp_save, fp); + if (err) + return(err); + + /* + * Fill in the bootinfo for the kernel. + */ + strncpy(bootinfo_v1.booted_kernel, fp->f_name, + sizeof(bootinfo_v1.booted_kernel)); + prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags, + sizeof(bootinfo_v1.boot_flags)); + bootinfo_v1.hwrpb = (void *)HWRPB_ADDR; + bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size; + bootinfo_v1.cngetc = NULL; + bootinfo_v1.cnputc = NULL; + bootinfo_v1.cnpollc = NULL; + + printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry); + exit(0); + closeall(); + alpha_pal_imb(); + (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save, + BOOTINFO_MAGIC, &bootinfo_v1, 1, 0); +#endif +} + + + diff --git a/sys/boot/arc/lib/module.c b/sys/boot/arc/lib/module.c new file mode 100644 index 0000000..a6a3997 --- /dev/null +++ b/sys/boot/arc/lib/module.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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$ + */ + +/* + * alpha-specific module functionality. + * + */ + +#include <stand.h> +#include <string.h> + +#include "bootstrap.h" +#include "libarc.h" + +/* + * Use voodoo to load modules required by current hardware. + */ +int +arc_autoload(void) +{ + /* XXX use PnP to locate stuff here */ + return(0); +} diff --git a/sys/boot/arc/lib/prom.c b/sys/boot/arc/lib/prom.c new file mode 100644 index 0000000..5f13801 --- /dev/null +++ b/sys/boot/arc/lib/prom.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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 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$ + * + */ + +#define PROM_E_BOOTED_DEV "XXX1" +#define PROM_E_BOOTED_FILE "XXX2" +#define PROM_E_BOOTED_OSFLAGS "XXX3" +#define PROM_E_TTY_DEV "XXX4" + +u_int64_t +prom_getenv(PROM_E_BOOTED_FILE, bootfile, sizeof(bootfile)) +{ + +} diff --git a/sys/boot/arc/lib/setjmperr.c b/sys/boot/arc/lib/setjmperr.c new file mode 100644 index 0000000..9c005e1 --- /dev/null +++ b/sys/boot/arc/lib/setjmperr.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +longjmperror() +{ + panic("longjmp botch.\n"); +} diff --git a/sys/boot/arc/lib/time.c b/sys/boot/arc/lib/time.c new file mode 100644 index 0000000..bf0ba1a --- /dev/null +++ b/sys/boot/arc/lib/time.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +time_t +time(time_t *tloc) +{ + int secs = GetRelativeTime(); + if (tloc) + *tloc = secs; + return secs; +} |