Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/hpcsh add self kernel loader.
details: https://anonhg.NetBSD.org/src/rev/26ebc277ac31
branches: trunk
changeset: 521246:26ebc277ac31
user: uch <uch%NetBSD.org@localhost>
date: Sun Jan 27 05:14:33 2002 +0000
description:
add self kernel loader.
diffstat:
sys/arch/hpcsh/conf/GENERIC | 18 +-
sys/arch/hpcsh/conf/files.hpcsh | 14 +-
sys/arch/hpcsh/hpcsh/kloader.c | 532 ++++++++++++++++++++++++++++++++++++++++
sys/arch/hpcsh/hpcsh/kloader.h | 50 +++
sys/arch/hpcsh/hpcsh/machdep.c | 42 ++-
5 files changed, 636 insertions(+), 20 deletions(-)
diffs (truncated from 782 to 300 lines):
diff -r b1e87cecf1f1 -r 26ebc277ac31 sys/arch/hpcsh/conf/GENERIC
--- a/sys/arch/hpcsh/conf/GENERIC Sun Jan 27 01:50:54 2002 +0000
+++ b/sys/arch/hpcsh/conf/GENERIC Sun Jan 27 05:14:33 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.14 2001/12/28 12:21:56 martin Exp $
+# $NetBSD: GENERIC,v 1.15 2002/01/27 05:14:33 uch Exp $
#
# GENERIC machine description file
#
@@ -22,21 +22,29 @@
maxusers 32 # estimated number of users
+options KLOADER_KERNEL_PATH="\"/netbsd\""
+options KLOADER_DEBUG
+#options INTERRUPT_MONITOR
+#options BUS_SPACE_DEBUG
+#options PFCKBD_DEBUG
+#options HD64461VIDEO_DEBUG
+#options HD64461PCMCIA_DEBUG
+
options SH7709A # 133MHz
options SH7709A_BROKEN_IPR
options PCLOCK=22000000 # 22MHz
options DDB # in-kernel debugger
-options DIAGNOSTIC # extra kernel debugging checks
-options DEBUG # extra kernel debugging support
+#options DIAGNOSTIC # extra kernel debugging checks
+#options DEBUG # extra kernel debugging support
options KTRACE # system call tracing support
options MSGBUFSIZE=65534
# Standard system options
options RTC_OFFSET=-540 # hardware clock is this many mins. west of GMT
-options SCSIVERBOSE # human readable SCSI error messages
-options PCMCIAVERBOSE # verbose PCMCIA configuration messages
+#options SCSIVERBOSE # human readable SCSI error messages
+#options PCMCIAVERBOSE # verbose PCMCIA configuration messages
# Executable format options
options EXEC_COFF # 32-bit COFF executables
diff -r b1e87cecf1f1 -r 26ebc277ac31 sys/arch/hpcsh/conf/files.hpcsh
--- a/sys/arch/hpcsh/conf/files.hpcsh Sun Jan 27 01:50:54 2002 +0000
+++ b/sys/arch/hpcsh/conf/files.hpcsh Sun Jan 27 05:14:33 2002 +0000
@@ -1,9 +1,15 @@
-# $NetBSD: files.hpcsh,v 1.14 2001/07/02 17:19:09 uch Exp $
+# $NetBSD: files.hpcsh,v 1.15 2002/01/27 05:14:33 uch Exp $
#
maxpartitions 8
maxusers 2 16 64
+defflag debug_hpcsh.h BUS_SPACE_DEBUG
+ KLOADER_DEBUG
+ PFCKBD_DEBUG
+ HD64461VIDEO_DEBUG
+ HD64461PCMCIA_DEBUG
+
file arch/hpcsh/hpcsh/conf.c
file arch/hpcsh/hpcsh/machdep.c
file arch/hpcsh/hpcsh/clock.c
@@ -11,7 +17,13 @@
file arch/hpcsh/hpcsh/autoconf.c
file arch/hpcsh/hpcsh/bus_space.c
file arch/hpcsh/hpcsh/procfs_machdep.c procfs
+
file arch/hpcsh/hpcsh/debug.c
+defflag opt_interrupt_monitor.h INTERRUPT_MONITOR
+
+file arch/hpcsh/hpcsh/kloader.c
+defparam opt_kloader_kernel_path.h KLOADER_KERNEL_PATH
+
device mainbus { [id = -1] }
diff -r b1e87cecf1f1 -r 26ebc277ac31 sys/arch/hpcsh/hpcsh/kloader.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcsh/hpcsh/kloader.c Sun Jan 27 05:14:33 2002 +0000
@@ -0,0 +1,532 @@
+/* $NetBSD: kloader.c,v 1.1 2002/01/27 05:14:34 uch Exp $ */
+
+/*-
+ * Copyright (c) 2001, 2002 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 "debug_hpcsh.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/namei.h>
+#include <sys/fcntl.h>
+#define ELFSIZE 32
+#include <sys/exec_elf.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <hpc/hpc/bootinfo.h>
+#include <hpcsh/hpcsh/kloader.h>
+
+#ifdef KLOADER_DEBUG
+#define DPRINTF_ENABLE
+#define DPRINTF_DEBUG kloader_debug
+#endif
+#include <hpcsh/hpcsh/debug.h>
+
+/* XXX-start should be in sh3/include */
+#define SH7709A_CCA 0xf0000000
+
+#define SH7709A_CACHE_LINESZ 16
+#define SH7709A_CACHE_ENTRY 256
+#define SH7709A_CACHE_WAY 4
+#define SH7709A_CACHE_SIZE \
+ (SH7709A_CACHE_LINESZ * SH7709A_CACHE_ENTRY * SH7709A_CACHE_WAY)
+
+#define SH7709A_CACHE_ENTRY_SHIFT 4
+#define SH7709A_CACHE_ENTRY_MASK 0x00000ff0
+#define SH7709A_CACHE_WAY_SHIFT 12
+#define SH7709A_CACHE_WAY_MASK 0x00003000
+
+#define SH7709A_CACHE_FLUSH() \
+do { \
+ u_int32_t __e, __w, __wa, __a; \
+ \
+ for (__w = 0; __w < SH7709A_CACHE_WAY; __w++) { \
+ __wa = SH7709A_CCA | __w << SH7709A_CACHE_WAY_SHIFT; \
+ for (__e = 0; __e < SH7709A_CACHE_ENTRY; __e++) { \
+ __a = __wa |(__e << SH7709A_CACHE_ENTRY_SHIFT); \
+ /* Clear U,V bit */ \
+ (*(__volatile__ u_int32_t *)__a) &= ~0x3; \
+ } \
+ } \
+} while (/*CONSTCOND*/0)
+/* XXX-end should be in sh3/include */
+
+struct kloader_page_tag {
+ u_int32_t next;
+ u_int32_t src;
+ u_int32_t dst;
+ u_int32_t sz;
+};
+#define BUCKET_SIZE (PAGE_SIZE - sizeof(struct kloader_page_tag))
+
+STATIC struct {
+ struct pglist pg_head;
+#define PG_VADDR(pg) SH3_PHYS_TO_P1SEG(VM_PAGE_TO_PHYS(pg))
+ struct vm_page *cur_pg;
+ struct vnode *vp;
+ struct kloader_page_tag *tagstart;
+ struct kloader_bootinfo *bootinfo;
+ vaddr_t loader_sp;
+ void (*loader)(struct kloader_bootinfo *, struct kloader_page_tag *);
+ int setuped;
+} kloader;
+
+extern paddr_t avail_start, avail_end;
+
+STATIC void kloader_boot(struct kloader_bootinfo *, struct kloader_page_tag *);
+STATIC int kloader_load(void);
+STATIC int kloader_alloc_memory(size_t);
+STATIC void kloader_load_segment(vaddr_t, vsize_t, off_t, size_t);
+STATIC void kloader_load_segment_end(void);
+STATIC void kloader_load_bucket(vaddr_t, off_t, size_t);
+
+STATIC struct vnode *kloader_open(const char *);
+STATIC void kloader_close(void);
+STATIC int kloader_read(size_t, size_t, void *);
+
+#ifdef KLOADER_DEBUG
+STATIC void kloader_pagetag_dump(void);
+STATIC void kloader_bootinfo_dump(void);
+#endif
+
+#define KLOADER_PROC (&proc0)
+
+void
+kloader_reboot_setup(const char *filename)
+{
+
+ if (kloader.bootinfo == NULL) {
+ PRINTF("No bootinfo.\n");
+ return;
+ }
+
+ PRINTF("kernel file name: %s\n", filename);
+ kloader.vp = kloader_open(filename);
+ if (kloader.vp == NULL)
+ return;
+
+ if (kloader_load() != 0)
+ goto end;
+
+ kloader.setuped = 1;
+#ifdef KLOADER_DEBUG
+ kloader_pagetag_dump();
+#endif
+ end:
+ kloader_close();
+}
+
+void
+kloader_reboot()
+{
+
+ if (!kloader.setuped)
+ return;
+
+#ifdef KLOADER_DEBUG
+ kloader_bootinfo_dump();
+#endif
+ PRINTF("Rebooting...\n");
+
+ SH7709A_CACHE_FLUSH();
+
+ __asm__ __volatile__(
+ "mov %0, r4;"
+ "mov %1, r5;"
+ "jmp @%2;"
+ "mov %3, sp"
+ : :
+ "r"(kloader.bootinfo),
+ "r"(kloader.tagstart),
+ "r"(kloader.loader),
+ "r"(kloader.loader_sp));
+ /* NOTREACHED */
+}
+
+/*
+ * 2nd-bootloader. Make sure that PIC and its size is lower than page size.
+ */
+void
+kloader_boot(struct kloader_bootinfo *kbi, struct kloader_page_tag *p)
+{
+ int tmp;
+
+ /* Disable interrupt. block exception.(TLB exception don't occur) */
+ __asm__ __volatile__(
+ "stc sr, %1;"
+ "or %0, %1;"
+ "ldc %1, sr" : : "r"(0x500000f0), "r"(tmp));
+
+ /* Now I run on P1, TLB flush. and disable. */
+ SHREG_MMUCR = MMUCR_TF;
+
+ do {
+ u_int32_t *dst =(u_int32_t *)p->dst;
+ u_int32_t *src =(u_int32_t *)p->src;
+ u_int32_t sz = p->sz / sizeof (int);
+ while (sz--)
+ *dst++ = *src++;
+ } while ((p = (struct kloader_page_tag *)p->next) != 0);
+
+ SH7709A_CACHE_FLUSH();
+
+ /* jump to kernel entry. */
+ __asm__ __volatile__(
+ "mov %0, r4;"
+ "mov %1, r5;"
+ "jmp @%3;"
+ "mov %2, r6;"
+ : :
+ "r"(kbi->argc),
+ "r"(kbi->argv),
+ "r"(&kbi->bootinfo),
+ "r"(kbi->entry));
+ /* NOTREACHED */
+}
+
Home |
Main Index |
Thread Index |
Old Index