diff options
author | Jasper Lievisse Adriaanse <jasper@cvs.openbsd.org> | 2013-06-05 01:02:30 +0000 |
---|---|---|
committer | Jasper Lievisse Adriaanse <jasper@cvs.openbsd.org> | 2013-06-05 01:02:30 +0000 |
commit | 8c6aa021cd28b19c37b44b1258927b54dee1c52d (patch) | |
tree | 1243b66d8d71bb69f810a711f3b2386a2482c758 /sys | |
parent | b628c5aadd099f20ef722e0f3c67d63a241bab2d (diff) |
add WIP second stage bootloader for octeon; far from working and contains many stubs still.
committing it now so I can work on this in tree.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/octeon/stand/Makefile | 7 | ||||
-rw-r--r-- | sys/arch/octeon/stand/Makefile.inc | 45 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/Makefile | 18 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/Makefile.inc | 38 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/clock.c | 33 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/conf.c | 58 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/devopen.c | 121 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/exec.c | 7 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/ld.script | 23 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/libsa.h | 46 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/machdep.c | 155 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/start.S | 85 | ||||
-rw-r--r-- | sys/arch/octeon/stand/boot/uart.c | 126 | ||||
-rw-r--r-- | sys/arch/octeon/stand/libsa/Makefile | 52 |
14 files changed, 814 insertions, 0 deletions
diff --git a/sys/arch/octeon/stand/Makefile b/sys/arch/octeon/stand/Makefile new file mode 100644 index 00000000000..17dd4f5fe51 --- /dev/null +++ b/sys/arch/octeon/stand/Makefile @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile,v 1.1 2013/06/05 01:02:29 jasper Exp $ + +.if ${MACHINE} == "octeon" +SUBDIR += libsa +.endif + +.include <bsd.subdir.mk> diff --git a/sys/arch/octeon/stand/Makefile.inc b/sys/arch/octeon/stand/Makefile.inc new file mode 100644 index 00000000000..18d8470f888 --- /dev/null +++ b/sys/arch/octeon/stand/Makefile.inc @@ -0,0 +1,45 @@ +# $OpenBSD: Makefile.inc,v 1.1 2013/06/05 01:02:29 jasper Exp $ + +BINDIR= /usr/mdec + +STANDALONE?= -D_STANDALONE + +.if ${MACHINE} == "octeon" +CPPFLAGS+= ${STANDALONE} +CPPFLAGS+= -I. +CFLAGS+= -fno-stack-protector -Wall +CFLAGS+= -fno-builtin-vprintf -fno-builtin-printf -fno-builtin-putchar +# Silence warnings +CFLAGS+= -fno-builtin-snprintf +CFLAGS+= -fno-builtin-memcpy +CFLAGS+= -fno-builtin-memcmp +CFLAGS+= -fno-builtin-memset +CFLAGS+= -fno-builtin-strncpy +CFLAGS+= -fno-builtin-strncmp +CFLAGS+= -fno-builtin-exit +SAABI= -mips3 -mno-abicalls -G 0 -fno-pic -fno-common +AS?= as +LD?= ld +.endif + +### Figure out what to use for libsa +LIBSADIR?= ${.CURDIR}/../libsa + +.if exists(${LIBSADIR}/${__objdir}) +LIBSAOBJDIR= ${LIBSADIR}/${__objdir} +.else +LIBSAOBJDIR= ${LIBSADIR} +.endif + +LIBSA= ${LIBSAOBJDIR}/libsa.a + +### Figure out what to use for libz +LIBZDIR?= ${.CURDIR}/../libz + +.if exists(${LIBZDIR}/${__objdir}) +LIBZOBJDIR= ${LIBZDIR}/${__objdir} +.else +LIBZOBJDIR= ${LIBZDIR} +.endif + +LIBZ= ${LIBZOBJDIR}/libz.a diff --git a/sys/arch/octeon/stand/boot/Makefile b/sys/arch/octeon/stand/boot/Makefile new file mode 100644 index 00000000000..c4fc6e0af66 --- /dev/null +++ b/sys/arch/octeon/stand/boot/Makefile @@ -0,0 +1,18 @@ +# $OpenBSD: Makefile,v 1.1 2013/06/05 01:02:29 jasper Exp $ + +NOMAN= +#MAN= boot.8 +#MLINKS= boot.8 boot.conf.5 + +.if ${MACHINE} == "octeon" +PROG= boot +.include "${.CURDIR}/Makefile.inc" +.else +NOPROG= +.endif + +CFLAGS+=-fno-pie +AFLAGS+=-fno-pie +LDFLAGS+=-nopie + +.include <bsd.prog.mk> diff --git a/sys/arch/octeon/stand/boot/Makefile.inc b/sys/arch/octeon/stand/boot/Makefile.inc new file mode 100644 index 00000000000..888d8633c07 --- /dev/null +++ b/sys/arch/octeon/stand/boot/Makefile.inc @@ -0,0 +1,38 @@ +# $OpenBSD: Makefile.inc,v 1.1 2013/06/05 01:02:29 jasper Exp $ + +NOMAN= +S= ${.CURDIR}/../../../.. +BOOTDIR= ${S}/arch/octeon/stand/boot + +CPPFLAGS+= ${SAABI} -mno-abicalls -D_NO_ABICALLS -Werror \ + -nostdinc -D__octeon__ -msoft-float \ + -I${S} -I${S}/lib/libsa \ + -I${.OBJDIR} -I${BOOTDIR} + +LDSCRIPT= ${.CURDIR}/ld.script +LDFLAGS+= ${SALDFLAGS} -T ${LDSCRIPT} -Ttext=0xffffffff81000000 -e start + +AFLAGS+= ${SAABI} + +.PATH: ${BOOTDIR} +SRCS= start.S +SRCS+= conf.c clock.c devopen.c exec.c machdep.c uart.c + +#### MI boot code +.PATH: ${S}/stand/boot +SRCS+= boot.c cmd.c vars.c + +#### libkern +.PATH: ${S}/lib/libkern/arch/mips64 ${S}/lib/libkern +SRCS+= strlcat.c strlcpy.c strlen.c +SRCS+= udivdi3.c qdivrem.c + +.if !make(obj) +.BEGIN: + @([ -h machine ] || ln -s ${.CURDIR}/../../include machine) + @([ -h mips64 ] || ln -s ${.CURDIR}/../../../mips64/include mips64) +CLEANFILES+= machine mips64 +.endif + +${PROG}: ${OBJS} ${LIBSA} + ${LD} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBSA} diff --git a/sys/arch/octeon/stand/boot/clock.c b/sys/arch/octeon/stand/boot/clock.c new file mode 100644 index 00000000000..f5e302321c2 --- /dev/null +++ b/sys/arch/octeon/stand/boot/clock.c @@ -0,0 +1,33 @@ +/* $OpenBSD: clock.c,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2013 Jasper Lievisse Adriaanse <jasper@openbsd.org> + * + * 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 <sys/types.h> + +#include "libsa.h" + +/* Arbitrarily chosen value, needs talking to cp0 for a delay loop. */ +#define DELAY_MULTIPLIER 10000 + +void +delay(int ns) +{ + volatile int i = ns * DELAY_MULTIPLIER; + for (; --i;) + ; +} diff --git a/sys/arch/octeon/stand/boot/conf.c b/sys/arch/octeon/stand/boot/conf.c new file mode 100644 index 00000000000..1bde3cde363 --- /dev/null +++ b/sys/arch/octeon/stand/boot/conf.c @@ -0,0 +1,58 @@ +/* $OpenBSD: conf.c,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2013 Jasper Lievisse Adriaanse <jasper@openbsd.org> + * + * 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 <sys/param.h> +#include <dev/cons.h> + +#include "libsa.h" +#include <lib/libsa/ufs.h> +#include <lib/libsa/cd9660.h> + +const char version[] = "0.1"; + +/* + * Device configuration + */ +struct devsw devsw[] = { + /* ATA storage device */ + /* XXX */ + { "wd", NULL, NULL, NULL, noioctl } +}; +int ndevs = nitems(devsw); + +/* + * Filesystem configuration + */ +struct fs_ops file_system[] = { + /* ufs filesystem */ + { ufs_open, ufs_close, ufs_read, ufs_write, + ufs_seek, ufs_stat, ufs_readdir }, + /* cd9660 filesystem - in case a cd image is dd'ed on non USB media */ + { cd9660_open, cd9660_close, cd9660_read, cd9660_write, + cd9660_seek, cd9660_stat, cd9660_readdir } +}; +int nfsys = nitems(file_system); + +/* + * Console configuration + */ +struct consdev constab[] = { + { cn30xxuartcnprobe, cn30xxuartcninit, cn30xxuartcngetc, cn30xxuartcnputc }, + { NULL } +}; +struct consdev *cn_tab; diff --git a/sys/arch/octeon/stand/boot/devopen.c b/sys/arch/octeon/stand/boot/devopen.c new file mode 100644 index 00000000000..0b338beb165 --- /dev/null +++ b/sys/arch/octeon/stand/boot/devopen.c @@ -0,0 +1,121 @@ +/* $OpenBSD: devopen.c,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/*- + * Copyright (c) 2003 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Rolf Grossmann. + * + * 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 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. + */ + +#include "libsa.h" + +#define MAXDEVNAME 16 + +/* + * Parse a device spec. + * + * [A-Za-z]*[0-9]*[A-Za-z]:file + * dev uint part + */ +int +devparse(const char *fname, int *dev, int *unit, int *part, const char **file) +{ + const char *s; + + *unit = 0; /* default to wd0a */ + *part = 0; + *dev = 0; + + s = strchr(fname, ':'); + if (s != NULL) { + int devlen; + int i, u, p = 0; + struct devsw *dp; + char devname[MAXDEVNAME]; + + devlen = s - fname; + if (devlen > MAXDEVNAME) + return (EINVAL); + + /* extract device name */ + for (i = 0; isalpha(fname[i]) && (i < devlen); i++) + devname[i] = fname[i]; + devname[i] = 0; + + if (!isdigit(fname[i])) + return (EUNIT); + + /* device number */ + for (u = 0; isdigit(fname[i]) && (i < devlen); i++) + u = u * 10 + (fname[i] - '0'); + + if (!isalpha(fname[i])) + return (EPART); + + /* partition number */ + if (i < devlen) + p = fname[i++] - 'a'; + + if (i != devlen) + return (ENXIO); + + /* check device name */ + for (dp = devsw, i = 0; i < ndevs; dp++, i++) { + if (dp->dv_name && !strcmp(devname, dp->dv_name)) + break; + } + + if (i >= ndevs) + return (ENXIO); + + *unit = u; + *part = p; + *dev = i; + fname = ++s; + } + + *file = fname; + + return (0); +} + +int +devopen(struct open_file *f, const char *fname, char **file) +{ + struct devsw *dp; + int dev, unit, part, error; + + error = devparse(fname, &dev, &unit, &part, (const char **)file); + if (error) + return (error); + + dp = &devsw[dev]; + if ((void *)dp->dv_open == (void *)nodev) + return (ENXIO); + + f->f_dev = dp; + + return (*dp->dv_open)(f, unit, part); +} diff --git a/sys/arch/octeon/stand/boot/exec.c b/sys/arch/octeon/stand/boot/exec.c new file mode 100644 index 00000000000..2bd64546ee6 --- /dev/null +++ b/sys/arch/octeon/stand/boot/exec.c @@ -0,0 +1,7 @@ +#include <sys/param.h> +#include "libsa.h" +#include <lib/libsa/loadfile.h> + +void +run_loadfile(u_long *marks, int howto) +{} diff --git a/sys/arch/octeon/stand/boot/ld.script b/sys/arch/octeon/stand/boot/ld.script new file mode 100644 index 00000000000..eaf67e0bb74 --- /dev/null +++ b/sys/arch/octeon/stand/boot/ld.script @@ -0,0 +1,23 @@ +OUTPUT_FORMAT("elf64-tradbigmips") +OUTPUT_ARCH(mips) +ENTRY(start) + +SECTIONS +{ + .text : { *(.text .text.* .gnu.linkonce.t.*) } + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + _gp = ALIGN(16) + 0x7ff0; + .data : { *(.data .data.* .gnu.linkonce.d.*) } + PROVIDE (edata = .); + .sbss : { *(.sbss .sbss.* .gnu.linkonce.sb.* .scommon) } + .bss : { *(.bss .bss.* .gnu.linkonce.b.* COMMON) } + PROVIDE (_end = .); + PROVIDE (end = .); + /DISCARD/ : + { + *(.pdr) + *(.mdebug.abi64) + *(.MIPS.options) + } +} diff --git a/sys/arch/octeon/stand/boot/libsa.h b/sys/arch/octeon/stand/boot/libsa.h new file mode 100644 index 00000000000..90c6061b384 --- /dev/null +++ b/sys/arch/octeon/stand/boot/libsa.h @@ -0,0 +1,46 @@ +/* $OpenBSD: libsa.h,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2013 Jasper Lievisse Adriaanse <jasper@openbsd.org> + * + * 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 DEFAULT_KERNEL_ADDRESS 0 +#define INITRD_BASE PHYS_TO_CKSEG0(0x04000000) +#define CONSPEED 115200 + +extern char *kernelfile; + +/* + * MD interfaces for MI boot(9) + */ +void devboot(dev_t, char *); +void machdep(void); +void run_loadfile(u_long *, int); + +/* + * CN30XX UART + */ + +void cn30xxuartcnprobe(struct consdev *); +void cn30xxuartcninit(struct consdev *); +void cn30xxuartcnputc(dev_t, int); +int cn30xxuartcngetc(dev_t); + +/* + * clock + */ +void delay(int); diff --git a/sys/arch/octeon/stand/boot/machdep.c b/sys/arch/octeon/stand/boot/machdep.c new file mode 100644 index 00000000000..c509904615f --- /dev/null +++ b/sys/arch/octeon/stand/boot/machdep.c @@ -0,0 +1,155 @@ +/* $OpenBSD: machdep.c,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2009, 2010 Miodrag Vallat. + * Copyright (c) 2013 Jasper Lievisse Adriaanse <jasper@openbsd.org> + * + * 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. + */ +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 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 <lib/libkern/libkern.h> +#include "libsa.h" +#include <machine/cpu.h> +#include <machine/octeonreg.h> +#include <machine/octeonvar.h> +#include <stand/boot/cmd.h> + +int +main() +{ + cninit(); + return (0); +} + +/* + * Console and TTY related functions + */ + +int +cnspeed(dev_t dev, int s) +{ + return (CONSPEED); +} + +int +getchar() +{ + int c = cngetc(); + + if (c == '\r') + c = '\n'; + + if ((c < ' ' && c != '\n') || c == '\177') + return c; + + putchar(c); + + return c; +} + +int pch_pos; + +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; + } +} + +char * +ttyname(int fd) +{ + return "uboot console"; +} + +dev_t +ttydev(char *name) +{ + return (NODEV); +} + +/* + * Boot -devices and -path related functions. + */ + +void +devboot(dev_t dev, char *path) +{ + strlcpy(path, "octcf0a", 7); +} + +time_t +getsecs() +{ + return (0); +} + +void +machdep() +{} + +__dead void +_rtt() +{ + octeon_xkphys_write_8(OCTEON_CIU_BASE + CIU_SOFT_RST, 1); + for (;;) ; +} + diff --git a/sys/arch/octeon/stand/boot/start.S b/sys/arch/octeon/stand/boot/start.S new file mode 100644 index 00000000000..570a42cf818 --- /dev/null +++ b/sys/arch/octeon/stand/boot/start.S @@ -0,0 +1,85 @@ +/* $OpenBSD: start.S,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 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 <machine/param.h> +#include <machine/asm.h> +#include <machine/cpu.h> +#include <mips64/mips_cpu.h> +#include <machine/regnum.h> +#include <machine/cpustate.h> + + .set noreorder + .set mips64r2 + + .globl start + .globl kernel_text +kernel_text = start +start: +/* initialize ebase */ + dla t0, 0xffffffff80000000 + mtc0 t0, COP_0_EBASE + +/* initialize cvmctl */ + dli t0, 0x900043F0 + dmtc0 t0, COP_0_CVMCTL + +/* initialize cvmmemctl */ + dli t0, 0x1846104 # If you want to skip write buffer, use this + dmtc0 t0, COP_0_CVMMEMCTL + +/* initialize pagegrain */ + dli t0, 0x20000000 + dmtc0 t0, COP_0_TLB_PG_GRAIN + + mfc0 v0, COP_0_STATUS_REG + li v1, ~(SR_INT_ENAB | SR_ERL | SR_EXL) + and v0, v1 + mtc0 v0, COP_0_STATUS_REG # disable all interrupts + + mtc0 zero, COP_0_CAUSE_REG # Clear soft interrupts + + LA gp, _gp + + /* + * Initialize stack and call bootloader setup. + */ + LA t0, start - FRAMESZ(CF_SZ) + PTR_S ra, CF_RA_OFFS(t0) # save uboot return address + PTR_S sp, 0(t0) # and stack + move sp, t0 + jal main # main(argc, argv, envp, callvec, esym) + + beqz v0, 1f # upon failure, return to uboot + nop + + move a0, zero + PANIC("Startup failed!") + +1: PTR_L ra, CF_RA_OFFS(sp) + PTR_L sp, 0(sp) + jr ra + nop diff --git a/sys/arch/octeon/stand/boot/uart.c b/sys/arch/octeon/stand/boot/uart.c new file mode 100644 index 00000000000..79970e51060 --- /dev/null +++ b/sys/arch/octeon/stand/boot/uart.c @@ -0,0 +1,126 @@ +/* $OpenBSD: uart.c,v 1.1 2013/06/05 01:02:29 jasper Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 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/device.h> +#include <sys/tty.h> + +#include <machine/bus.h> + +#include <dev/ic/comreg.h> +#include <dev/ic/comvar.h> +#include <dev/cons.h> + +#include "libsa.h" + +#define OCTEON_MIO_UART0 0x8001180000000800ull +#define OCTEON_MIO_UART0_LSR 0x8001180000000828ull +#define OCTEON_MIO_UART0_RBR 0x8001180000000800ull +#define OCTEON_MIO_UART0_USR 0x8001180000000938ull +#define OCTEON_MIO_UART0_LCR 0x8001180000000818ull +#define OCTEON_MIO_UART0_DLL 0x8001180000000880ull +#define OCTEON_MIO_UART0_DLH 0x8001180000000888ull +#define USR_TXFIFO_NOTFULL 2 + +static int delay_changed = 1; +int cn30xxuart_delay(void); +void cn30xxuart_wait_txhr_empty(int); + +/* + * Early console routines. + */ +int +cn30xxuart_delay(void) +{ + int divisor; + u_char lcr; + static int d = 0; + + if (!delay_changed) return d; + delay_changed = 0; + lcr = (u_char)*(uint64_t*)OCTEON_MIO_UART0_LCR; + *(uint64_t*)OCTEON_MIO_UART0_LCR = lcr | LCR_DLAB; + divisor = (int)(*(uint64_t*)OCTEON_MIO_UART0_DLL | + *(uint64_t*)OCTEON_MIO_UART0_DLH << 8); + *(uint64_t*)OCTEON_MIO_UART0_LCR = lcr; + + return 10; /* return an approx delay value */ +} + +void +cn30xxuart_wait_txhr_empty(int d) +{ + while (((*(uint64_t*)OCTEON_MIO_UART0_LSR & LSR_TXRDY) == 0) && + ((*(uint64_t*)OCTEON_MIO_UART0_USR & USR_TXFIFO_NOTFULL) == 0)) + delay(d); +} + +void +cn30xxuartcninit(struct consdev *consdev) +{ +} + +void +cn30xxuartcnprobe(struct consdev *cn) +{ + cn->cn_pri = CN_LOWPRI; + cn->cn_dev = makedev(0, 0); +} + +void +cn30xxuartcnpollc(dev_t dev, int c) +{ +} + +void +cn30xxuartcnputc (dev_t dev, int c) +{ + int d; + + /* 1/10th the time to transmit 1 character (estimate). */ + d = cn30xxuart_delay(); + cn30xxuart_wait_txhr_empty(d); + *(uint64_t*)OCTEON_MIO_UART0_RBR = (uint8_t)c; + cn30xxuart_wait_txhr_empty(d); +} + +int +cn30xxuartcngetc (dev_t dev) +{ + int c, d; + + /* 1/10th the time to transmit 1 character (estimate). */ + d = cn30xxuart_delay(); + + while ((*(uint64_t*)OCTEON_MIO_UART0_LSR & LSR_RXRDY) == 0) + delay(d); + + c = (uint8_t)*(uint64_t*)OCTEON_MIO_UART0_RBR; + + return (c); +} diff --git a/sys/arch/octeon/stand/libsa/Makefile b/sys/arch/octeon/stand/libsa/Makefile new file mode 100644 index 00000000000..7f606bd462a --- /dev/null +++ b/sys/arch/octeon/stand/libsa/Makefile @@ -0,0 +1,52 @@ +# $OpenBSD: Makefile,v 1.1 2013/06/05 01:02:29 jasper Exp $ + +.include "${.CURDIR}/../Makefile.inc" + +LIB= sa + +.PATH: ${.CURDIR}/../../../../lib/libsa + +CLEANFILES += machine mips64 + +CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdinc -mno-abicalls -D_NO_ABICALLS \ + -fno-pie \ + -I${.CURDIR} -I${.CURDIR}/../include -I${.CURDIR}/../.. \ + -I${.CURDIR}/../../.. -I${.CURDIR}/../../../.. \ + -I${.CURDIR}/../../../../lib/libsa \ + -I${.OBJDIR} + +# stand routines +SRCS= alloc.c cons.c ctime.c exit.c getfile.c gets.c globals.c \ + memcmp.c memcpy.c memset.c printf.c \ + snprintf.c strchr.c strcmp.c strerror.c strncmp.c strncpy.c strtol.c + +# io routines +SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fstat.c ioctl.c \ + lseek.c open.c read.c readdir.c stat.c write.c +#SRCS+= nullfs.c + +#SRCS+= cread.c +#CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD + +# boot filesystems +SRCS+= ufs.c cd9660.c + +CFLAGS+=-DNO_NET + +SRCS+= loadfile.c + +${OBJS}: ${.CURDIR}/../Makefile.inc + +NOPROFILE= +NOPIC= + +.if !make(obj) +.BEGIN: + @([ -h machine ] || ln -s ${.CURDIR}/../../include machine) + @([ -h mips64 ] || ln -s ${.CURDIR}/../../../mips64/include mips64) +CLEANFILES+= machine mips64 +.endif + +install: + +.include <bsd.lib.mk> |