297 lines
5.1 KiB
C
297 lines
5.1 KiB
C
|
/* $NetBSD: bootxx.c,v 1.1 1998/06/12 21:07:24 tsubai Exp $ */
|
||
|
|
||
|
/*
|
||
|
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
|
||
|
* Copyright (C) 1995, 1996 TooLs GmbH.
|
||
|
* 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 TooLs GmbH.
|
||
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
||
|
* derived from this software without specific prior written permission.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 <machine/bat.h>
|
||
|
|
||
|
int (*openfirmware)(void *);
|
||
|
int stack[1024];
|
||
|
|
||
|
#define MAXBLOCKNUM 16
|
||
|
|
||
|
int block_size = 0;
|
||
|
int block_count = MAXBLOCKNUM;
|
||
|
int block_table[MAXBLOCKNUM] = { 0 };
|
||
|
void (*entry)(void *) = (void *)0x3e0000;
|
||
|
|
||
|
asm("
|
||
|
.text
|
||
|
.align 2
|
||
|
.globl _start
|
||
|
_start:
|
||
|
|
||
|
li 8,0x4000 /* _start */
|
||
|
li 9,0x100
|
||
|
mtctr 9
|
||
|
1:
|
||
|
dcbf 0,8
|
||
|
icbi 0,8
|
||
|
addi 8,8,0x20
|
||
|
bdnz 1b
|
||
|
sync
|
||
|
isync
|
||
|
|
||
|
li 8,0x1ffe /* map the lowest 256MB */
|
||
|
li 9,0x22 /* BAT_I */
|
||
|
mtdbatu 3,8
|
||
|
mtdbatl 3,9
|
||
|
mtibatu 3,8
|
||
|
mtibatl 3,9
|
||
|
isync
|
||
|
|
||
|
lis 1,stack@ha /* setup 4KB of stack */
|
||
|
addi 1,1,stack@l
|
||
|
addi 1,1,4096
|
||
|
|
||
|
b startup
|
||
|
");
|
||
|
|
||
|
|
||
|
static __inline void
|
||
|
OF_exit()
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
} args = {
|
||
|
"exit",
|
||
|
0,
|
||
|
0
|
||
|
};
|
||
|
|
||
|
openfirmware(&args);
|
||
|
for (;;); /* just in case */
|
||
|
}
|
||
|
|
||
|
static __inline int
|
||
|
OF_finddevice(name)
|
||
|
char *name;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
char *device;
|
||
|
int phandle;
|
||
|
} args = {
|
||
|
"finddevice",
|
||
|
1,
|
||
|
1,
|
||
|
};
|
||
|
|
||
|
args.device = name;
|
||
|
openfirmware(&args);
|
||
|
|
||
|
return args.phandle;
|
||
|
}
|
||
|
|
||
|
static __inline int
|
||
|
OF_getprop(handle, prop, buf, buflen)
|
||
|
int handle;
|
||
|
char *prop;
|
||
|
void *buf;
|
||
|
int buflen;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
int phandle;
|
||
|
char *prop;
|
||
|
void *buf;
|
||
|
int buflen;
|
||
|
int size;
|
||
|
} args = {
|
||
|
"getprop",
|
||
|
4,
|
||
|
1,
|
||
|
};
|
||
|
|
||
|
args.phandle = handle;
|
||
|
args.prop = prop;
|
||
|
args.buf = buf;
|
||
|
args.buflen = buflen;
|
||
|
openfirmware(&args);
|
||
|
|
||
|
return args.size;
|
||
|
}
|
||
|
|
||
|
static __inline int
|
||
|
OF_open(dname)
|
||
|
char *dname;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
char *dname;
|
||
|
int handle;
|
||
|
} args = {
|
||
|
"open",
|
||
|
1,
|
||
|
1,
|
||
|
};
|
||
|
|
||
|
args.dname = dname;
|
||
|
openfirmware(&args);
|
||
|
|
||
|
return args.handle;
|
||
|
}
|
||
|
|
||
|
static __inline void
|
||
|
OF_close(handle)
|
||
|
int handle;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
int handle;
|
||
|
} args = {
|
||
|
"close",
|
||
|
1,
|
||
|
0,
|
||
|
};
|
||
|
|
||
|
args.handle = handle;
|
||
|
openfirmware(&args);
|
||
|
}
|
||
|
|
||
|
static __inline int
|
||
|
OF_read(handle, addr, len)
|
||
|
int handle;
|
||
|
void *addr;
|
||
|
int len;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
int ihandle;
|
||
|
void *addr;
|
||
|
int len;
|
||
|
int actual;
|
||
|
} args = {
|
||
|
"read",
|
||
|
3,
|
||
|
1,
|
||
|
};
|
||
|
|
||
|
args.ihandle = handle;
|
||
|
args.addr = addr;
|
||
|
args.len = len;
|
||
|
openfirmware(&args);
|
||
|
|
||
|
return args.actual;
|
||
|
}
|
||
|
|
||
|
static __inline int
|
||
|
OF_seek(handle, pos)
|
||
|
int handle;
|
||
|
u_quad_t pos;
|
||
|
{
|
||
|
static struct {
|
||
|
char *name;
|
||
|
int nargs;
|
||
|
int nreturns;
|
||
|
int handle;
|
||
|
int poshi;
|
||
|
int poslo;
|
||
|
int status;
|
||
|
} args = {
|
||
|
"seek",
|
||
|
3,
|
||
|
1,
|
||
|
};
|
||
|
|
||
|
args.handle = handle;
|
||
|
args.poshi = (int)(pos >> 32);
|
||
|
args.poslo = (int)pos;
|
||
|
openfirmware(&args);
|
||
|
|
||
|
return args.status;
|
||
|
}
|
||
|
|
||
|
|
||
|
char bootpath[128];
|
||
|
|
||
|
void
|
||
|
startup(arg1, arg2, openfirm)
|
||
|
int arg1, arg2;
|
||
|
void *openfirm;
|
||
|
{
|
||
|
int fd, blk, chosen;
|
||
|
int i;
|
||
|
char *addr;
|
||
|
|
||
|
openfirmware = openfirm;
|
||
|
|
||
|
chosen = OF_finddevice("/chosen");
|
||
|
OF_getprop(chosen, "bootpath", bootpath, sizeof(bootpath));
|
||
|
|
||
|
/*
|
||
|
* "scsi/sd@0:0" --> "scsi/sd@0"
|
||
|
*/
|
||
|
for (i = 0; i < sizeof(bootpath); i++)
|
||
|
if (bootpath[i] == ':')
|
||
|
bootpath[i] = 0;
|
||
|
|
||
|
fd = OF_open(bootpath);
|
||
|
|
||
|
addr = (char *)entry;
|
||
|
for (i = 0; i < block_count; i++) {
|
||
|
blk = block_table[i];
|
||
|
|
||
|
OF_seek(fd, (u_quad_t)blk * 512);
|
||
|
OF_read(fd, addr, block_size);
|
||
|
addr += block_size;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* enable D/I cache
|
||
|
*/
|
||
|
asm("
|
||
|
mtdbatu 3,%0
|
||
|
mtdbatl 3,%1
|
||
|
mtibatu 3,%0
|
||
|
mtibatl 3,%1
|
||
|
isync
|
||
|
" :: "r"(BATU(0)), "r"(BATL(0, 0)));
|
||
|
|
||
|
entry(openfirm);
|
||
|
|
||
|
OF_exit();
|
||
|
for (;;);
|
||
|
}
|