Home | History | Annotate | Line # | Download | only in sh3
sh_arch.cpp revision 1.7.8.2
      1  1.7.8.2  nathanw /*	$NetBSD: sh_arch.cpp,v 1.7.8.2 2002/02/28 04:09:46 nathanw Exp $	*/
      2  1.7.8.2  nathanw 
      3  1.7.8.2  nathanw /*-
      4  1.7.8.2  nathanw  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5  1.7.8.2  nathanw  * All rights reserved.
      6  1.7.8.2  nathanw  *
      7  1.7.8.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.7.8.2  nathanw  * by UCHIYAMA Yasushi.
      9  1.7.8.2  nathanw  *
     10  1.7.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.7.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.7.8.2  nathanw  * are met:
     13  1.7.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.7.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.7.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.7.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.7.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.7.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.7.8.2  nathanw  *    must display the following acknowledgement:
     20  1.7.8.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.7.8.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.7.8.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.7.8.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.7.8.2  nathanw  *    from this software without specific prior written permission.
     25  1.7.8.2  nathanw  *
     26  1.7.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.7.8.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.7.8.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.7.8.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.7.8.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.7.8.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.7.8.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.7.8.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.7.8.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.7.8.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.7.8.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.7.8.2  nathanw  */
     38  1.7.8.2  nathanw 
     39  1.7.8.2  nathanw #include <hpcboot.h>
     40  1.7.8.2  nathanw #include <hpcmenu.h>
     41  1.7.8.2  nathanw #include <sh3/sh_arch.h>
     42  1.7.8.2  nathanw 
     43  1.7.8.2  nathanw SH_BOOT_FUNC_(7709);
     44  1.7.8.2  nathanw SH_BOOT_FUNC_(7709A);
     45  1.7.8.2  nathanw SH_BOOT_FUNC_(7750);
     46  1.7.8.2  nathanw 
     47  1.7.8.2  nathanw static int _cpu_type;
     48  1.7.8.2  nathanw 
     49  1.7.8.2  nathanw int
     50  1.7.8.2  nathanw SHArchitecture::cpu_type()
     51  1.7.8.2  nathanw {
     52  1.7.8.2  nathanw 	if (_cpu_type == 0) {
     53  1.7.8.2  nathanw 		SYSTEM_INFO si;
     54  1.7.8.2  nathanw 		GetSystemInfo(&si);
     55  1.7.8.2  nathanw 		_cpu_type = si.wProcessorLevel;
     56  1.7.8.2  nathanw 	}
     57  1.7.8.2  nathanw 
     58  1.7.8.2  nathanw 	return _cpu_type;
     59  1.7.8.2  nathanw }
     60  1.7.8.2  nathanw 
     61  1.7.8.2  nathanw BOOL
     62  1.7.8.2  nathanw SHArchitecture::init()
     63  1.7.8.2  nathanw {
     64  1.7.8.2  nathanw 
     65  1.7.8.2  nathanw 	if (!_mem->init()) {
     66  1.7.8.2  nathanw 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     67  1.7.8.2  nathanw 		return FALSE;
     68  1.7.8.2  nathanw 	}
     69  1.7.8.2  nathanw 	// D-RAM information
     70  1.7.8.2  nathanw 	DPRINTF((TEXT("Memory Bank:\n")));
     71  1.7.8.2  nathanw 
     72  1.7.8.2  nathanw 	return TRUE;
     73  1.7.8.2  nathanw }
     74  1.7.8.2  nathanw 
     75  1.7.8.2  nathanw void
     76  1.7.8.2  nathanw SHArchitecture::systemInfo()
     77  1.7.8.2  nathanw {
     78  1.7.8.2  nathanw 
     79  1.7.8.2  nathanw 	// Windows CE common infomation.
     80  1.7.8.2  nathanw 	super::systemInfo();
     81  1.7.8.2  nathanw 
     82  1.7.8.2  nathanw 	// CPU specific.
     83  1.7.8.2  nathanw 	_dev->dump(HPC_MENU._cons_parameter);
     84  1.7.8.2  nathanw }
     85  1.7.8.2  nathanw 
     86  1.7.8.2  nathanw BOOL
     87  1.7.8.2  nathanw SHArchitecture::setupLoader()
     88  1.7.8.2  nathanw {
     89  1.7.8.2  nathanw 	vaddr_t v;
     90  1.7.8.2  nathanw 
     91  1.7.8.2  nathanw 	if (!_mem->getPage(v , _loader_addr)) {
     92  1.7.8.2  nathanw 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
     93  1.7.8.2  nathanw 		return FALSE;
     94  1.7.8.2  nathanw 	}
     95  1.7.8.2  nathanw 	_loader_addr = ptokv(_loader_addr);
     96  1.7.8.2  nathanw 
     97  1.7.8.2  nathanw 	DPRINTF((TEXT("2nd bootloader address U0: 0x%08x P1: 0x%08x\n"),
     98  1.7.8.2  nathanw 	    (unsigned)v,(unsigned)_loader_addr));
     99  1.7.8.2  nathanw 
    100  1.7.8.2  nathanw 	memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
    101  1.7.8.2  nathanw 
    102  1.7.8.2  nathanw 	return TRUE;
    103  1.7.8.2  nathanw }
    104  1.7.8.2  nathanw 
    105  1.7.8.2  nathanw void
    106  1.7.8.2  nathanw SHArchitecture::jump(paddr_t info, paddr_t pvec)
    107  1.7.8.2  nathanw {
    108  1.7.8.2  nathanw 	kaddr_t sp;
    109  1.7.8.2  nathanw 	vaddr_t v;
    110  1.7.8.2  nathanw 	paddr_t p;
    111  1.7.8.2  nathanw 
    112  1.7.8.2  nathanw 	// stack for bootloader
    113  1.7.8.2  nathanw 	_mem->getPage(v, p);
    114  1.7.8.2  nathanw 	sp = ptokv(p + _mem->getPageSize() / 2);
    115  1.7.8.2  nathanw 
    116  1.7.8.2  nathanw 	info = ptokv(info);
    117  1.7.8.2  nathanw 	pvec = ptokv(pvec);
    118  1.7.8.2  nathanw 
    119  1.7.8.2  nathanw 	DPRINTF((TEXT("boot arg: 0x%08x stack: 0x%08x\nBooting kernel...\n"),
    120  1.7.8.2  nathanw 	    info, sp));
    121  1.7.8.2  nathanw 
    122  1.7.8.2  nathanw 	// Change to privilege-mode.
    123  1.7.8.2  nathanw 	SetKMode(1);
    124  1.7.8.2  nathanw 
    125  1.7.8.2  nathanw 	// Cache flush(for 2nd bootloader)
    126  1.7.8.2  nathanw 	//
    127  1.7.8.2  nathanw 	// SH4 uses WinCE CacheSync(). this routine may causes TLB
    128  1.7.8.2  nathanw 	// exception. so calls before suspendIntr().
    129  1.7.8.2  nathanw 	//
    130  1.7.8.2  nathanw 	cache_flush();
    131  1.7.8.2  nathanw 
    132  1.7.8.2  nathanw 	// Disable external interrupt.
    133  1.7.8.2  nathanw 	suspendIntr();
    134  1.7.8.2  nathanw 
    135  1.7.8.2  nathanw 	// jump to 2nd loader.(run P1) at this time I still use MMU.
    136  1.7.8.2  nathanw 	__asm(
    137  1.7.8.2  nathanw 	    "mov	r6, r15\n"
    138  1.7.8.2  nathanw 	    "jmp	@r7\n"
    139  1.7.8.2  nathanw 	    "nop	\n", info, pvec, sp, _loader_addr);
    140  1.7.8.2  nathanw 	// NOTREACHED
    141  1.7.8.2  nathanw }
    142  1.7.8.2  nathanw 
    143  1.7.8.2  nathanw // disable external interrupt and save its priority.
    144  1.7.8.2  nathanw u_int32_t
    145  1.7.8.2  nathanw suspendIntr()
    146  1.7.8.2  nathanw {
    147  1.7.8.2  nathanw 	u_int32_t sr;
    148  1.7.8.2  nathanw 
    149  1.7.8.2  nathanw 	__asm(
    150  1.7.8.2  nathanw 	    "stc	sr, r0\n"
    151  1.7.8.2  nathanw 	    "mov.l	r0, @r4\n"
    152  1.7.8.2  nathanw 	    "or		r5, r0\n"
    153  1.7.8.2  nathanw 	    "ldc	r0, sr\n", &sr, 0x000000f0);
    154  1.7.8.2  nathanw 	return sr & 0x000000f0;
    155  1.7.8.2  nathanw }
    156  1.7.8.2  nathanw 
    157  1.7.8.2  nathanw // resume external interrupt priority.
    158  1.7.8.2  nathanw void
    159  1.7.8.2  nathanw resumeIntr(u_int32_t s)
    160  1.7.8.2  nathanw {
    161  1.7.8.2  nathanw 
    162  1.7.8.2  nathanw 	__asm(
    163  1.7.8.2  nathanw 	    "stc	sr, r0\n"
    164  1.7.8.2  nathanw 	    "and	r5, r0\n"
    165  1.7.8.2  nathanw 	    "or		r4, r0\n"
    166  1.7.8.2  nathanw 	    "ldc	r0, sr\n", s, 0xffffff0f);
    167  1.7.8.2  nathanw }
    168