Home | History | Annotate | Line # | Download | only in sh3
      1  1.15  martin /*	$NetBSD: sh_arch.cpp,v 1.15 2008/04/28 20:23:20 martin Exp $	*/
      2   1.1     uch 
      3   1.1     uch /*-
      4  1.10     uch  * Copyright (c) 2001, 2002, 2004 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  *
     19   1.1     uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     uch  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     uch  */
     31   1.1     uch 
     32   1.8     uch #include <hpcboot.h>
     33   1.2     uch #include <hpcmenu.h>
     34   1.1     uch #include <sh3/sh_arch.h>
     35   1.9     uch 
     36  1.11     uch SH_BOOT_FUNC_(7707);
     37   1.9     uch SH_BOOT_FUNC_(7709);
     38   1.9     uch SH_BOOT_FUNC_(7709A);
     39   1.9     uch SH_BOOT_FUNC_(7750);
     40   1.9     uch 
     41   1.9     uch static int _cpu_type;
     42   1.9     uch 
     43   1.9     uch int
     44   1.9     uch SHArchitecture::cpu_type()
     45   1.9     uch {
     46   1.9     uch 	if (_cpu_type == 0) {
     47  1.10     uch #if _WIN32_WCE == 101
     48  1.10     uch 		_cpu_type = 3;
     49  1.10     uch #else
     50   1.9     uch 		SYSTEM_INFO si;
     51   1.9     uch 		GetSystemInfo(&si);
     52   1.9     uch 		_cpu_type = si.wProcessorLevel;
     53  1.10     uch #endif
     54   1.9     uch 	}
     55   1.9     uch 
     56   1.9     uch 	return _cpu_type;
     57   1.9     uch }
     58   1.1     uch 
     59   1.1     uch BOOL
     60   1.9     uch SHArchitecture::init()
     61   1.1     uch {
     62   1.8     uch 
     63   1.1     uch 	if (!_mem->init()) {
     64   1.1     uch 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     65   1.1     uch 		return FALSE;
     66   1.1     uch 	}
     67   1.9     uch 	// D-RAM information
     68   1.8     uch 	DPRINTF((TEXT("Memory Bank:\n")));
     69   1.1     uch 
     70   1.1     uch 	return TRUE;
     71   1.1     uch }
     72   1.1     uch 
     73   1.9     uch void
     74   1.9     uch SHArchitecture::systemInfo()
     75   1.9     uch {
     76   1.9     uch 
     77  1.13     wiz 	// Windows CE common information.
     78   1.9     uch 	super::systemInfo();
     79   1.9     uch 
     80   1.9     uch 	// CPU specific.
     81   1.9     uch 	_dev->dump(HPC_MENU._cons_parameter);
     82   1.9     uch }
     83   1.9     uch 
     84   1.1     uch BOOL
     85   1.1     uch SHArchitecture::setupLoader()
     86   1.1     uch {
     87   1.1     uch 	vaddr_t v;
     88   1.1     uch 
     89   1.1     uch 	if (!_mem->getPage(v , _loader_addr)) {
     90   1.1     uch 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
     91   1.1     uch 		return FALSE;
     92   1.1     uch 	}
     93   1.9     uch 	_loader_addr = ptokv(_loader_addr);
     94   1.9     uch 
     95   1.9     uch 	DPRINTF((TEXT("2nd bootloader address U0: 0x%08x P1: 0x%08x\n"),
     96   1.7     uch 	    (unsigned)v,(unsigned)_loader_addr));
     97   1.1     uch 
     98   1.1     uch 	memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
     99   1.1     uch 
    100   1.1     uch 	return TRUE;
    101   1.1     uch }
    102   1.1     uch 
    103   1.1     uch void
    104   1.1     uch SHArchitecture::jump(paddr_t info, paddr_t pvec)
    105   1.1     uch {
    106   1.1     uch 	kaddr_t sp;
    107   1.1     uch 	vaddr_t v;
    108   1.1     uch 	paddr_t p;
    109   1.1     uch 
    110   1.1     uch 	// stack for bootloader
    111   1.1     uch 	_mem->getPage(v, p);
    112   1.1     uch 	sp = ptokv(p + _mem->getPageSize() / 2);
    113   1.1     uch 
    114   1.1     uch 	info = ptokv(info);
    115   1.1     uch 	pvec = ptokv(pvec);
    116   1.9     uch 
    117   1.8     uch 	DPRINTF((TEXT("boot arg: 0x%08x stack: 0x%08x\nBooting kernel...\n"),
    118   1.7     uch 	    info, sp));
    119   1.1     uch 
    120   1.1     uch 	// Change to privilege-mode.
    121   1.1     uch 	SetKMode(1);
    122   1.1     uch 
    123   1.8     uch 	// Cache flush(for 2nd bootloader)
    124   1.8     uch 	//
    125   1.8     uch 	// SH4 uses WinCE CacheSync(). this routine may causes TLB
    126   1.8     uch 	// exception. so calls before suspendIntr().
    127   1.8     uch 	//
    128   1.8     uch 	cache_flush();
    129   1.8     uch 
    130   1.1     uch 	// Disable external interrupt.
    131   1.1     uch 	suspendIntr();
    132   1.1     uch 
    133   1.1     uch 	// jump to 2nd loader.(run P1) at this time I still use MMU.
    134   1.8     uch 	__asm(
    135   1.8     uch 	    "mov	r6, r15\n"
    136   1.7     uch 	    "jmp	@r7\n"
    137   1.8     uch 	    "nop	\n", info, pvec, sp, _loader_addr);
    138   1.1     uch 	// NOTREACHED
    139   1.1     uch }
    140   1.1     uch 
    141   1.1     uch // disable external interrupt and save its priority.
    142  1.14     uwe uint32_t
    143   1.9     uch suspendIntr()
    144   1.1     uch {
    145  1.14     uwe 	uint32_t sr;
    146   1.8     uch 
    147   1.8     uch 	__asm(
    148   1.8     uch 	    "stc	sr, r0\n"
    149   1.7     uch 	    "mov.l	r0, @r4\n"
    150   1.9     uch 	    "or		r5, r0\n"
    151   1.7     uch 	    "ldc	r0, sr\n", &sr, 0x000000f0);
    152   1.1     uch 	return sr & 0x000000f0;
    153   1.1     uch }
    154   1.1     uch 
    155   1.1     uch // resume external interrupt priority.
    156   1.1     uch void
    157  1.14     uwe resumeIntr(uint32_t s)
    158   1.1     uch {
    159   1.8     uch 
    160   1.9     uch 	__asm(
    161   1.9     uch 	    "stc	sr, r0\n"
    162   1.7     uch 	    "and	r5, r0\n"
    163   1.9     uch 	    "or		r4, r0\n"
    164   1.7     uch 	    "ldc	r0, sr\n", s, 0xffffff0f);
    165   1.1     uch }
    166