Home | History | Annotate | Line # | Download | only in sh3
sh_arch.cpp revision 1.7.2.2
      1  1.7.2.2  jdolecek /*	$NetBSD: sh_arch.cpp,v 1.7.2.2 2002/03/16 15:57:52 jdolecek Exp $	*/
      2      1.1       uch 
      3      1.1       uch /*-
      4  1.7.2.1  jdolecek  * Copyright (c) 2001, 2002 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 
     39  1.7.2.1  jdolecek #include <hpcboot.h>
     40      1.2       uch #include <hpcmenu.h>
     41      1.1       uch #include <sh3/sh_arch.h>
     42  1.7.2.2  jdolecek 
     43  1.7.2.2  jdolecek SH_BOOT_FUNC_(7709);
     44  1.7.2.2  jdolecek SH_BOOT_FUNC_(7709A);
     45  1.7.2.2  jdolecek SH_BOOT_FUNC_(7750);
     46  1.7.2.2  jdolecek 
     47  1.7.2.2  jdolecek static int _cpu_type;
     48  1.7.2.2  jdolecek 
     49  1.7.2.2  jdolecek int
     50  1.7.2.2  jdolecek SHArchitecture::cpu_type()
     51  1.7.2.2  jdolecek {
     52  1.7.2.2  jdolecek 	if (_cpu_type == 0) {
     53  1.7.2.2  jdolecek 		SYSTEM_INFO si;
     54  1.7.2.2  jdolecek 		GetSystemInfo(&si);
     55  1.7.2.2  jdolecek 		_cpu_type = si.wProcessorLevel;
     56  1.7.2.2  jdolecek 	}
     57  1.7.2.2  jdolecek 
     58  1.7.2.2  jdolecek 	return _cpu_type;
     59  1.7.2.2  jdolecek }
     60      1.1       uch 
     61      1.1       uch BOOL
     62  1.7.2.2  jdolecek SHArchitecture::init()
     63      1.1       uch {
     64  1.7.2.1  jdolecek 
     65      1.1       uch 	if (!_mem->init()) {
     66      1.1       uch 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     67      1.1       uch 		return FALSE;
     68      1.1       uch 	}
     69  1.7.2.2  jdolecek 	// D-RAM information
     70  1.7.2.1  jdolecek 	DPRINTF((TEXT("Memory Bank:\n")));
     71      1.1       uch 
     72      1.1       uch 	return TRUE;
     73      1.1       uch }
     74      1.1       uch 
     75  1.7.2.2  jdolecek void
     76  1.7.2.2  jdolecek SHArchitecture::systemInfo()
     77  1.7.2.2  jdolecek {
     78  1.7.2.2  jdolecek 
     79  1.7.2.2  jdolecek 	// Windows CE common infomation.
     80  1.7.2.2  jdolecek 	super::systemInfo();
     81  1.7.2.2  jdolecek 
     82  1.7.2.2  jdolecek 	// CPU specific.
     83  1.7.2.2  jdolecek 	_dev->dump(HPC_MENU._cons_parameter);
     84  1.7.2.2  jdolecek }
     85  1.7.2.2  jdolecek 
     86      1.1       uch BOOL
     87      1.1       uch SHArchitecture::setupLoader()
     88      1.1       uch {
     89      1.1       uch 	vaddr_t v;
     90      1.1       uch 
     91      1.1       uch 	if (!_mem->getPage(v , _loader_addr)) {
     92      1.1       uch 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
     93      1.1       uch 		return FALSE;
     94      1.1       uch 	}
     95  1.7.2.2  jdolecek 	_loader_addr = ptokv(_loader_addr);
     96  1.7.2.2  jdolecek 
     97  1.7.2.2  jdolecek 	DPRINTF((TEXT("2nd bootloader address U0: 0x%08x P1: 0x%08x\n"),
     98      1.7       uch 	    (unsigned)v,(unsigned)_loader_addr));
     99      1.1       uch 
    100      1.1       uch 	memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
    101      1.1       uch 
    102      1.1       uch 	return TRUE;
    103      1.1       uch }
    104      1.1       uch 
    105      1.1       uch void
    106      1.1       uch SHArchitecture::jump(paddr_t info, paddr_t pvec)
    107      1.1       uch {
    108      1.1       uch 	kaddr_t sp;
    109      1.1       uch 	vaddr_t v;
    110      1.1       uch 	paddr_t p;
    111      1.1       uch 
    112      1.1       uch 	// stack for bootloader
    113      1.1       uch 	_mem->getPage(v, p);
    114      1.1       uch 	sp = ptokv(p + _mem->getPageSize() / 2);
    115      1.1       uch 
    116      1.1       uch 	info = ptokv(info);
    117      1.1       uch 	pvec = ptokv(pvec);
    118  1.7.2.2  jdolecek 
    119  1.7.2.1  jdolecek 	DPRINTF((TEXT("boot arg: 0x%08x stack: 0x%08x\nBooting kernel...\n"),
    120      1.7       uch 	    info, sp));
    121      1.1       uch 
    122      1.1       uch 	// Change to privilege-mode.
    123      1.1       uch 	SetKMode(1);
    124      1.1       uch 
    125      1.1       uch 	// Cache flush(for 2nd bootloader)
    126  1.7.2.1  jdolecek 	//
    127  1.7.2.1  jdolecek 	// SH4 uses WinCE CacheSync(). this routine may causes TLB
    128  1.7.2.1  jdolecek 	// exception. so calls before suspendIntr().
    129  1.7.2.1  jdolecek 	//
    130      1.1       uch 	cache_flush();
    131      1.1       uch 
    132  1.7.2.1  jdolecek 	// Disable external interrupt.
    133  1.7.2.1  jdolecek 	suspendIntr();
    134  1.7.2.1  jdolecek 
    135      1.1       uch 	// jump to 2nd loader.(run P1) at this time I still use MMU.
    136  1.7.2.1  jdolecek 	__asm(
    137  1.7.2.1  jdolecek 	    "mov	r6, r15\n"
    138      1.7       uch 	    "jmp	@r7\n"
    139  1.7.2.1  jdolecek 	    "nop	\n", info, pvec, sp, _loader_addr);
    140      1.1       uch 	// NOTREACHED
    141      1.1       uch }
    142      1.1       uch 
    143      1.1       uch // disable external interrupt and save its priority.
    144      1.1       uch u_int32_t
    145  1.7.2.2  jdolecek suspendIntr()
    146      1.1       uch {
    147      1.1       uch 	u_int32_t sr;
    148  1.7.2.1  jdolecek 
    149  1.7.2.1  jdolecek 	__asm(
    150  1.7.2.1  jdolecek 	    "stc	sr, r0\n"
    151      1.7       uch 	    "mov.l	r0, @r4\n"
    152  1.7.2.2  jdolecek 	    "or		r5, r0\n"
    153      1.7       uch 	    "ldc	r0, sr\n", &sr, 0x000000f0);
    154      1.1       uch 	return sr & 0x000000f0;
    155      1.1       uch }
    156      1.1       uch 
    157      1.1       uch // resume external interrupt priority.
    158      1.1       uch void
    159      1.1       uch resumeIntr(u_int32_t s)
    160      1.1       uch {
    161  1.7.2.1  jdolecek 
    162  1.7.2.2  jdolecek 	__asm(
    163  1.7.2.2  jdolecek 	    "stc	sr, r0\n"
    164      1.7       uch 	    "and	r5, r0\n"
    165  1.7.2.2  jdolecek 	    "or		r4, r0\n"
    166      1.7       uch 	    "ldc	r0, sr\n", s, 0xffffff0f);
    167      1.1       uch }
    168