Initial commit of a 1-stage boot loader for NetBSD/cobalt. Only booting off
the hard drive is supported at the moment.
This commit is contained in:
parent
9ef6b561d7
commit
2b74542ac0
61
sys/arch/cobalt/include/loadfile_machdep.h
Normal file
61
sys/arch/cobalt/include/loadfile_machdep.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* $NetBSD: loadfile_machdep.h,v 1.1 2003/06/25 17:26:25 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _COBALT_LOADFILE_MACHDEP_H_
|
||||
#define _COBALT_LOADFILE_MACHDEP_H_
|
||||
|
||||
#define BOOT_ECOFF
|
||||
#define BOOT_ELF32
|
||||
|
||||
#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA)
|
||||
#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA)
|
||||
|
||||
#define LOADADDR(a) (((u_long)(a)) + offset)
|
||||
#define ALIGNENTRY(a) ((u_long)(a))
|
||||
#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c))
|
||||
#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c))
|
||||
#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c))
|
||||
#define WARN(a) (void)(printf a, \
|
||||
printf((errno ? ": %s\n" : "\n"), \
|
||||
strerror(errno)))
|
||||
#define PROGRESS(a) (void) printf a
|
||||
#define ALLOC(a) alloc(a)
|
||||
#define FREE(a, b) free(a, b)
|
||||
#define OKMAGIC(a) ((a) == OMAGIC)
|
||||
|
||||
#endif /* !_COBALT_LOADFILE_MACHDEP_H_ */
|
@ -1,5 +1,5 @@
|
||||
# $NetBSD: Makefile,v 1.2 2000/06/20 00:24:03 soren Exp $
|
||||
# $NetBSD: Makefile,v 1.3 2003/06/25 17:25:55 cdi Exp $
|
||||
|
||||
SUBDIR= installkernel
|
||||
SUBDIR= installkernel boot
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
98
sys/arch/cobalt/stand/boot/Makefile
Normal file
98
sys/arch/cobalt/stand/boot/Makefile
Normal file
@ -0,0 +1,98 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/06/25 17:24:21 cdi Exp $
|
||||
|
||||
S= ${.CURDIR}/../../../..
|
||||
MIPS= ${S}/arch/mips
|
||||
COBALT= ${S}/arch/cobalt
|
||||
PROG= ${BOOTPROG}
|
||||
|
||||
# .PATH: ${.CURDIR}/../common
|
||||
|
||||
BINMODE?= 444
|
||||
|
||||
.PHONY: machine-links
|
||||
beforedepend: machine-links
|
||||
|
||||
machine-links: machine cobalt mips
|
||||
machine cobalt:
|
||||
-rm -f ${.TARGET}
|
||||
ln -s ${COBALT}/include ${.TARGET}
|
||||
|
||||
mips:
|
||||
-rm -f ${.TARGET}
|
||||
ln -s ${MIPS}/include ${.TARGET}
|
||||
|
||||
CLEANFILES+= machine cobalt mips
|
||||
|
||||
realall: machine-links ${PROG}
|
||||
|
||||
# PRIMARY_LOAD_ADDRESS?= 0x80600000
|
||||
LOAD_ADDRESS?=0x81000000
|
||||
|
||||
COMPORT?=0x0
|
||||
COMBASE?=0xbc800000
|
||||
COMSPEED?=115200
|
||||
COMPROBE?=0xa020001c
|
||||
|
||||
AFLAGS+= -D_LOCORE -D_KERNEL -DASSEMBLER -mno-abicalls
|
||||
|
||||
# -I${.CURDIR}/../.. done by Makefile.inc
|
||||
CPPFLAGS+= -nostdinc -D_STANDALONE -DNO_ABICALLS -D_NO_PROM_DEFINES
|
||||
# CPPFLAGS+= -D_DEBUG
|
||||
CPPFLAGS+= -I${.OBJDIR} -I${S} -I${S}/lib/libsa
|
||||
CPPFLAGS+= -DCONS_SERIAL -DCOMBASE=${COMBASE} -DCOMPORT=${COMPORT}
|
||||
CPPFLAGS+= -DCOMSPEED=${COMSPEED} -DCOMPROBE=${COMPROBE}
|
||||
|
||||
# compiler flags for smallest code size
|
||||
CFLAGS= -Os -mmemcpy -ffreestanding -mno-abicalls -msoft-float -G 128
|
||||
OFORMAT= --oformat elf32-littlemips
|
||||
|
||||
NETBSD_VERS!= sh ${S}/conf/osrelease.sh
|
||||
CPPFLAGS+= -DNETBSD_VERS='"${NETBSD_VERS}"'
|
||||
|
||||
LDSCRIPT?= ${MIPS}/conf/stand.ldscript
|
||||
|
||||
PROG= boot
|
||||
# common sources
|
||||
SRCS+= start.S boot.c devopen.c conf.c clock.c
|
||||
SRCS+= prf.c com.c cons.c ns16550.c pciide.c wdc.c wd.c
|
||||
|
||||
SRCS+= vers.c
|
||||
CLEANFILES+= vers.c
|
||||
|
||||
### find out what to use for libkern
|
||||
KERN_AS= library
|
||||
.include "${S}/lib/libkern/Makefile.inc"
|
||||
|
||||
### find out what to use for libz
|
||||
Z_AS= library
|
||||
.include "${S}/lib/libz/Makefile.inc"
|
||||
|
||||
### find out what to use for libsa
|
||||
SA_AS= library
|
||||
SAMISCMAKEFLAGS+=SA_USE_LOADFILE=yes SA_USE_CREAD=yes
|
||||
.include "${S}/lib/libsa/Makefile.inc"
|
||||
|
||||
LIBS= ${KERNLIB} ${SALIB} ${ZLIB} ${KERNLIB}
|
||||
|
||||
.PHONY: vers.c
|
||||
vers.c: ${.CURDIR}/version
|
||||
sh ${S}/conf/newvers_stand.sh ${.CURDIR}/version "cobalt"
|
||||
|
||||
${PROG}: machine-links ${LDSCRIPT} ${OBJS} ${LIBS}
|
||||
${LD} ${OFORMAT} -Map ${PROG}.map -N -x -Ttext ${LOAD_ADDRESS} \
|
||||
-T ${LDSCRIPT} -e start -o ${PROG} ${OBJS} ${LIBS}
|
||||
gzip -c9 ${PROG} > ${PROG}.gz
|
||||
@${SIZE} ${PROG}
|
||||
|
||||
MAN=
|
||||
CLEANFILES+= ${PROG}.map ${PROG}.elf ${PROG}.gz
|
||||
|
||||
cleandir distclean: cleanlibdir
|
||||
|
||||
cleanlibdir:
|
||||
rm -rf lib
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
/usr/lib/crt0.o:
|
||||
true
|
326
sys/arch/cobalt/stand/boot/boot.c
Normal file
326
sys/arch/cobalt/stand/boot/boot.c
Normal file
@ -0,0 +1,326 @@
|
||||
/* $NetBSD: boot.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jonathan Stone, Michael Hitch, Simon Burge and Wayne Knowles.
|
||||
*
|
||||
* 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 <machine/cpu.h>
|
||||
#include <machine/leds.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libsa/loadfile.h>
|
||||
#include <lib/libkern/libkern.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/exec.h>
|
||||
#include <sys/exec_elf.h>
|
||||
|
||||
#include "boot.h"
|
||||
#include "cons.h"
|
||||
#include "common.h"
|
||||
|
||||
char *kernelnames[] = {
|
||||
"netbsd",
|
||||
"netbsd.gz",
|
||||
"onetbsd",
|
||||
"onetbsd.gz",
|
||||
"netbsd.bak",
|
||||
"netbsd.bak.gz",
|
||||
"netbsd.old",
|
||||
"netbsd.old.gz",
|
||||
"netbsd.cobalt",
|
||||
"netbsd.cobalt.gz",
|
||||
"netbsd.elf",
|
||||
"netbsd.elf.gz",
|
||||
NULL
|
||||
};
|
||||
|
||||
extern long end;
|
||||
static char *bootstring;
|
||||
|
||||
static int patch_bootstring (char *bootspec);
|
||||
static int get_bsdbootname (char **dev, char **name, char **kname);
|
||||
static int prominit (unsigned int memsize);
|
||||
static int print_banner (unsigned int memsize);
|
||||
|
||||
void start(void);
|
||||
int cpu_reboot(void);
|
||||
int main(unsigned int memsize);
|
||||
|
||||
/*
|
||||
* Perform CPU reboot.
|
||||
*/
|
||||
int
|
||||
cpu_reboot()
|
||||
{
|
||||
printf("rebooting...\n\n");
|
||||
|
||||
*(volatile char *)MIPS_PHYS_TO_KSEG1(LED_ADDR) = LED_RESET;
|
||||
printf("WARNING: reboot failed!\n");
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/*
|
||||
* Substitute root value with NetBSD root partition name.
|
||||
*/
|
||||
int
|
||||
patch_bootstring(bootspec)
|
||||
char *bootspec;
|
||||
{
|
||||
char *sp = bootstring;
|
||||
u_int8_t unit, part;
|
||||
int dev, error;
|
||||
char *file;
|
||||
|
||||
DPRINTF(("patch_bootstring: %s\n", bootspec));
|
||||
|
||||
/* get boot parameters */
|
||||
if (devparse(bootspec, &dev, &unit, &part, (const char **)&file) != 0)
|
||||
unit = part = 0;
|
||||
|
||||
DPRINTF(("patch_bootstring: %d, %d\n", unit, part));
|
||||
|
||||
/* take out the 'root=xxx' parameter */
|
||||
if ( (sp = strstr(bootstring, "root=")) != NULL) {
|
||||
const char *end;
|
||||
|
||||
end = strchr(sp, ' ');
|
||||
|
||||
/* strip off leading spaces */
|
||||
for (--sp; (sp > bootstring) && (*sp == ' '); --sp)
|
||||
;
|
||||
|
||||
if (end != NULL)
|
||||
strcpy(++sp, end);
|
||||
else
|
||||
*++sp = '\0';
|
||||
}
|
||||
|
||||
DPRINTF(("patch_bootstring: [%s]\n", bootstring));
|
||||
|
||||
#define DEVNAMESIZE (MAXDEVNAME + sizeof(" root=/dev/hd") + sizeof("0a"))
|
||||
/* bsd notation -> linux notation (wd0a -> hda1) */
|
||||
if (strlen(bootstring) <= (511 - DEVNAMESIZE)) {
|
||||
int len;
|
||||
|
||||
strcat(bootstring, " root=/dev/hd");
|
||||
|
||||
len = strlen(bootstring);
|
||||
bootstring[len++] = unit + 'a';
|
||||
bootstring[len++] = part + '1';
|
||||
bootstring[len++] = '\0';
|
||||
}
|
||||
|
||||
DPRINTF(("patch_bootstring: -> %s\n", bootstring));
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract NetBSD boot specification
|
||||
*/
|
||||
int
|
||||
get_bsdbootname(dev, name, kname)
|
||||
char **dev;
|
||||
char **name;
|
||||
char **kname;
|
||||
{
|
||||
char *spec;
|
||||
|
||||
*dev = NULL;
|
||||
*name = NULL;
|
||||
*kname = NULL;
|
||||
|
||||
if ( (spec = strstr(bootstring, "nbsd=")) != NULL) {
|
||||
int len;
|
||||
char *ptr = strchr(spec, ' ');
|
||||
|
||||
spec += 5; /* skip 'nbsd=' */
|
||||
len = (ptr == NULL) ? strlen(spec) : ptr - spec;
|
||||
|
||||
if (len > 0) {
|
||||
char *devname = alloc(len + 1);
|
||||
if (devname != NULL) {
|
||||
memcpy(devname, spec, len);
|
||||
devname[len] = '\0';
|
||||
|
||||
if ( (ptr = memchr(devname,':',len)) != NULL) {
|
||||
/* wdXX:kernel */
|
||||
*ptr = '\0';
|
||||
*dev = devname;
|
||||
|
||||
if (*++ptr)
|
||||
*kname = ptr;
|
||||
|
||||
devname = alloc(len + 1);
|
||||
if (devname != NULL) {
|
||||
memcpy(devname, spec, len);
|
||||
devname[len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
*name = devname;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the bootstring from PROM.
|
||||
*/
|
||||
int
|
||||
prominit(memsize)
|
||||
unsigned int memsize;
|
||||
{
|
||||
bootstring = (char *)(memsize - 512);
|
||||
bootstring[511] = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* Print boot message.
|
||||
*/
|
||||
int
|
||||
print_banner(memsize)
|
||||
unsigned int memsize;
|
||||
{
|
||||
printf("\n");
|
||||
printf(">> %s " NETBSD_VERS " Bootloader, Revision %s [@%p]\n",
|
||||
bootprog_name, bootprog_rev,
|
||||
(unsigned long)&start & ~PAGE_MASK);
|
||||
printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
|
||||
printf(">> Memory:\t\t%u k\n", (memsize - MIPS_KSEG0_START) / 1024);
|
||||
printf(">> PROM boot string:\t%s\n", bootstring);
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry point.
|
||||
* Parse PROM boot string, load the kernel and jump into it
|
||||
*/
|
||||
int
|
||||
main(memsize)
|
||||
unsigned int memsize;
|
||||
{
|
||||
char *name, **namep, *dev, *kernel, *spec;
|
||||
char bootpath[PATH_MAX];
|
||||
int win;
|
||||
u_long marks[MARK_MAX];
|
||||
void (*entry) __P((unsigned int));
|
||||
|
||||
int addr, speed;
|
||||
|
||||
prominit(memsize);
|
||||
cninit(&addr, &speed);
|
||||
|
||||
print_banner(memsize);
|
||||
|
||||
memset(marks, 0, sizeof marks);
|
||||
get_bsdbootname(&dev, &name, &kernel);
|
||||
|
||||
if (kernel != NULL) {
|
||||
DPRINTF(("kernel: %s\n", kernel));
|
||||
patch_bootstring(name);
|
||||
win = (loadfile(name, marks, LOAD_KERNEL) == 0);
|
||||
} else {
|
||||
win = 0;
|
||||
DPRINTF(("kernel: NULL\n"));
|
||||
for (namep = kernelnames, win = 0;
|
||||
(*namep != NULL) && !win;
|
||||
namep++) {
|
||||
kernel = *namep;
|
||||
|
||||
bootpath[0] = '\0';
|
||||
|
||||
strcpy(bootpath, (dev != NULL) ? dev : "wd0a");
|
||||
strcat(bootpath, ":");
|
||||
strcat(bootpath, kernel);
|
||||
|
||||
printf("Loading: %s\n", bootpath);
|
||||
patch_bootstring(bootpath);
|
||||
win = (loadfile(bootpath, marks, LOAD_ALL) != -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (win) {
|
||||
entry = (void *) marks[MARK_ENTRY];
|
||||
|
||||
printf("Starting at 0x%x\n\n", (u_int)entry);
|
||||
(*entry)(memsize);
|
||||
}
|
||||
|
||||
(void)printf("Boot failed! Rebooting...\n");
|
||||
return (0);
|
||||
}
|
76
sys/arch/cobalt/stand/boot/boot.h
Normal file
76
sys/arch/cobalt/stand/boot/boot.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* $NetBSD: boot.h,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by 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.
|
||||
*/
|
||||
|
||||
#if defined(_DEBUG)
|
||||
#define DPRINTF(x) printf x;
|
||||
#else
|
||||
#define DPRINTF(x)
|
||||
#endif
|
||||
|
||||
#define MAXDEVNAME 16
|
||||
#define DEFKERNELNAME kernelnames[0]
|
||||
|
||||
extern char *kernelnames[];
|
||||
|
||||
/*
|
||||
* com
|
||||
*/
|
||||
int comspeed __P((long));
|
||||
|
||||
/*
|
||||
* console
|
||||
*/
|
||||
char* cninit __P((int *, int *));
|
||||
int cngetc __P((void));
|
||||
void cnputc __P((int));
|
||||
int cnscan __P((void));
|
||||
|
||||
/*
|
||||
* clock
|
||||
*/
|
||||
void delay(int);
|
||||
|
||||
/*
|
||||
* wd
|
||||
*/
|
||||
int wdstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
|
||||
int wdopen __P((struct open_file *, ...));
|
||||
int wdclose __P((struct open_file *));
|
||||
|
||||
/*
|
||||
* devopen
|
||||
*/
|
||||
int devparse (const char *fname, int *dev, u_int8_t *unit,
|
||||
u_int8_t *part, const char **file);
|
55
sys/arch/cobalt/stand/boot/clock.c
Normal file
55
sys/arch/cobalt/stand/boot/clock.c
Normal file
@ -0,0 +1,55 @@
|
||||
/* $NetBSD: clock.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Manuel Bouyer.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <lib/libsa/stand.h>
|
||||
|
||||
#include "boot.h"
|
||||
|
||||
#define DELAY_CALIBRATE 1000
|
||||
|
||||
void
|
||||
delay(int ms)
|
||||
{
|
||||
/*
|
||||
* XXX need *real* clock calibration.
|
||||
*/
|
||||
volatile register int N = ms * DELAY_CALIBRATE;
|
||||
for (; --N;)
|
||||
;
|
||||
}
|
98
sys/arch/cobalt/stand/boot/com.c
Normal file
98
sys/arch/cobalt/stand/boot/com.c
Normal file
@ -0,0 +1,98 @@
|
||||
/* $NetBSD: com.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* Charles M. Hannum. All rights reserved.
|
||||
*
|
||||
* Interrupt processing and hardware flow control partly based on code from
|
||||
* Onno van der Linden and Gordon Ross.
|
||||
*
|
||||
* 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 Charles M. Hannum.
|
||||
* 4. 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) 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. 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.
|
||||
*
|
||||
* @(#)com.c 7.5 (Berkeley) 5/16/91
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define COM_FREQ 1843200 /* 16-bit baud rate divisor */
|
||||
#define COM_TOLERANCE 30 /* baud rate tolerance, in 0.1% units */
|
||||
|
||||
int
|
||||
comspeed(speed)
|
||||
long speed;
|
||||
{
|
||||
#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
|
||||
|
||||
int x, err;
|
||||
long frequency = COM_FREQ * 10;
|
||||
|
||||
if (speed <= 0)
|
||||
return (-1);
|
||||
x = divrnd((frequency / 16), speed);
|
||||
if (x <= 0)
|
||||
return (-1);
|
||||
err = divrnd(((quad_t)frequency) * 1000 / 16, speed * x) - 1000;
|
||||
if (err < 0)
|
||||
err = -err;
|
||||
if (err > COM_TOLERANCE)
|
||||
return (-1);
|
||||
return (x);
|
||||
|
||||
#undef divrnd(n, q)
|
||||
}
|
45
sys/arch/cobalt/stand/boot/common.h
Normal file
45
sys/arch/cobalt/stand/boot/common.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* $NetBSD: common.h,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jonathan Stone, Michael Hitch and Simon Burge.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* vers.c (generated by newvers.sh)
|
||||
*/
|
||||
extern const char bootprog_rev[];
|
||||
extern const char bootprog_name[];
|
||||
extern const char bootprog_date[];
|
||||
extern const char bootprog_maker[];
|
81
sys/arch/cobalt/stand/boot/conf.c
Normal file
81
sys/arch/cobalt/stand/boot/conf.c
Normal file
@ -0,0 +1,81 @@
|
||||
/* $NetBSD: conf.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
* 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. 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.
|
||||
*
|
||||
* @(#)conf.c 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <ufs.h>
|
||||
#include <nfs.h>
|
||||
#include <netif.h>
|
||||
#include <dev_net.h>
|
||||
|
||||
#include "boot.h"
|
||||
|
||||
/*
|
||||
* Device configuration
|
||||
*/
|
||||
struct devsw devsw[] = {
|
||||
{ "wd", wdstrategy, wdopen, wdclose, noioctl },
|
||||
};
|
||||
|
||||
int ndevs = (sizeof(devsw)/sizeof(devsw[0]));
|
||||
|
||||
/*
|
||||
* Filesystem configuration
|
||||
*/
|
||||
struct fs_ops file_system[] = {
|
||||
{ ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat },
|
||||
/* { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat }*/
|
||||
};
|
||||
|
||||
int nfsys = sizeof(file_system) / sizeof(file_system[0]);
|
||||
|
||||
#if 0
|
||||
extern struct netif_driver en_driver;
|
||||
|
||||
struct netif_driver *netif_drivers[] = {
|
||||
&en_driver,
|
||||
};
|
||||
|
||||
int n_netif_drivers = sizeof(netif_drivers) / sizeof(netif_drivers[0]);
|
||||
#endif
|
266
sys/arch/cobalt/stand/boot/cons.c
Normal file
266
sys/arch/cobalt/stand/boot/cons.c
Normal file
@ -0,0 +1,266 @@
|
||||
/* $NetBSD: cons.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 University of Utah.
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* the Systems Programming Group of the University of Utah Computer
|
||||
* Science Department.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* from: Utah Hdr: cons.c 1.7 92/02/28
|
||||
*
|
||||
* @(#)cons.c 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
|
||||
#include "boot.h"
|
||||
#include "cons.h"
|
||||
|
||||
#ifdef CONS_SERIAL
|
||||
void siocnprobe __P((struct consdev *));
|
||||
void siocninit __P((struct consdev *));
|
||||
void siocnputchar __P((void *, int));
|
||||
int siocngetchar __P((void *));
|
||||
int siocnscan __P((void *));
|
||||
# include "ns16550.h"
|
||||
# ifndef COMPORT
|
||||
# define COMPORT COM1
|
||||
# endif
|
||||
# ifndef COMSPEED
|
||||
# define COMSPEED 9600
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct consdev constab[] = {
|
||||
#ifdef CONS_SERIAL
|
||||
{ "com", COMPORT, COMSPEED,
|
||||
siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
struct consdev *cn_tab;
|
||||
|
||||
char *
|
||||
cninit(addr, speed)
|
||||
int *addr;
|
||||
int *speed;
|
||||
{
|
||||
register struct consdev *cp;
|
||||
|
||||
cn_tab = NULL;
|
||||
for (cp = constab; cp->cn_probe; cp++) {
|
||||
(*cp->cn_probe)(cp);
|
||||
if (cp->cn_pri > CN_DEAD &&
|
||||
(cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
|
||||
cn_tab = cp;
|
||||
}
|
||||
if (cn_tab) {
|
||||
(*cn_tab->cn_init)(cn_tab);
|
||||
*addr = cn_tab->address;
|
||||
*speed = cn_tab->speed;
|
||||
return (cn_tab->cn_name);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
cngetc()
|
||||
{
|
||||
|
||||
if (cn_tab)
|
||||
return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cnputc(c)
|
||||
int c;
|
||||
{
|
||||
|
||||
if (cn_tab)
|
||||
(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
|
||||
}
|
||||
|
||||
int
|
||||
cnscan()
|
||||
{
|
||||
|
||||
if (cn_tab)
|
||||
return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef CONS_FB
|
||||
/*
|
||||
* frame buffer console
|
||||
*/
|
||||
void
|
||||
fbcnprobe(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
|
||||
cp->cn_pri = CN_INTERNAL;
|
||||
}
|
||||
|
||||
void
|
||||
fbcninit(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
|
||||
video_init((u_char *)cp->address);
|
||||
kbdreset();
|
||||
}
|
||||
|
||||
int
|
||||
fbcngetchar(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (kbd_getc());
|
||||
}
|
||||
|
||||
void
|
||||
fbcnputchar(dev, c)
|
||||
void *dev;
|
||||
register int c;
|
||||
{
|
||||
|
||||
video_putc(c);
|
||||
}
|
||||
|
||||
int
|
||||
fbcnscan(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (kbd(1));
|
||||
}
|
||||
#endif /* CONS_FB */
|
||||
|
||||
#ifdef CONS_VGA
|
||||
/*
|
||||
* VGA console
|
||||
*/
|
||||
void
|
||||
vgacnprobe(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
cp->cn_pri = CN_NORMAL;
|
||||
}
|
||||
|
||||
void
|
||||
vgacninit(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
|
||||
vga_reset((u_char *)cp->address);
|
||||
vga_init((u_char *)cp->address);
|
||||
kbdreset();
|
||||
}
|
||||
|
||||
int
|
||||
vgacngetchar(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (kbd_getc());
|
||||
}
|
||||
|
||||
void
|
||||
vgacnputchar(dev, c)
|
||||
void *dev;
|
||||
register int c;
|
||||
{
|
||||
|
||||
vga_putc(c);
|
||||
}
|
||||
|
||||
int
|
||||
vgacnscan(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (kbd(1));
|
||||
}
|
||||
#endif /* CONS_VGA */
|
||||
|
||||
#ifdef CONS_SERIAL
|
||||
/*
|
||||
* serial console
|
||||
*/
|
||||
void
|
||||
siocnprobe(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
if (*((unsigned long *)COMPROBE) != 0)
|
||||
cp->cn_pri = CN_REMOTE;
|
||||
}
|
||||
|
||||
void
|
||||
siocninit(cp)
|
||||
struct consdev *cp;
|
||||
{
|
||||
|
||||
cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
|
||||
}
|
||||
|
||||
int
|
||||
siocngetchar(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (NS16550_getc((struct NS16550 *)dev));
|
||||
}
|
||||
|
||||
void
|
||||
siocnputchar(dev, c)
|
||||
void *dev;
|
||||
register int c;
|
||||
{
|
||||
|
||||
if (c == '\n')
|
||||
NS16550_putc((struct NS16550 *)dev, '\r');
|
||||
NS16550_putc((struct NS16550 *)dev, c);
|
||||
}
|
||||
|
||||
int
|
||||
siocnscan(dev)
|
||||
void *dev;
|
||||
{
|
||||
|
||||
return (NS16550_scankbd((struct NS16550 *)dev));
|
||||
}
|
||||
#endif /* CONS_SERIAL */
|
67
sys/arch/cobalt/stand/boot/cons.h
Normal file
67
sys/arch/cobalt/stand/boot/cons.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* $NetBSD: cons.h,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 University of Utah.
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* the Systems Programming Group of the University of Utah Computer
|
||||
* Science Department.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* from: Utah $Hdr: cons.h 1.6 92/01/21$
|
||||
*
|
||||
* @(#)cons.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
struct consdev {
|
||||
char *cn_name; /* console device name */
|
||||
int address; /* address */
|
||||
int speed; /* speed(serial only) */
|
||||
void (*cn_probe) /* probe hardware and fill in consdev info */
|
||||
__P((struct consdev *));
|
||||
void (*cn_init) /* turn on as console */
|
||||
__P((struct consdev *));
|
||||
int (*cn_getc) /* getchar interface */
|
||||
__P((void *));
|
||||
void (*cn_putc) /* putchar interface */
|
||||
__P((void *, int));
|
||||
int (*cn_scan) /* scan interface */
|
||||
__P((void *));
|
||||
int cn_pri; /* pecking order; the higher the better */
|
||||
void *cn_dev; /* device data tag */
|
||||
};
|
||||
|
||||
/* values for cn_pri - reflect our policy for console selection */
|
||||
#define CN_DEAD 0 /* device doesn't exist */
|
||||
#define CN_NORMAL 1 /* device exists but is nothing special */
|
||||
#define CN_INTERNAL 2 /* "internal" bit-mapped display */
|
||||
#define CN_REMOTE 3 /* serial interface with remote bit set */
|
144
sys/arch/cobalt/stand/boot/devopen.c
Normal file
144
sys/arch/cobalt/stand/boot/devopen.c
Normal file
@ -0,0 +1,144 @@
|
||||
/* $NetBSD: devopen.c,v 1.1 2003/06/25 17:24:22 cdi 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libkern/libkern.h>
|
||||
|
||||
#include "boot.h"
|
||||
|
||||
/*
|
||||
* Parse a device spec.
|
||||
*
|
||||
* Format:
|
||||
* [device:][filename]
|
||||
*/
|
||||
int
|
||||
devparse(const char *fname, int *dev, u_int8_t *unit,
|
||||
u_int8_t *part, const char **file)
|
||||
{
|
||||
const char *col;
|
||||
|
||||
*unit = 0; /* default to wd0a */
|
||||
*part = 0;
|
||||
*dev = 0;
|
||||
*file = DEFKERNELNAME;
|
||||
|
||||
if (fname == NULL)
|
||||
return (0);
|
||||
|
||||
if ( (col = strchr(fname, ':')) != NULL) {
|
||||
int devlen;
|
||||
u_int8_t i, u, p;
|
||||
struct devsw *dp;
|
||||
char devname[MAXDEVNAME];
|
||||
|
||||
devlen = col - fname;
|
||||
if (devlen > MAXDEVNAME)
|
||||
return (EINVAL);
|
||||
|
||||
#define isnum(c) (((c) >= '0') && ((c) <= '9'))
|
||||
#define isalpha(c) (((c) >= 'a') && ((c) <= 'z'))
|
||||
|
||||
/* extract device name */
|
||||
for (i = 0; isalpha(fname[i]) && (i < devlen); i++)
|
||||
devname[i] = fname[i];
|
||||
devname[i] = 0;
|
||||
|
||||
if (!isnum(fname[i]))
|
||||
return (EUNIT);
|
||||
|
||||
/* device number */
|
||||
for (u = 0; isnum(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 = ++col;
|
||||
}
|
||||
|
||||
if (*fname)
|
||||
*file = fname;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
devopen(struct open_file *f, const char *fname, char **file)
|
||||
{
|
||||
struct devsw *dp;
|
||||
u_int8_t unit, part;
|
||||
int dev, error;
|
||||
|
||||
DPRINTF(("devopen(%s)\n", fname));
|
||||
|
||||
if ( (error = devparse(fname, &dev, &unit, &part,
|
||||
(const char **)file)) != 0)
|
||||
return error;
|
||||
|
||||
dp = &devsw[dev];
|
||||
if ((void *)dp->dv_open == (void *)nodev)
|
||||
return ENXIO;
|
||||
|
||||
f->f_dev = dp;
|
||||
|
||||
if ( (error = (*dp->dv_open)(f, unit, part)) != 0)
|
||||
printf("%s%d%c: %d = %s\n", devsw[dev].dv_name,
|
||||
unit, 'a' + part, error, strerror(error));
|
||||
|
||||
return error;
|
||||
}
|
105
sys/arch/cobalt/stand/boot/ns16550.c
Normal file
105
sys/arch/cobalt/stand/boot/ns16550.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* $NetBSD: ns16550.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1995-1997 Gary Thomas (gdt@linuxppc.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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Gary Thomas.
|
||||
* 4. 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.
|
||||
*/
|
||||
|
||||
#ifdef CONS_SERIAL
|
||||
/*
|
||||
* NS16550 support
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include "boot.h"
|
||||
#include "ns16550.h"
|
||||
|
||||
int calculated_speed;
|
||||
|
||||
volatile struct NS16550 *
|
||||
NS16550_init(addr, speed)
|
||||
int addr;
|
||||
int speed;
|
||||
{
|
||||
struct NS16550 *com_port;
|
||||
|
||||
com_port = (struct NS16550 *)(COMBASE + addr);
|
||||
|
||||
com_port->lcr = 0x80; /* Access baud rate */
|
||||
speed = comspeed(speed);
|
||||
com_port->dll = speed;
|
||||
com_port->dlm = speed >> 8;
|
||||
|
||||
com_port->lcr = 0x03; /* 8 data, 1 stop, no parity */
|
||||
com_port->mcr = 0x03; /* 8 bits */
|
||||
com_port->fcr = 0x07; /* Clear & enable FIFOs */
|
||||
com_port->ier = 0x00;
|
||||
|
||||
return (com_port);
|
||||
}
|
||||
|
||||
void
|
||||
NS16550_putc(com_port, c)
|
||||
volatile struct NS16550 *com_port;
|
||||
int c;
|
||||
{
|
||||
|
||||
while ((com_port->lsr & LSR_THRE) == 0)
|
||||
;
|
||||
com_port->thr = c;
|
||||
}
|
||||
|
||||
int
|
||||
NS16550_getc(com_port)
|
||||
volatile struct NS16550 *com_port;
|
||||
{
|
||||
|
||||
while ((com_port->lsr & LSR_DR) == 0)
|
||||
;
|
||||
return (com_port->rbr);
|
||||
}
|
||||
|
||||
int
|
||||
NS16550_scankbd(com_port)
|
||||
volatile struct NS16550 *com_port;
|
||||
{
|
||||
|
||||
if ((com_port->lsr & LSR_DR) == 0)
|
||||
return -1;
|
||||
return (com_port->rbr);
|
||||
}
|
||||
|
||||
int
|
||||
NS16550_test(com_port)
|
||||
volatile struct NS16550 *com_port;
|
||||
{
|
||||
|
||||
return ((com_port->lsr & LSR_DR) != 0)
|
||||
;
|
||||
}
|
||||
#endif /* CONS_SERIAL */
|
78
sys/arch/cobalt/stand/boot/ns16550.h
Normal file
78
sys/arch/cobalt/stand/boot/ns16550.h
Normal file
@ -0,0 +1,78 @@
|
||||
/* $NetBSD: ns16550.h,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1995-1997 Gary Thomas (gdt@linuxppc.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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Gary Thomas.
|
||||
* 4. 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NS16550 Serial Port
|
||||
*/
|
||||
|
||||
struct NS16550
|
||||
{
|
||||
volatile unsigned char rbr; /* 0 */
|
||||
volatile unsigned char ier; /* 1 */
|
||||
volatile unsigned char fcr; /* 2 */
|
||||
volatile unsigned char lcr; /* 3 */
|
||||
volatile unsigned char mcr; /* 4 */
|
||||
volatile unsigned char lsr; /* 5 */
|
||||
volatile unsigned char msr; /* 6 */
|
||||
volatile unsigned char scr; /* 7 */
|
||||
};
|
||||
|
||||
#define thr rbr
|
||||
#define iir fcr
|
||||
#define dll rbr
|
||||
#define dlm ier
|
||||
|
||||
#define LSR_DR 0x01 /* Data ready */
|
||||
#define LSR_OE 0x02 /* Overrun */
|
||||
#define LSR_PE 0x04 /* Parity error */
|
||||
#define LSR_FE 0x08 /* Framing error */
|
||||
#define LSR_BI 0x10 /* Break */
|
||||
#define LSR_THRE 0x20 /* Xmit holding register empty */
|
||||
#define LSR_TEMT 0x40 /* Xmitter empty */
|
||||
#define LSR_ERR 0x80 /* Error */
|
||||
|
||||
#define LCR_EERS 0xBF /* Enable access to Enhanced Register Set */
|
||||
#define LCR_DLAB 0x80 /* Divisor latch access enable */
|
||||
|
||||
#ifndef COMBASE
|
||||
#define COMBASE 0x80000000
|
||||
#endif
|
||||
|
||||
#ifndef COMPROBE
|
||||
#define COMPROBE 0xa020001c
|
||||
#endif
|
||||
|
||||
extern volatile struct NS16550 *NS16550_init __P((int, int));
|
||||
extern void NS16550_putc __P((volatile struct NS16550 *, int));
|
||||
extern int NS16550_getc __P((volatile struct NS16550 *));
|
||||
extern int NS16550_scankbd __P((volatile struct NS16550 *));
|
||||
extern int NS16550_test __P((volatile struct NS16550 *));
|
72
sys/arch/cobalt/stand/boot/pciide.c
Normal file
72
sys/arch/cobalt/stand/boot/pciide.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* $NetBSD: pciide.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <mips/cpuregs.h>
|
||||
|
||||
#include "boot.h"
|
||||
#include "wdvar.h"
|
||||
|
||||
int
|
||||
pciide_init(chp, unit)
|
||||
struct channel_softc *chp;
|
||||
u_int8_t *unit;
|
||||
{
|
||||
u_long bpa, addr;
|
||||
int compatchan = 0;
|
||||
|
||||
/*
|
||||
* two channels per chip, two drives per channel
|
||||
*/
|
||||
compatchan = *unit / PCIIDE_CHANNEL_NDEV;
|
||||
if (compatchan >= PCIIDE_NUM_CHANNELS)
|
||||
return (ENXIO);
|
||||
*unit %= PCIIDE_CHANNEL_NDEV;
|
||||
|
||||
DPRINTF(("[pciide] unit: %d, channel: %d\n", *unit, compatchan));
|
||||
|
||||
/*
|
||||
* XXX map?
|
||||
*/
|
||||
bpa = PCIIDE_COMPAT_CMD_BASE(compatchan);
|
||||
addr = MIPS_PHYS_TO_KSEG1(bpa);
|
||||
if (bpa < 0x10000000)
|
||||
addr += 0x10000000;
|
||||
|
||||
chp->c_base = (u_int8_t*)addr;
|
||||
chp->c_data = (u_int16_t*)(addr + wd_data);
|
||||
return (0);
|
||||
}
|
52
sys/arch/cobalt/stand/boot/prf.c
Normal file
52
sys/arch/cobalt/stand/boot/prf.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* $NetBSD: prf.c,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Kazuki Sakamoto.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
|
||||
void
|
||||
putchar(c)
|
||||
unsigned char c;
|
||||
{
|
||||
cnputc(c);
|
||||
}
|
||||
|
||||
int
|
||||
getchar()
|
||||
{
|
||||
return (cngetc());
|
||||
}
|
64
sys/arch/cobalt/stand/boot/start.S
Normal file
64
sys/arch/cobalt/stand/boot/start.S
Normal file
@ -0,0 +1,64 @@
|
||||
/* $NetBSD: start.S,v 1.1 2003/06/25 17:24:22 cdi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Wayne Knowles
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <mips/asm.h>
|
||||
|
||||
LEAF(start)
|
||||
.set noreorder
|
||||
#ifdef __GP_SUPPORT__
|
||||
la gp, _C_LABEL (_gp)
|
||||
#endif
|
||||
la sp, start - CALLFRAME_SIZ
|
||||
sw zero, CALLFRAME_RA(sp) # clear ra for debugger
|
||||
sw zero, CALLFRAME_SP(sp) # clear fp for debugger
|
||||
move s0, a0 # save argc
|
||||
move s1, a1 # save argv
|
||||
|
||||
la a0, _C_LABEL (edata) # clear BSS
|
||||
move a1, zero
|
||||
la a2, _C_LABEL (end)
|
||||
jal _C_LABEL(memset) # memset(edata, 0, end - edata)
|
||||
subu a2, a2, a0
|
||||
|
||||
move a0, s0 # restore argc
|
||||
jal _C_LABEL(main) # main(unsigned int)
|
||||
move a1, s1 # restore argv
|
||||
|
||||
jal _C_LABEL(cpu_reboot) # failed, reboot
|
||||
nop
|
||||
END(start)
|
7
sys/arch/cobalt/stand/boot/version
Normal file
7
sys/arch/cobalt/stand/boot/version
Normal file
@ -0,0 +1,7 @@
|
||||
$NetBSD: version,v 1.1 2003/06/25 17:25:05 cdi Exp $
|
||||
|
||||
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
|
||||
file is important - make sure the entries are appended on end, last item
|
||||
is taken as the current.
|
||||
|
||||
0.1: Initial revision, only booting from the harddrive is supported
|
279
sys/arch/cobalt/stand/boot/wd.c
Normal file
279
sys/arch/cobalt/stand/boot/wd.c
Normal file
@ -0,0 +1,279 @@
|
||||
/* $NetBSD: wd.c,v 1.1 2003/06/25 17:24:23 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Manuel Bouyer.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stdint.h>
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
|
||||
#include <machine/param.h>
|
||||
#include <machine/stdarg.h>
|
||||
|
||||
#include "boot.h"
|
||||
#include "wdvar.h"
|
||||
|
||||
static int wd_get_params(struct wd_softc *wd);
|
||||
static int wdgetdisklabel(struct wd_softc *wd);
|
||||
static void wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp);
|
||||
|
||||
/*
|
||||
* Get drive parameters through 'device identify' command.
|
||||
*/
|
||||
int
|
||||
wd_get_params(wd)
|
||||
struct wd_softc *wd;
|
||||
{
|
||||
int error;
|
||||
unsigned char buf[DEV_BSIZE];
|
||||
|
||||
if ( (error = wdc_exec_identify(wd, buf)) != 0)
|
||||
return (error);
|
||||
|
||||
wd->sc_params = *(struct ataparams *)buf;
|
||||
|
||||
/* 48-bit LBA addressing */
|
||||
if ((wd->sc_params.atap_cmd2_en & WDC_CAP_LBA48) != 0) {
|
||||
DPRINTF(("Drive supports LBA48.\n"));
|
||||
#if defined(_ENABLE_LBA48)
|
||||
wd->sc_flags |= WDF_LBA48;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Prior to ATA-4, LBA was optional. */
|
||||
if ((wd->sc_params.atap_capabilities1 & WDC_CAP_LBA) != 0) {
|
||||
DPRINTF(("Drive supports LBA.\n"));
|
||||
wd->sc_flags |= WDF_LBA;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize disk label to the default value.
|
||||
*/
|
||||
void
|
||||
wdgetdefaultlabel(wd, lp)
|
||||
struct wd_softc *wd;
|
||||
struct disklabel *lp;
|
||||
{
|
||||
memset(lp, 0, sizeof(struct disklabel));
|
||||
|
||||
lp->d_secsize = DEV_BSIZE;
|
||||
lp->d_ntracks = wd->sc_params.atap_heads;
|
||||
lp->d_nsectors = wd->sc_params.atap_sectors;
|
||||
lp->d_ncylinders = wd->sc_params.atap_cylinders;
|
||||
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
||||
|
||||
if (strcmp(wd->sc_params.atap_model, "ST506") == 0)
|
||||
lp->d_type = DTYPE_ST506;
|
||||
else
|
||||
lp->d_type = DTYPE_ESDI;
|
||||
|
||||
strncpy(lp->d_typename, wd->sc_params.atap_model, 16);
|
||||
strncpy(lp->d_packname, "fictitious", 16);
|
||||
if (wd->sc_capacity > UINT32_MAX)
|
||||
lp->d_secperunit = UINT32_MAX;
|
||||
else
|
||||
lp->d_secperunit = wd->sc_capacity;
|
||||
lp->d_rpm = 3600;
|
||||
lp->d_interleave = 1;
|
||||
lp->d_flags = 0;
|
||||
|
||||
lp->d_partitions[RAW_PART].p_offset = 0;
|
||||
lp->d_partitions[RAW_PART].p_size =
|
||||
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
|
||||
lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
|
||||
lp->d_npartitions = MAXPARTITIONS; /* RAW_PART + 1 ??? */
|
||||
|
||||
lp->d_magic = DISKMAGIC;
|
||||
lp->d_magic2 = DISKMAGIC;
|
||||
lp->d_checksum = dkcksum(lp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read disk label from the device.
|
||||
*/
|
||||
int
|
||||
wdgetdisklabel(wd)
|
||||
struct wd_softc *wd;
|
||||
{
|
||||
char *msg;
|
||||
int sector;
|
||||
size_t rsize;
|
||||
struct disklabel *lp;
|
||||
unsigned char buf[DEV_BSIZE];
|
||||
|
||||
wdgetdefaultlabel(wd, &wd->sc_label);
|
||||
|
||||
/*
|
||||
* Find NetBSD Partition in DOS partition table.
|
||||
*/
|
||||
sector = 0;
|
||||
if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize))
|
||||
return EOFFSET;
|
||||
|
||||
if (*(u_int16_t *)&buf[MBR_MAGICOFF] == MBR_MAGIC) {
|
||||
int i;
|
||||
struct mbr_partition *mp;
|
||||
|
||||
/*
|
||||
* Lookup NetBSD slice. If there is none, go ahead
|
||||
* and try to read the disklabel off sector #0.
|
||||
*/
|
||||
mp = (struct mbr_partition *)&buf[MBR_PARTOFF];
|
||||
for (i = 0; i < NMBRPART; i++) {
|
||||
if (mp[i].mbrp_typ == MBR_PTYPE_NETBSD) {
|
||||
sector = mp[i].mbrp_start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE,
|
||||
buf, &rsize))
|
||||
return EOFFSET;
|
||||
|
||||
if ( (msg = getdisklabel(buf + LABELOFFSET, &wd->sc_label)))
|
||||
printf("wd%d: getdisklabel: %s\n", wd->sc_unit, msg);
|
||||
|
||||
lp = &wd->sc_label;
|
||||
|
||||
/* check partition */
|
||||
if ((wd->sc_part >= lp->d_npartitions) ||
|
||||
(lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) {
|
||||
DPRINTF(("illegal partition\n"));
|
||||
return (EPART);
|
||||
}
|
||||
|
||||
DPRINTF(("label info: d_secsize %d, d_nsectors %d, d_ncylinders %d,"
|
||||
"d_ntracks %d, d_secpercyl %d\n",
|
||||
wd->sc_label.d_secsize,
|
||||
wd->sc_label.d_nsectors,
|
||||
wd->sc_label.d_ncylinders,
|
||||
wd->sc_label.d_ntracks,
|
||||
wd->sc_label.d_secpercyl));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open device (read drive parameters and disklabel)
|
||||
*/
|
||||
int
|
||||
wdopen(struct open_file *f, ...)
|
||||
{
|
||||
int error;
|
||||
va_list ap;
|
||||
u_int8_t unit, part;
|
||||
struct wd_softc *wd;
|
||||
|
||||
va_start(ap, f);
|
||||
unit = va_arg(ap, u_int8_t);
|
||||
part = va_arg(ap, u_int8_t);
|
||||
va_end(ap);
|
||||
|
||||
DPRINTF(("wdopen: %d:%d\n", unit, part));
|
||||
|
||||
wd = alloc(sizeof(struct wd_softc));
|
||||
if (wd == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
memset(wd, 0, sizeof(struct wd_softc));
|
||||
|
||||
if (wdc_init(wd, &unit) != 0)
|
||||
return (ENXIO);
|
||||
|
||||
wd->sc_part = part;
|
||||
wd->sc_unit = unit;
|
||||
|
||||
if ( (error = wd_get_params(wd)) != 0)
|
||||
return (error);
|
||||
|
||||
if ( (error = wdgetdisklabel(wd)) != 0)
|
||||
return error;
|
||||
|
||||
f->f_devdata = wd;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close device.
|
||||
*/
|
||||
int
|
||||
wdclose(struct open_file *f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read some data.
|
||||
*/
|
||||
int
|
||||
wdstrategy(f, rw, dblk, size, buf, rsize)
|
||||
void *f;
|
||||
int rw;
|
||||
daddr_t dblk;
|
||||
size_t size;
|
||||
void *buf;
|
||||
size_t *rsize;
|
||||
{
|
||||
int i, nsect;
|
||||
daddr_t blkno;
|
||||
struct wd_softc *wd = f;
|
||||
|
||||
if (size == 0)
|
||||
return (0);
|
||||
|
||||
if (rw != F_READ)
|
||||
return EOPNOTSUPP;
|
||||
|
||||
nsect = howmany(size, wd->sc_label.d_secsize);
|
||||
blkno = dblk + wd->sc_label.d_partitions[wd->sc_part].p_offset;
|
||||
|
||||
for (i = 0; i < nsect; i++, blkno++) {
|
||||
int error;
|
||||
|
||||
if ( (error = wdc_exec_read(wd, WDCC_READ, blkno, buf)) != 0)
|
||||
return (error);
|
||||
|
||||
buf += wd->sc_label.d_secsize;
|
||||
}
|
||||
|
||||
*rsize = size;
|
||||
return (0);
|
||||
}
|
385
sys/arch/cobalt/stand/boot/wdc.c
Normal file
385
sys/arch/cobalt/stand/boot/wdc.c
Normal file
@ -0,0 +1,385 @@
|
||||
/* $NetBSD: wdc.c,v 1.1 2003/06/25 17:24:23 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Manuel Bouyer.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/disklabel_mbr.h>
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <machine/param.h>
|
||||
|
||||
#include "boot.h"
|
||||
#include "wdvar.h"
|
||||
|
||||
#define WDCDELAY 100
|
||||
#define WDCNDELAY_RST 31000 * 10
|
||||
|
||||
static int wdcprobe(struct channel_softc *chp);
|
||||
static int wdc_wait_for_ready(struct channel_softc *chp);
|
||||
static int wdc_read_block(struct wd_softc *sc, struct wdc_command *wd_c);
|
||||
static int __wdcwait_reset(struct channel_softc *chp, int drv_mask);
|
||||
|
||||
/*
|
||||
* Reset the controller.
|
||||
*/
|
||||
static int
|
||||
__wdcwait_reset(chp, drv_mask)
|
||||
struct channel_softc *chp;
|
||||
int drv_mask;
|
||||
{
|
||||
int timeout;
|
||||
u_int8_t st0, st1;
|
||||
|
||||
/* wait for BSY to deassert */
|
||||
for (timeout = 0; timeout < WDCNDELAY_RST; timeout++) {
|
||||
chp->c_base[wd_sdh] = WDSD_IBM; /* master */
|
||||
delay(10);
|
||||
st0 = chp->c_base[wd_status];
|
||||
chp->c_base[wd_sdh] = WDSD_IBM | 0x10; /* slave */
|
||||
delay(10);
|
||||
st1 = chp->c_base[wd_status];
|
||||
|
||||
if ((drv_mask & 0x01) == 0) {
|
||||
/* no master */
|
||||
if ((drv_mask & 0x02) != 0 && (st1 & WDCS_BSY) == 0) {
|
||||
/* No master, slave is ready, it's done */
|
||||
goto end;
|
||||
}
|
||||
} else if ((drv_mask & 0x02) == 0) {
|
||||
/* no slave */
|
||||
if ((drv_mask & 0x01) != 0 && (st0 & WDCS_BSY) == 0) {
|
||||
/* No slave, master is ready, it's done */
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
/* Wait for both master and slave to be ready */
|
||||
if ((st0 & WDCS_BSY) == 0 && (st1 & WDCS_BSY) == 0) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
delay(WDCDELAY);
|
||||
}
|
||||
|
||||
/* Reset timed out. Maybe it's because drv_mask was not right */
|
||||
if (st0 & WDCS_BSY)
|
||||
drv_mask &= ~0x01;
|
||||
if (st1 & WDCS_BSY)
|
||||
drv_mask &= ~0x02;
|
||||
|
||||
end:
|
||||
return (drv_mask);
|
||||
}
|
||||
|
||||
/* Test to see controller with at last one attached drive is there.
|
||||
* Returns a bit for each possible drive found (0x01 for drive 0,
|
||||
* 0x02 for drive 1).
|
||||
* Logic:
|
||||
* - If a status register is at 0xff, assume there is no drive here
|
||||
* (ISA has pull-up resistors). Similarly if the status register has
|
||||
* the value we last wrote to the bus (for IDE interfaces without pullups).
|
||||
* If no drive at all -> return.
|
||||
* - reset the controller, wait for it to complete (may take up to 31s !).
|
||||
* If timeout -> return.
|
||||
*/
|
||||
static int
|
||||
wdcprobe(chp)
|
||||
struct channel_softc *chp;
|
||||
{
|
||||
u_int8_t st0, st1, sc, sn, cl, ch;
|
||||
u_int8_t ret_value = 0x03;
|
||||
u_int8_t drive;
|
||||
int found;
|
||||
|
||||
/*
|
||||
* Sanity check to see if the wdc channel responds at all.
|
||||
*/
|
||||
chp->c_base[wd_sdh] = WDSD_IBM;
|
||||
delay(10);
|
||||
st0 = chp->c_base[wd_status];
|
||||
chp->c_base[wd_sdh] = WDSD_IBM | 0x10;
|
||||
delay(10);
|
||||
st1 = chp->c_base[wd_status];
|
||||
|
||||
if (st0 == 0xff || st0 == WDSD_IBM)
|
||||
ret_value &= ~0x01;
|
||||
if (st1 == 0xff || st1 == (WDSD_IBM | 0x10))
|
||||
ret_value &= ~0x02;
|
||||
if (ret_value == 0)
|
||||
return (ENXIO);
|
||||
|
||||
/* assert SRST, wait for reset to complete */
|
||||
chp->c_base[wd_sdh] = WDSD_IBM;
|
||||
delay(10);
|
||||
chp->c_base[wd_aux_ctlr] = WDCTL_RST | WDCTL_IDS;
|
||||
delay(1000);
|
||||
chp->c_base[wd_aux_ctlr] = WDCTL_IDS;
|
||||
delay(1000);
|
||||
(void) chp->c_base[wd_error];
|
||||
chp->c_base[wd_aux_ctlr] = WDCTL_4BIT;
|
||||
delay(10);
|
||||
|
||||
ret_value = __wdcwait_reset(chp, ret_value);
|
||||
|
||||
/* if reset failed, there's nothing here */
|
||||
if (ret_value == 0)
|
||||
return (ENXIO);
|
||||
|
||||
/*
|
||||
* Test presence of drives. First test register signatures looking for
|
||||
* ATAPI devices. If it's not an ATAPI and reset said there may be
|
||||
* something here assume it's ATA or OLD. Ghost will be killed later in
|
||||
* attach routine.
|
||||
*/
|
||||
found = 0;
|
||||
for (drive = 0; drive < 2; drive++) {
|
||||
if ((ret_value & (0x01 << drive)) == 0)
|
||||
continue;
|
||||
return (0);
|
||||
}
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the device.
|
||||
*/
|
||||
int
|
||||
wdc_init(sc, unit)
|
||||
struct wd_softc *sc;
|
||||
u_int8_t *unit;
|
||||
{
|
||||
if (pciide_init(&sc->sc_channel, unit) != 0)
|
||||
return (ENXIO);
|
||||
if (wdcprobe(&sc->sc_channel) != 0)
|
||||
return (ENXIO);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait until the device is ready.
|
||||
*/
|
||||
int
|
||||
wdc_wait_for_ready(chp)
|
||||
struct channel_softc *chp;
|
||||
{
|
||||
u_int timeout;
|
||||
for (timeout = WDC_TIMEOUT; timeout > 0; --timeout) {
|
||||
if ((chp->c_base[wd_status] & (WDCS_BSY | WDCS_DRDY))
|
||||
== WDCS_DRDY)
|
||||
return (0);
|
||||
}
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read one block off the device.
|
||||
*/
|
||||
int
|
||||
wdc_read_block(sc, wd_c)
|
||||
struct wd_softc *sc;
|
||||
struct wdc_command *wd_c;
|
||||
{
|
||||
int i;
|
||||
struct channel_softc *chp = &sc->sc_channel;
|
||||
u_int16_t *ptr = (u_int16_t*)wd_c->data;
|
||||
|
||||
if (ptr == NULL)
|
||||
return (0);
|
||||
|
||||
for (i = wd_c->bcount; i > 0; i -= sizeof(u_int16_t))
|
||||
*ptr++ = *chp->c_data;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a command to the device (CHS and LBA adressing).
|
||||
*/
|
||||
int
|
||||
wdccommand(sc, wd_c)
|
||||
struct wd_softc *sc;
|
||||
struct wdc_command *wd_c;
|
||||
{
|
||||
u_int8_t err;
|
||||
struct channel_softc *chp = &sc->sc_channel;
|
||||
|
||||
#if 0
|
||||
DPRINTF(("wdccommand(%d, %d, %d, %d, %d, %d, %d)\n",
|
||||
wd_c->drive, wd_c->r_command, wd_c->r_cyl,
|
||||
wd_c->r_head, wd_c->r_sector, wd_c->bcount,
|
||||
wd_c->r_precomp));
|
||||
#endif
|
||||
|
||||
chp->c_base[wd_precomp] = wd_c->r_precomp;
|
||||
chp->c_base[wd_seccnt] = wd_c->r_count;
|
||||
chp->c_base[wd_sector] = wd_c->r_sector;
|
||||
chp->c_base[wd_cyl_lo] = wd_c->r_cyl;
|
||||
chp->c_base[wd_cyl_hi] = wd_c->r_cyl >> 8;
|
||||
chp->c_base[wd_sdh] = WDSD_IBM | (wd_c->drive << 4) | wd_c->r_head;
|
||||
chp->c_base[wd_command] = wd_c->r_command;
|
||||
|
||||
if (wdc_wait_for_ready(chp) != 0)
|
||||
return (ENXIO);
|
||||
|
||||
if (chp->c_base[wd_status] & WDCS_ERR) {
|
||||
printf("wd%d: error %x\n", chp->compatchan,
|
||||
chp->c_base[wd_error]);
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a command to the device (LBA48 addressing).
|
||||
*/
|
||||
int
|
||||
wdccommandext(wd, wd_c)
|
||||
struct wd_softc *wd;
|
||||
struct wdc_command *wd_c;
|
||||
{
|
||||
u_int8_t err;
|
||||
struct channel_softc *chp = &wd->sc_channel;
|
||||
|
||||
/* Select drive, head, and addressing mode. */
|
||||
chp->c_base[wd_sdh] = (wd_c->drive << 4) | WDSD_LBA;
|
||||
|
||||
/* previous */
|
||||
chp->c_base[wd_features] = 0;
|
||||
chp->c_base[wd_seccnt] = wd_c->r_count >> 8;
|
||||
chp->c_base[wd_lba_hi] = wd_c->r_blkno >> 40;
|
||||
chp->c_base[wd_lba_mi] = wd_c->r_blkno >> 32;
|
||||
chp->c_base[wd_lba_lo] = wd_c->r_blkno >> 24;
|
||||
|
||||
/* current */
|
||||
chp->c_base[wd_features] = 0;
|
||||
chp->c_base[wd_seccnt] = wd_c->r_count;
|
||||
chp->c_base[wd_lba_hi] = wd_c->r_blkno >> 16;
|
||||
chp->c_base[wd_lba_mi] = wd_c->r_blkno >> 8;
|
||||
chp->c_base[wd_lba_lo] = wd_c->r_blkno;
|
||||
|
||||
/* Send command. */
|
||||
chp->c_base[wd_command] = wd_c->r_command;
|
||||
|
||||
if (wdc_wait_for_ready(chp) != 0)
|
||||
return (ENXIO);
|
||||
|
||||
if (chp->c_base[wd_status] & WDCS_ERR) {
|
||||
printf("wd%d: error %x\n", chp->compatchan,
|
||||
chp->c_base[wd_error]);
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue 'device identify' command.
|
||||
*/
|
||||
int
|
||||
wdc_exec_identify(wd, data)
|
||||
struct wd_softc *wd;
|
||||
void *data;
|
||||
{
|
||||
int error;
|
||||
struct wdc_command wd_c;
|
||||
|
||||
memset(&wd_c, 0, sizeof(wd_c));
|
||||
|
||||
wd_c.drive = wd->sc_unit;
|
||||
wd_c.r_command = WDCC_IDENTIFY;
|
||||
wd_c.bcount = DEV_BSIZE;
|
||||
wd_c.data = data;
|
||||
|
||||
if ( (error = wdccommand(wd, &wd_c)) != 0)
|
||||
return (error);
|
||||
|
||||
return wdc_read_block(wd, &wd_c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue 'read' command.
|
||||
*/
|
||||
int
|
||||
wdc_exec_read(wd, cmd, blkno, data)
|
||||
struct wd_softc *wd;
|
||||
u_int8_t cmd;
|
||||
daddr_t blkno;
|
||||
void *data;
|
||||
{
|
||||
int error;
|
||||
struct wdc_command wd_c;
|
||||
|
||||
memset(&wd_c, 0, sizeof(wd_c));
|
||||
|
||||
if (wd->sc_flags & WDF_LBA48) {
|
||||
/* LBA48 */
|
||||
wd_c.r_blkno = blkno;
|
||||
} else if (wd->sc_flags & WDF_LBA) {
|
||||
/* LBA */
|
||||
wd_c.r_sector = (blkno >> 0) & 0xff;
|
||||
wd_c.r_cyl = (blkno >> 8) & 0xffff;
|
||||
wd_c.r_head = (blkno >> 24) & 0x0f;
|
||||
wd_c.r_head |= WDSD_LBA;
|
||||
} else {
|
||||
/* LHS */
|
||||
wd_c.r_sector = blkno % wd->sc_label.d_nsectors;
|
||||
wd_c.r_sector++; /* Sectors begin with 1, not 0. */
|
||||
blkno /= wd->sc_label.d_nsectors;
|
||||
wd_c.r_head = blkno % wd->sc_label.d_ntracks;
|
||||
blkno /= wd->sc_label.d_ntracks;
|
||||
wd_c.r_cyl = blkno;
|
||||
wd_c.r_head |= WDSD_CHS;
|
||||
}
|
||||
|
||||
wd_c.data = data;
|
||||
wd_c.r_count = 1;
|
||||
wd_c.drive = wd->sc_unit;
|
||||
wd_c.r_command = cmd;
|
||||
wd_c.bcount = wd->sc_label.d_secsize;
|
||||
|
||||
if (wd->sc_flags & WDF_LBA48)
|
||||
error = wdccommandext(wd, &wd_c);
|
||||
else
|
||||
error = wdccommand(wd, &wd_c);
|
||||
|
||||
if (error != 0)
|
||||
return error;
|
||||
|
||||
return wdc_read_block(wd, &wd_c);
|
||||
}
|
95
sys/arch/cobalt/stand/boot/wdvar.h
Normal file
95
sys/arch/cobalt/stand/boot/wdvar.h
Normal file
@ -0,0 +1,95 @@
|
||||
/* $NetBSD: wdvar.h,v 1.1 2003/06/25 17:24:23 cdi Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2001 Dynarc AB, Sweden. All rights reserved.
|
||||
*
|
||||
* This code is derived from software written by Anders Magnusson,
|
||||
* ragge@ludd.luth.se
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _STAND_WDVAR_H
|
||||
#define _STAND_WDVAR_H
|
||||
|
||||
#include <dev/ic/wdcreg.h>
|
||||
#include <dev/ata/atareg.h>
|
||||
#include <dev/pci/pciidereg.h>
|
||||
|
||||
#include <mips/cpuregs.h>
|
||||
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/disklabel_mbr.h>
|
||||
|
||||
#define WDC_TIMEOUT 2000000
|
||||
#define PCIIDE_CHANNEL_NDEV 2
|
||||
#define NUNITS (PCIIDE_CHANNEL_NDEV * PCIIDE_NUM_CHANNELS)
|
||||
|
||||
struct channel_softc {
|
||||
volatile u_int8_t *c_base;
|
||||
volatile u_int16_t *c_data;
|
||||
|
||||
u_int8_t compatchan;
|
||||
};
|
||||
|
||||
struct wd_softc {
|
||||
#define WDF_LBA 0x0001
|
||||
#define WDF_LBA48 0x0002
|
||||
u_int16_t sc_flags;
|
||||
|
||||
u_int8_t sc_part;
|
||||
u_int8_t sc_unit;
|
||||
|
||||
u_int64_t sc_capacity;
|
||||
|
||||
struct ataparams sc_params;
|
||||
struct disklabel sc_label;
|
||||
struct channel_softc sc_channel;
|
||||
};
|
||||
|
||||
struct wdc_command {
|
||||
u_int8_t drive; /* drive id */
|
||||
|
||||
u_int8_t r_command; /* Parameters to upload to registers */
|
||||
u_int8_t r_head;
|
||||
u_int16_t r_cyl;
|
||||
u_int8_t r_sector;
|
||||
u_int8_t r_count;
|
||||
u_int8_t r_precomp;
|
||||
|
||||
u_int16_t bcount;
|
||||
void *data;
|
||||
|
||||
u_int64_t r_blkno;
|
||||
};
|
||||
|
||||
int wdc_init (struct wd_softc*, u_int8_t*);
|
||||
int wdccommand (struct wd_softc*, struct wdc_command*);
|
||||
int wdccommandext (struct wd_softc*, struct wdc_command*);
|
||||
int wdc_exec_read (struct wd_softc*, u_int8_t, daddr_t, void*);
|
||||
int wdc_exec_identify (struct wd_softc*, void*);
|
||||
|
||||
int pciide_init (struct channel_softc*, u_int8_t*);
|
||||
|
||||
#endif /* _STAND_WDVAR_H */
|
Loading…
Reference in New Issue
Block a user