Home | History | Annotate | Line # | Download | only in mips
mips_arch.cpp revision 1.4
      1  1.4    uch /* -*-C++-*-	$NetBSD: mips_arch.cpp,v 1.4 2004/08/06 18:33:09 uch Exp $	*/
      2  1.1    uch 
      3  1.1    uch /*-
      4  1.1    uch  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1    uch  * All rights reserved.
      6  1.1    uch  *
      7  1.1    uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    uch  * by UCHIYAMA Yasushi.
      9  1.1    uch  *
     10  1.1    uch  * Redistribution and use in source and binary forms, with or without
     11  1.1    uch  * modification, are permitted provided that the following conditions
     12  1.1    uch  * are met:
     13  1.1    uch  * 1. Redistributions of source code must retain the above copyright
     14  1.1    uch  *    notice, this list of conditions and the following disclaimer.
     15  1.1    uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    uch  *    documentation and/or other materials provided with the distribution.
     18  1.1    uch  * 3. All advertising materials mentioning features or use of this software
     19  1.1    uch  *    must display the following acknowledgement:
     20  1.1    uch  *        This product includes software developed by the NetBSD
     21  1.1    uch  *        Foundation, Inc. and its contributors.
     22  1.1    uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1    uch  *    contributors may be used to endorse or promote products derived
     24  1.1    uch  *    from this software without specific prior written permission.
     25  1.1    uch  *
     26  1.1    uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1    uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1    uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1    uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1    uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1    uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1    uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1    uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1    uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1    uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1    uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1    uch  */
     38  1.1    uch #undef DEBUG_KERNADDR_ACCESS
     39  1.1    uch #undef DEBUG_CP0_ACCESS
     40  1.1    uch 
     41  1.1    uch #include <hpcboot.h>
     42  1.1    uch #include <mips/mips_arch.h>
     43  1.1    uch #include <console.h>
     44  1.1    uch #include <memory.h>
     45  1.1    uch 
     46  1.1    uch MIPSArchitecture::MIPSArchitecture(Console *&cons, MemoryManager *&mem)
     47  1.1    uch 	: Architecture(cons, mem)
     48  1.1    uch {
     49  1.1    uch 	/* NO-OP */
     50  1.1    uch }
     51  1.1    uch 
     52  1.1    uch MIPSArchitecture::~MIPSArchitecture(void)
     53  1.1    uch {
     54  1.1    uch 	/* NO-OP */
     55  1.1    uch }
     56  1.1    uch 
     57  1.1    uch void
     58  1.1    uch MIPSArchitecture::systemInfo()
     59  1.1    uch {
     60  1.1    uch 	u_int32_t r0, r1;
     61  1.1    uch 	Architecture::systemInfo();
     62  1.1    uch 	r0 = r1 = 0;
     63  1.1    uch 
     64  1.1    uch #ifdef DEBUG_CP0_ACCESS
     65  1.1    uch 	/* CP0 access test */
     66  1.1    uch 	_kmode = SetKMode(1);
     67  1.1    uch 
     68  1.1    uch 	DPRINTF((TEXT("status register test\n")));
     69  1.1    uch 	GET_SR(r0);
     70  1.1    uch 	DPRINTF((TEXT("current value: 0x%08x\n"), r0));
     71  1.1    uch 	SET_SR(r1);
     72  1.1    uch 	GET_SR(r1);
     73  1.1    uch 	DPRINTF((TEXT("write test:    0x%08x\n"), r1));
     74  1.1    uch 	SET_SR(r0);
     75  1.1    uch 
     76  1.1    uch 	SetKMode(_kmode);
     77  1.1    uch #endif // DEBUG_CP0_ACCESS
     78  1.1    uch }
     79  1.1    uch 
     80  1.1    uch BOOL
     81  1.1    uch MIPSArchitecture::init()
     82  1.1    uch {
     83  1.1    uch 	if (!_mem->init()) {
     84  1.1    uch 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     85  1.1    uch 		return FALSE;
     86  1.1    uch 	}
     87  1.1    uch 
     88  1.1    uch 	return TRUE;
     89  1.1    uch }
     90  1.1    uch 
     91  1.1    uch BOOL
     92  1.1    uch MIPSArchitecture::setupLoader()
     93  1.1    uch {
     94  1.1    uch 	vaddr_t v;
     95  1.1    uch 
     96  1.1    uch #ifdef DEBUG_KERNADDR_ACCESS // kernel address access test
     97  1.4    uch #define	TEST_MAGIC		0xac1dcafe
     98  1.1    uch 	paddr_t p;
     99  1.1    uch 	u_int32_t r0;
    100  1.1    uch 
    101  1.1    uch 	_kmode = SetKMode(1);
    102  1.1    uch 	_mem->getPage(v, p);
    103  1.1    uch 	VOLATILE_REF(ptokv(p)) = TEST_MAGIC;
    104  1.1    uch 	cacheFlush();
    105  1.1    uch 	r0 = VOLATILE_REF(v);
    106  1.1    uch 	DPRINTF((TEXT("kernel address access test: %S\n"),
    107  1.2    uch 	    r0 == TEST_MAGIC ? "OK" : "NG"));
    108  1.1    uch 	SetKMode(_kmode);
    109  1.1    uch #endif // DEBUG_KERNADDR_ACCESS
    110  1.1    uch 
    111  1.1    uch 	if (!_mem->getPage(v , _loader_addr)) {
    112  1.1    uch 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
    113  1.1    uch 		return FALSE;
    114  1.1    uch 	}
    115  1.1    uch 	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
    116  1.2    uch 	    (unsigned)v,(unsigned)_loader_addr));
    117  1.1    uch 
    118  1.1    uch 	memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
    119  1.1    uch 	DPRINTF((TEXT("2nd bootloader copy done.\n")));
    120  1.1    uch 
    121  1.1    uch 	return TRUE;
    122  1.1    uch }
    123  1.1    uch 
    124  1.1    uch void
    125  1.1    uch MIPSArchitecture::jump(paddr_t info, paddr_t pvec)
    126  1.1    uch {
    127  1.1    uch 	kaddr_t sp;
    128  1.1    uch 	vaddr_t v;
    129  1.1    uch 	paddr_t p;
    130  1.1    uch 
    131  1.1    uch 	// stack for bootloader(but mips loader don't use stack)
    132  1.1    uch 	_mem->getPage(v, p);
    133  1.1    uch 	sp = ptokv(p + _mem->getPageSize() - 0x10);
    134  1.1    uch 
    135  1.1    uch 	info = ptokv(info);
    136  1.1    uch 	pvec = ptokv(pvec);
    137  1.1    uch 	_loader_addr = ptokv(_loader_addr);
    138  1.1    uch 
    139  1.1    uch 	// switch kernel mode.
    140  1.1    uch 	SetKMode(1);
    141  1.1    uch 	if (SetKMode(1) != 1) {
    142  1.1    uch 		DPRINTF((TEXT("SetKMode(1) failed.\n")));
    143  1.1    uch 		return;
    144  1.1    uch 	}
    145  1.3  enami 	DPRINTF((TEXT("jump to 0x%08x (info=0x%08x, pvec=0x%08x)\n"),
    146  1.2    uch 	    _loader_addr, info, pvec));
    147  1.1    uch 
    148  1.1    uch 	// writeback whole D-cache and invalidate whole I-cache.
    149  1.1    uch 	// 2nd boot-loader access data via kseg0 which were writed via kuseg,
    150  1.1    uch 	cacheFlush();
    151  1.1    uch 
    152  1.1    uch 	// jump to 2nd-loader(run kseg0)
    153  1.1    uch 	__asm(".set noreorder;"
    154  1.2    uch 	    "jr	a3;"
    155  1.2    uch 	    "move	sp, a2;"
    156  1.2    uch 	    ".set reorder", info, pvec, sp, _loader_addr);
    157  1.1    uch 	// NOTREACHED
    158  1.1    uch }
    159