diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2006-10-06 21:48:51 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2006-10-06 21:48:51 +0000 |
commit | 83b32e82fc7a5cb82458e3db56483ae958f083d3 (patch) | |
tree | 25cb7e586908e5deebe19642a6468c09585163eb /sys/arch/landisk/stand/boot | |
parent | cd7ea476994e7b1417f1387ef000c66afa1da348 (diff) |
w/ help of netbsd srcs and some mother unzel made it lift off
Diffstat (limited to 'sys/arch/landisk/stand/boot')
-rw-r--r-- | sys/arch/landisk/stand/boot/Makefile | 42 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/conf.c | 52 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/delay.c | 131 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/devs.c | 160 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/getsecs.c | 202 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/libsa.h | 34 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/scifcons.c | 250 | ||||
-rw-r--r-- | sys/arch/landisk/stand/boot/srt0.S | 153 |
8 files changed, 1024 insertions, 0 deletions
diff --git a/sys/arch/landisk/stand/boot/Makefile b/sys/arch/landisk/stand/boot/Makefile new file mode 100644 index 00000000000..eda9d8989c3 --- /dev/null +++ b/sys/arch/landisk/stand/boot/Makefile @@ -0,0 +1,42 @@ +# $OpenBSD: Makefile,v 1.1 2006/10/06 21:48:50 mickey Exp $ + +PROG= boot +SRCS= srt0.S conf.c devs.c getsecs.c scifcons.c delay.c +LDFLAGS=-nostdlib -Ttext 0x8ff00000 -N -x -Bstatic -e start + +INSTALL_STRIP= + +S= ${.CURDIR}/../../../.. +CPPFLAGS+=-D_STANDALONE +CPPFLAGS+=-DSH4 +CPPFLAGS+=-nostdinc -I${.OBJDIR} -I${.CURDIR} -I${.CURDIR}/.. -I${S} +CPPFLAGS+=-DLOADADDRESS=0x8ff00000 + +.PATH: ${S}/stand/boot +SRCS+= boot.c cmd.c vars.c bootarg.c + +SAREL= +SA_ZLIB= +USE_LOADFILE= +.PATH: ${S}/lib/libsa +SRCS+= ctime.c strtol.c +.include "${S}/lib/libsa/Makefile.inc" +DPADD+= $(SALIB) +LDADD+= $(SALIB) + +KERN_AS?= library +.include "${S}/lib/libkern/Makefile.inc" +DPADD+= $(KERNLIB) +LDADD+= $(KERNLIB) + +Z_AS?= library +.include "${S}/lib/libz/Makefile.inc" +DPADD+= $(ZLIB) +LDADD+= $(ZLIB) + +${PROG}: ${OBJS} ${DPADD} + ${LD} -o ${PROG}.sym ${LDFLAGS} \ + -Map ${PROG}.map -cref ${OBJS} ${LDADD} + ${OBJCOPY} -O binary ${PROG}.sym ${PROG} + +.include <bsd.prog.mk> diff --git a/sys/arch/landisk/stand/boot/conf.c b/sys/arch/landisk/stand/boot/conf.c new file mode 100644 index 00000000000..4ac899aa9ff --- /dev/null +++ b/sys/arch/landisk/stand/boot/conf.c @@ -0,0 +1,52 @@ +/* $OpenBSD: conf.c,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ + +/* + * Copyright (c) 2006 Michael Shalayeff + * All rights reserved. + * + * 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 MIND, 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> +#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 <dev/cons.h> + +const char version[] = "0.99"; +int debug = 1; + +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 +}; +int nfsys = NENTS(file_system); + +struct devsw devsw[] = { + { "dk", blkdevstrategy, blkdevopen, blkdevclose, noioctl }, +}; +int ndevs = NENTS(devsw); diff --git a/sys/arch/landisk/stand/boot/delay.c b/sys/arch/landisk/stand/boot/delay.c new file mode 100644 index 00000000000..b0dc7f2cab1 --- /dev/null +++ b/sys/arch/landisk/stand/boot/delay.c @@ -0,0 +1,131 @@ +/* $OpenBSD: delay.c,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ +/* $NetBSD: delay.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2005 NONAKA Kimihiro + * 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 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. + */ + +#include <sys/param.h> +#include <libsa.h> + +#include <sh/tmureg.h> + +#ifndef TICK_CH +#define TICK_CH 0 +#endif +#if TICK_CH == 0 +#define TSTR SH4_TSTR +#define TCOR SH4_TCOR0 +#define TCNT SH4_TCNT0 +#define TCR SH4_TCR0 +#define TSTR_CH TSTR_STR0 +#elif TICK_CH == 1 +#define TSTR SH4_TSTR +#define TCOR SH4_TCOR1 +#define TCNT SH4_TCNT1 +#define TCR SH4_TCR1 +#define TSTR_CH TSTR_STR1 +#elif TICK_CH == 2 +#define TSTR SH4_TSTR +#define TCOR SH4_TCOR2 +#define TCNT SH4_TCNT2 +#define TCR SH4_TCR2 +#define TSTR_CH TSTR_STR2 +#elif TICK_CH == 3 +#define TSTR SH4_TSTR2 +#define TCOR SH4_TCOR3 +#define TCNT SH4_TCNT3 +#define TCR SH4_TCR3 +#define TSTR_CH SH4_TSTR2_STR3 +#elif TICK_CH == 4 +#define TSTR SH4_TSTR2 +#define TCOR SH4_TCOR4 +#define TCNT SH4_TCNT4 +#define TCR SH4_TCR4 +#define TSTR_CH SH4_TSTR2_STR4 +#else +#error TICK_CH != [01234] +#endif + +#ifndef TICK_PRESC +#define TICK_PRESC 1024 +#endif +#if TICK_PRESC == 4 +#define TCR_TPSC TCR_TPSC_P4 +#elif TICK_PRESC == 16 +#define TCR_TPSC TCR_TPSC_P16 +#elif TICK_PRESC == 64 +#define TCR_TPSC TCR_TPSC_P64 +#elif TICK_PRESC == 256 +#define TCR_TPSC TCR_TPSC_P256 +#elif TICK_PRESC == 1024 +#define TCR_TPSC SH4_TCR_TPSC_P1024 +#else +#error TICK_PRESC != 4, 16, 64, 256, 1024 +#endif + +#define TICKS_PER_SEC (PCLOCK / TICK_PRESC) +#define MS_PER_TICK (1000000 / TICKS_PER_SEC) + +int +tick_init(void) +{ + + _reg_bclr_1(TSTR, TSTR_CH); + _reg_write_2(TCR, TCR_TPSC); + _reg_write_4(TCOR, 0xffffffff); + _reg_write_4(TCNT, 0xffffffff); + _reg_bset_1(TSTR, TSTR_CH); + + return 0; +} + +void +tick_stop(void) +{ + + _reg_bclr_1(TSTR, TSTR_CH); +} + +uint32_t +gettick(void) +{ + + return ~(_reg_read_4(TCNT)); +} + +void +delay(int ms) +{ + uint32_t base, now; + + base = gettick(); + for (;;) { + now = gettick(); + if (((now - base) / MS_PER_TICK) > ms) { + break; + } + } +} diff --git a/sys/arch/landisk/stand/boot/devs.c b/sys/arch/landisk/stand/boot/devs.c new file mode 100644 index 00000000000..919c41e1d15 --- /dev/null +++ b/sys/arch/landisk/stand/boot/devs.c @@ -0,0 +1,160 @@ +/* $OpenBSD: devs.c,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ + +/* + * Copyright (c) 2006 Michael Shalayeff + * All rights reserved. + * + * 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 MIND, 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 <libsa.h> +#include <lib/libsa/loadfile.h> + +int sector; + +void +machdep(void) +{ + /* scif_init(9600); */ +} + +int +devopen(struct open_file *f, const char *fname, char **file) +{ + if (fname[0] != 'c' || fname[1] != 'f' || fname[2] != ':') + return EINVAL; + + *file = (char *)fname + 3; + f->f_flags |= F_NODEV; + f->f_dev = &devsw[0]; + return (0); +} + +void +devboot(dev_t bootdev, char *p) +{ + sector = bootdev; /* passed from pbr */ + p[0] = 'c'; + p[1] = 'f'; + p[2] = '\0'; +} + +char * +ttyname(int fd) +{ + return "scif"; +} + +dev_t +ttydev(char *name) +{ + return NODEV; +} + +int +cnspeed(dev_t dev, int sp) +{ + scif_init(sp); + return sp; +} + +void +run_loadfile(u_long *marks, int howto) +{ + u_long entry; + + entry = marks[MARK_ENTRY]; + + printf("entry point at 0x%x\n", (int)entry); + (*(void (*)(int,int,int))entry)(howto, marks[MARK_END], 0); +} + +int +blkdevopen(struct open_file *f, ...) +{ + return 0; +} + +int +blkdevstrategy(void *v, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize) +{ + + if (flag != F_READ) + return EROFS; + + if (size & (DEV_BSIZE - 1)) + return EINVAL; + + if (rsize) + *rsize = size; + + if (size != 0 && readsects(0x40, sector + dblk, buf, + size / DEV_BSIZE) != 0) + return EIO; + + return 0; +} + +int +blkdevclose(struct open_file *f) +{ + return 0; +} + +int pch_pos = 0; + +void +putchar(int c) +{ + switch (c) { + case '\177': /* DEL erases */ + scif_putc('\b'); + scif_putc(' '); + case '\b': + scif_putc('\b'); + if (pch_pos) + pch_pos--; + break; + case '\t': + do + scif_putc(' '); + while (++pch_pos % 8); + break; + case '\n': + scif_putc(c); + case '\r': + scif_putc('\r'); + pch_pos=0; + break; + default: + scif_putc(c); + pch_pos++; + break; + } +} + +int +getchar(void) +{ + int c = scif_getc(); + + if (c == '\r') + c = '\n'; + + if ((c < ' ' && c != '\n') || c == '\177') + return c; + + putchar(c); + return c; +} diff --git a/sys/arch/landisk/stand/boot/getsecs.c b/sys/arch/landisk/stand/boot/getsecs.c new file mode 100644 index 00000000000..64c21d7ad31 --- /dev/null +++ b/sys/arch/landisk/stand/boot/getsecs.c @@ -0,0 +1,202 @@ +/* $NetBSD: getsecs.c,v 1.2 2006/09/11 13:48:57 nonaka Exp $ */ + +#include <sys/param.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> + +#include <lib/libsa/stand.h> +#include <lib/libsa/net.h> +#include <lib/libsa/netif.h> + +#include <sh/devreg.h> +#include <sh/scireg.h> + +#include <dev/ic/rs5c313reg.h> + +/** + * RICOH RS5C313 + * + * Web page: http://www.ricoh.co.jp/LSI/product_rtc/3wire/5c313/ + * + * How to control RS5C313 on LANDISK + * see http://www.mizore.jp/wiki/index.php?LANDISK/rtc + */ + +uint8_t rtc_read(uint32_t addr); +void rtc_write(uint32_t addr, uint8_t data); + +static void +rtc_init(void) +{ + + SHREG_SCSPTR = SCSPTR_SPB1IO | SCSPTR_SPB1DT + | SCSPTR_SPB0IO | SCSPTR_SPB0DT; +} + +/* control RTC chip enable */ +static void +rtc_ce(int onoff) +{ + + if (onoff) { + _reg_write_1(0xb0000003, (1 << 1)); + } else { + _reg_write_1(0xb0000003, (0 << 1)); + } +} + +static inline void +rtc_clk(int onoff) +{ + + if (onoff) { + SHREG_SCSPTR |= SCSPTR_SPB0DT; + } else { + SHREG_SCSPTR &= ~SCSPTR_SPB0DT; + } +} + +static void +rtc_dir(int output) +{ + + if (output) { + SHREG_SCSPTR |= SCSPTR_SPB1IO; + } else { + SHREG_SCSPTR &= ~SCSPTR_SPB1IO; + } +} + +/* data-out */ +static void +rtc_do(int onoff) +{ + + if (onoff) { + SHREG_SCSPTR |= SCSPTR_SPB1DT; + } else { + SHREG_SCSPTR &= ~SCSPTR_SPB1DT; + } + + rtc_clk(0); + rtc_clk(1); +} + +/* data-in */ +static int +rtc_di(void) +{ + int d; + + d = (SHREG_SCSPTR & SCSPTR_SPB1DT) ? 1 : 0; + + rtc_clk(0); + rtc_clk(1); + + return d; +} + +uint8_t +rtc_read(uint32_t addr) +{ + uint8_t data; + + rtc_init(); + rtc_ce(1); + + rtc_dir(1); + rtc_do(1); /* Don't care */ + rtc_do(1); /* R/#W = 1(READ) */ + rtc_do(1); /* AD = 1 */ + rtc_do(0); /* DT = 0 */ + rtc_do(addr & 0x8); /* A3 */ + rtc_do(addr & 0x4); /* A2 */ + rtc_do(addr & 0x2); /* A1 */ + rtc_do(addr & 0x1); /* A0 */ + + rtc_dir(0); + (void)rtc_di(); + (void)rtc_di(); + (void)rtc_di(); + (void)rtc_di(); + data = rtc_di(); /* D3 */ + data <<= 1; + data |= rtc_di(); /* D2 */ + data <<= 1; + data |= rtc_di(); /* D1 */ + data <<= 1; + data |= rtc_di(); /* D0 */ + + rtc_ce(0); + + return data & 0xf; +} + +void +rtc_write(uint32_t addr, uint8_t data) +{ + + rtc_init(); + rtc_ce(1); + + rtc_dir(1); + rtc_do(1); /* Don't care */ + rtc_do(0); /* R/#W = 0(WRITE) */ + rtc_do(1); /* AD = 1 */ + rtc_do(0); /* DT = 0 */ + rtc_do(addr & 0x8); /* A3 */ + rtc_do(addr & 0x4); /* A2 */ + rtc_do(addr & 0x2); /* A1 */ + rtc_do(addr & 0x1); /* A0 */ + + rtc_do(1); /* Don't care */ + rtc_do(0); /* R/#W = 0(WRITE) */ + rtc_do(0); /* AD = 0 */ + rtc_do(1); /* DT = 1 */ + rtc_do(data & 0x8); /* D3 */ + rtc_do(data & 0x4); /* D2 */ + rtc_do(data & 0x2); /* D1 */ + rtc_do(data & 0x1); /* D0 */ + + rtc_ce(0); +} + +time_t +getsecs(void) +{ + uint32_t sec, min, hour, day; +#if 0 + uint32_t mon, year; +#endif + time_t secs; + + sec = rtc_read(RS5C313_SEC1); + sec += rtc_read(RS5C313_SEC10) * 10; + min = rtc_read(RS5C313_MIN1); + min += rtc_read(RS5C313_MIN10) * 10; + hour = rtc_read(RS5C313_HOUR1); + hour += rtc_read(RS5C313_HOUR10) * 10; + day = rtc_read(RS5C313_DAY1); + day += rtc_read(RS5C313_DAY10) * 10; +#if 0 + mon = rtc_read(RS5C313_MON1); + mon += rtc_read(RS5C313_MON10) * 10; + year = rtc_read(RS5C313_YEAR1); + year += rtc_read(RS5C313_YEAR10) * 10; +#endif + + secs = sec; + secs += min * 60; + secs += hour * 60 * 60; + secs += day * 60 * 60 * 24; +#if 0 + /* XXX mon, year */ +#endif + +#if defined(DEBUG) + printf("getsecs: secs = %d\n", (uint32_t)secs); +#endif + + return secs; +} diff --git a/sys/arch/landisk/stand/boot/libsa.h b/sys/arch/landisk/stand/boot/libsa.h new file mode 100644 index 00000000000..5b24d33fd0a --- /dev/null +++ b/sys/arch/landisk/stand/boot/libsa.h @@ -0,0 +1,34 @@ +/* $OpenBSD: libsa.h,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ + +/* + * Copyright (c) 2006 Michael Shalayeff + * All rights reserved. + * + * 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 MIND, 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 0 + +#define PCLOCK 33333333 + +int readsects(int dev, uint32_t lba, void *buf, size_t size); +int blkdevopen(struct open_file *, ...); +int blkdevclose(struct open_file *); +int blkdevstrategy(void *, int, daddr_t, size_t, void *, size_t *); +void scif_init(unsigned int); +int scif_getc(void); +void scif_putc(int); diff --git a/sys/arch/landisk/stand/boot/scifcons.c b/sys/arch/landisk/stand/boot/scifcons.c new file mode 100644 index 00000000000..63551234f13 --- /dev/null +++ b/sys/arch/landisk/stand/boot/scifcons.c @@ -0,0 +1,250 @@ +/* $OpenBSD: scifcons.c,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ +/* $NetBSD: scifcons.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ +/* NetBSD: scif.c,v 1.38 2004/12/13 02:14:13 chs Exp */ + +/*- + * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. 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. + */ +/*- + * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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) 1991 The Regents of the University of California. + * 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. 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. + * + * @(#)com.c 7.5 (Berkeley) 5/16/91 + */ +/* + * SH internal serial driver + * + * This code is derived from both z8530tty.c and com.c + */ + +#include <libsa.h> + +#include <sh/scifreg.h> + +#define scif_smr_read() SHREG_SCSMR2 +#define scif_smr_write(v) (SHREG_SCSMR2 = (v)) + +#define scif_brr_read() SHREG_SCBRR2 +#define scif_brr_write(v) (SHREG_SCBRR2 = (v)) + +#define scif_scr_read() SHREG_SCSCR2 +#define scif_scr_write(v) (SHREG_SCSCR2 = (v)) + +#define scif_ftdr_write(v) (SHREG_SCFTDR2 = (v)) + +#define scif_ssr_read() SHREG_SCSSR2 +#define scif_ssr_write(v) (SHREG_SCSSR2 = (v)) + +#define scif_frdr_read() SHREG_SCFRDR2 + +#define scif_fcr_read() SHREG_SCFCR2 +#define scif_fcr_write(v) (SHREG_SCFCR2 = (v)) + +#define scif_fdr_read() SHREG_SCFDR2 + +#define scif_sptr_read() SHREG_SCSPTR2 +#define scif_sptr_write(v) (SHREG_SCSPTR2 = (v)) + +#define scif_lsr_read() SHREG_SCLSR2 +#define scif_lsr_write(v) (SHREG_SCLSR2 = (v)) + +#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */ + +#define SERBUFSIZE 16 +static u_char serbuf[SERBUFSIZE]; +static int serbuf_read = 0; +static int serbuf_write = 0; + +void +scif_init(unsigned int bps) +{ + + serbuf_read = 0; + serbuf_write = 0; + + /* Initialize SCR */ + scif_scr_write(0x00); + + /* Clear FIFO */ + scif_fcr_write(SCFCR2_TFRST | SCFCR2_RFRST); + + /* Serial Mode Register */ + scif_smr_write(0x00); /* 8bit,NonParity,Even,1Stop */ + + /* Bit Rate Register */ + scif_brr_write(divrnd(PCLOCK, 32 * bps) - 1); + + delay(100); + + scif_sptr_write(SCSPTR2_RTSIO); + + scif_fcr_write(FIFO_RCV_TRIGGER_1 | FIFO_XMT_TRIGGER_8); + + /* Send permission, Receive permission ON */ + scif_scr_write(SCSCR2_TE | SCSCR2_RE); + + /* Serial Status Register */ + scif_ssr_write(scif_ssr_read() & SCSSR2_TDFE); /* Clear Status */ +} + +int +scif_getc(void) +{ + unsigned char c, err_c; + unsigned short err_c2; + + if (serbuf_read != serbuf_write) { + c = serbuf[serbuf_read]; + serbuf_read = (serbuf_read + 1) % SERBUFSIZE; + return (c); + } + + for (;;) { + /* wait for ready */ + while ((scif_fdr_read() & SCFDR2_RECVCNT) == 0) + continue; + + c = scif_frdr_read(); + err_c = scif_ssr_read(); + scif_ssr_write(scif_ssr_read() + & ~(SCSSR2_ER | SCSSR2_BRK | SCSSR2_RDF | SCSSR2_DR)); + + err_c2 = scif_lsr_read(); + scif_lsr_write(scif_lsr_read() & ~SCLSR2_ORER); + + if ((err_c & (SCSSR2_ER | SCSSR2_BRK | SCSSR2_FER + | SCSSR2_PER)) == 0) { + if ((err_c2 & SCLSR2_ORER) == 0) { + return (c); + } + } + } +} + +void +scif_putc(int c) +{ + + /* wait for ready */ + while ((scif_fdr_read() & SCFDR2_TXCNT) == SCFDR2_TXF_FULL) + continue; + + /* write send data to send register */ + scif_ftdr_write(c); + + /* clear ready flag */ + scif_ssr_write(scif_ssr_read() & ~(SCSSR2_TDFE | SCSSR2_TEND)); +} + +int +cnischar(void) +{ + unsigned char c, err_c; + unsigned short err_c2; + + /* check if any preread input is already there */ + if (serbuf_read != serbuf_write) + return (1); + + if (scif_fdr_read() & SCFDR2_RECVCNT) { + c = scif_frdr_read(); + err_c = scif_ssr_read(); + scif_ssr_write(scif_ssr_read() + & ~(SCSSR2_ER | SCSSR2_BRK | SCSSR2_RDF | SCSSR2_DR)); + + err_c2 = scif_lsr_read(); + scif_lsr_write(scif_lsr_read() & ~SCLSR2_ORER); + + if ((err_c & (SCSSR2_ER | SCSSR2_BRK | SCSSR2_FER + | SCSSR2_PER)) == 0) { + if ((err_c2 & SCLSR2_ORER) == 0) { + /* stuff char into preread buffer */ + serbuf[serbuf_write] = (u_char)c; + serbuf_write = (serbuf_write + 1) % SERBUFSIZE; + return (1); + } + } + } + return (0); /* nothing out there... */ +} diff --git a/sys/arch/landisk/stand/boot/srt0.S b/sys/arch/landisk/stand/boot/srt0.S new file mode 100644 index 00000000000..3e46a2a2e33 --- /dev/null +++ b/sys/arch/landisk/stand/boot/srt0.S @@ -0,0 +1,153 @@ +/* $OpenBSD: srt0.S,v 1.1 2006/10/06 21:48:50 mickey Exp $ */ +/* $NetBSD: boot.S,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2005 NONAKA Kimihiro + * 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 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. + */ + +#include <machine/asm.h> + +ENTRY(start) + bra boot_start1 + nop + .balign 4 +ENTRY(boot_magic) + .long 0x20041110 +ENTRY(boot_params) + .long boot_start1 - boot_params + + . = start + 0x80 +boot_start1: + mov r4, r0 + add #-4, r0 + mov.l @(0, r0), r0 + mov.l .L.boot_magic1, r1 + cmp/eq r0, r1 + bf 2f + mov r4, r0 + mov.l .L.boot_params_size, r3 + mov.l @r0, r2 + mov.l .L.boot_params, r1 + cmp/hi r3, r2 + bf 1f + mov r3, r2 +1: mov.b @r0+, r3 + mov.b r3, @r1 + dt r2 + bf/s 1b + add #1, r1 +2: + mov.l .L._end, r0 /* zero bss */ + mov.l .L.__bss_start, r1 + sub r1, r0 + shlr2 r0 /* _end and __bss_start are aligned */ + mov #0, r2 +1: mov.l r2, @r1 + dt r0 + bf/s 1b + add #4, r1 + + mov.l .L.boot, r0 + jsr @r0 + mov r5, r4 + +boot_fail: + mov r0, r1 + mova .L.errtxt, r0 + mov r0, r4 + mov #32, r0 + trapa #0x3f + mov r1, r4 + mov #32, r0 + trapa #0x3f + mova .L.crlf, r0 + mov r0, r4 + mov #32, r0 + trapa #0x3f +99: bra 99b + nop + + +ENTRY(halt) + mova .L.pwrctl, r0 + mov #1, r1 + mov.b @r1, r0 + rts + nop + +ENTRY(reboot) +ENTRY(_rtt) + mov #1, r4 /* reboot */ + mov #11, r0 + trapa #0x3f + mov.l .L.start, r0 + jmp @r0 + nop + +/* + * int raise(int sig); + */ +ENTRY(raise) + rts + nop + +/* + * + */ +ENTRY(cnset) + rts + nop + +/* + * int readsects(int dev, uint32_t lba, void *buf, size_t size); + */ +ENTRY(readsects) + mov #2, r0 + trapa #0x3f + rts + nop + + .align 2 +.L.boot_magic1: + .long 0x20031125 +.L.boot_params: + .long boot_params +.L.boot_params_size: + .long boot_start1 - boot_params +.L._end: + .long _end +.L.__bss_start: + .long __bss_start +.L.boot: + .long _C_LABEL(boot) +.L.start: + .long 0xc0000000 +.L.pwrctl: + .long 0xb0000003 + + .align 2 +.L.errtxt: .asciz ">>BOOT FAILED: " + .align 2 +.L.crlf: .asciz "\r\n" |