separate machine-independent part of kloader.

This commit is contained in:
uch 2002-01-29 18:44:22 +00:00
parent 1523771250
commit a312f31998
5 changed files with 228 additions and 134 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kloader.c,v 1.1 2002/01/27 05:14:34 uch Exp $ */
/* $NetBSD: kloader.c,v 1.1 2002/01/29 18:44:25 uch Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "debug_hpcsh.h"
#include "debug_kloader.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -46,73 +46,38 @@
#include <uvm/uvm_extern.h>
#include <hpc/hpc/bootinfo.h>
#include <hpcsh/hpcsh/kloader.h>
#include <machine/kloader.h>
#ifdef KLOADER_DEBUG
#define DPRINTF_ENABLE
#define DPRINTF_DEBUG kloader_debug
#endif
#include <hpcsh/hpcsh/debug.h>
#define USE_HPC_DPRINTF
#define __DPRINTF_EXT
#include <machine/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 kloader {
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 *);
kloader_bootfunc_t *loader;
int setuped;
} kloader;
extern paddr_t avail_start, avail_end;
struct kloader_ops *ops;
};
#define BUCKET_SIZE (PAGE_SIZE - sizeof(struct kloader_page_tag))
#define KLOADER_PROC (&proc0)
STATIC struct kloader kloader;
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 *);
@ -122,10 +87,8 @@ STATIC void kloader_pagetag_dump(void);
STATIC void kloader_bootinfo_dump(void);
#endif
#define KLOADER_PROC (&proc0)
void
kloader_reboot_setup(const char *filename)
__kloader_reboot_setup(struct kloader_ops *ops, const char *filename)
{
if (kloader.bootinfo == NULL) {
@ -133,6 +96,12 @@ kloader_reboot_setup(const char *filename)
return;
}
if (ops == NULL || ops->jump == NULL || ops->boot == NULL) {
PRINTF("No boot operations.\n");
return;
}
kloader.ops = ops;
PRINTF("kernel file name: %s\n", filename);
kloader.vp = kloader_open(filename);
if (kloader.vp == NULL)
@ -161,60 +130,8 @@ kloader_reboot()
#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 */
(*kloader.ops->jump) (kloader.loader, kloader.loader_sp,
kloader.bootinfo, kloader.tagstart);
}
int
@ -250,7 +167,7 @@ kloader_load()
if (ph[i].p_type == PT_LOAD) {
size_t filesz = ph[i].p_filesz;
_DPRINTF("+0x%x", filesz);
sz += sh3_round_page(filesz);
sz += round_page(filesz);
}
}
_DPRINTF(" entry: %08x\n", eh.e_entry);
@ -278,12 +195,10 @@ kloader_load()
/* copy loader code */
KDASSERT(kloader.cur_pg);
kloader.loader = (void *)PG_VADDR(kloader.cur_pg);
memcpy(kloader.loader, kloader_boot, PAGE_SIZE);
memcpy(kloader.loader, kloader.ops->boot, PAGE_SIZE);
/* loader stack */
kloader.cur_pg = TAILQ_NEXT(kloader.cur_pg, pageq);
KDASSERT(kloader.cur_pg);
kloader.loader_sp = (vaddr_t)PG_VADDR(kloader.cur_pg);
kloader.loader_sp = (vaddr_t)kloader.loader + PAGE_SIZE;
/* kernel entry point */
kloader.bootinfo->entry = eh.e_entry;
@ -297,11 +212,11 @@ kloader_load()
int
kloader_alloc_memory(size_t sz)
{
extern paddr_t avail_start, avail_end;
int i, n, error;
n = (sz + BUCKET_SIZE - 1) / BUCKET_SIZE /* kernel */
+ 1 /* 2nd loader */
+ 1; /* 2nd loader's stack */
+ 1; /* 2nd loader */
TAILQ_INIT(&kloader.pg_head);
@ -428,7 +343,7 @@ kloader_read(size_t ofs, size_t size, void *buf)
*/
void
kloader_bootinfo_set(struct kloader_bootinfo *kbi, int argc, char *argv[],
struct bootinfo *bi, boolean_t printok)
struct bootinfo *bi, int printok)
{
char *p, *pend, *buf;
int i;

View File

@ -0,0 +1,72 @@
/* $NetBSD: kloader.h,v 1.1 2002/01/29 18:44:26 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 <machine/bootinfo.h>
struct kloader_ops;
struct kloader_page_tag;
struct kloader_bootinfo;
typedef void kloader_bootfunc_t(struct kloader_bootinfo *,
struct kloader_page_tag *);
struct kloader_ops {
void (*jump)(kloader_bootfunc_t *, vaddr_t, struct kloader_bootinfo *,
struct kloader_page_tag *);
kloader_bootfunc_t *boot;
};
struct kloader_page_tag {
u_int32_t next;
u_int32_t src;
u_int32_t dst;
u_int32_t sz;
} __attribute__((__packed__, __aligned__(4)));
#define KLOADER_KERNELARGS_MAX 256
struct kloader_bootinfo {
vaddr_t entry;
int argc;
char **argv;
struct bootinfo bootinfo;
char _argbuf[KLOADER_KERNELARGS_MAX];
} __attribute__((__packed__, __aligned__(4)));
void __kloader_reboot_setup(struct kloader_ops *, const char *);
void kloader_reboot(void);
void kloader_bootinfo_set(struct kloader_bootinfo *, int, char *[],
struct bootinfo *, int);

View File

@ -1,11 +1,10 @@
# $NetBSD: files.hpcsh,v 1.15 2002/01/27 05:14:33 uch Exp $
# $NetBSD: files.hpcsh,v 1.16 2002/01/29 18:44:25 uch Exp $
#
maxpartitions 8
maxusers 2 16 64
defflag debug_hpcsh.h BUS_SPACE_DEBUG
KLOADER_DEBUG
PFCKBD_DEBUG
HD64461VIDEO_DEBUG
HD64461PCMCIA_DEBUG
@ -18,13 +17,11 @@ 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
file arch/hpc/hpc/kloader.c
file arch/hpcsh/hpcsh/kloader_machdep.c
defflag debug_kloader.h KLOADER_DEBUG
defparam opt_kloader_kernel_path.h KLOADER_KERNEL_PATH
device mainbus { [id = -1] }
#
@ -36,6 +33,13 @@ include "dev/hpc/files.bicons"
include "dev/hpc/files.hpckbd"
include "dev/hpc/files.hpcfb"
#
# Debug utility
#
file arch/hpc/hpc/debug_subr.c
file arch/hpcsh/hpcsh/debug.c
defflag opt_interrupt_monitor.h INTERRUPT_MONITOR
#
# Machine-independent SCSI drivers
#

View File

@ -0,0 +1,113 @@
/* $NetBSD: kloader_machdep.c,v 1.1 2002/01/29 18:44:24 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 <sys/param.h>
#include <sys/systm.h>
#include <sh3/cpufunc.h>
#include <machine/kloader.h>
void kloader_sh3_jump(kloader_bootfunc_t *, vaddr_t,
struct kloader_bootinfo *, struct kloader_page_tag *);
kloader_bootfunc_t kloader_sh3_boot;
struct kloader_ops kloader_sh3_ops = {
.jump = kloader_sh3_jump,
.boot = kloader_sh3_boot
};
void
kloader_reboot_setup(const char *filename)
{
__kloader_reboot_setup(&kloader_sh3_ops, filename);
}
void
kloader_sh3_jump(kloader_bootfunc_t func, vaddr_t sp,
struct kloader_bootinfo *info, struct kloader_page_tag *tag)
{
SH7709A_CACHE_FLUSH();
__asm__ __volatile__(
"mov %0, r4;"
"mov %1, r5;"
"jmp @%2;"
"mov %3, sp"
: : "r"(info), "r"(tag), "r"(func), "r"(sp));
/* NOTREACHED */
}
/*
* 2nd-bootloader. Make sure that PIC and its size is lower than page size.
*/
void
kloader_sh3_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 */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kloader.h,v 1.1 2002/01/27 05:14:34 uch Exp $ */
/* $NetBSD: kloader.h,v 1.1 2002/01/29 18:44:26 uch Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -33,18 +33,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#define KLOADER_KERNELARGS_MAX 256
#include <hpc/include/kloader.h>
struct kloader_bootinfo {
char _argbuf[KLOADER_KERNELARGS_MAX];
vaddr_t entry;
struct bootinfo bootinfo;
int argc;
char **argv;
} __attribute__((__aligned__(4)));
#define PG_VADDR(pg) SH3_PHYS_TO_P1SEG(VM_PAGE_TO_PHYS(pg))
void kloader_reboot_setup(const char *);
void kloader_reboot(void);
void kloader_bootinfo_set(struct kloader_bootinfo *, int, char *[],
struct bootinfo *, boolean_t);