Home | History | Annotate | Line # | Download | only in arm
arm_arch.cpp revision 1.3.8.2
      1  1.3.8.2  uch /*	$NetBSD: arm_arch.cpp,v 1.3.8.2 2001/05/08 18:51:25 uch Exp $	*/
      2  1.3.8.2  uch 
      3  1.3.8.2  uch /*-
      4  1.3.8.2  uch  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.3.8.2  uch  * All rights reserved.
      6  1.3.8.2  uch  *
      7  1.3.8.2  uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3.8.2  uch  * by UCHIYAMA Yasushi.
      9  1.3.8.2  uch  *
     10  1.3.8.2  uch  * Redistribution and use in source and binary forms, with or without
     11  1.3.8.2  uch  * modification, are permitted provided that the following conditions
     12  1.3.8.2  uch  * are met:
     13  1.3.8.2  uch  * 1. Redistributions of source code must retain the above copyright
     14  1.3.8.2  uch  *    notice, this list of conditions and the following disclaimer.
     15  1.3.8.2  uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.8.2  uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.8.2  uch  *    documentation and/or other materials provided with the distribution.
     18  1.3.8.2  uch  * 3. All advertising materials mentioning features or use of this software
     19  1.3.8.2  uch  *    must display the following acknowledgement:
     20  1.3.8.2  uch  *        This product includes software developed by the NetBSD
     21  1.3.8.2  uch  *        Foundation, Inc. and its contributors.
     22  1.3.8.2  uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3.8.2  uch  *    contributors may be used to endorse or promote products derived
     24  1.3.8.2  uch  *    from this software without specific prior written permission.
     25  1.3.8.2  uch  *
     26  1.3.8.2  uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3.8.2  uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3.8.2  uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3.8.2  uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3.8.2  uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3.8.2  uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3.8.2  uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3.8.2  uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3.8.2  uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3.8.2  uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3.8.2  uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.3.8.2  uch  */
     38  1.3.8.2  uch 
     39  1.3.8.2  uch #include <arm/arm_arch.h>
     40  1.3.8.2  uch #include <console.h>
     41  1.3.8.2  uch #include <memory.h>
     42  1.3.8.2  uch #include <arm/arm_sa1100.h>
     43  1.3.8.2  uch 
     44  1.3.8.2  uch ARMArchitecture::ARMArchitecture(Console *&cons, MemoryManager *&mem)
     45  1.3.8.2  uch 	: Architecture(cons, mem)
     46  1.3.8.2  uch {
     47  1.3.8.2  uch 	DPRINTF((TEXT("ARM architecture.\n")));
     48  1.3.8.2  uch }
     49  1.3.8.2  uch 
     50  1.3.8.2  uch ARMArchitecture::~ARMArchitecture(void)
     51  1.3.8.2  uch {
     52  1.3.8.2  uch }
     53  1.3.8.2  uch 
     54  1.3.8.2  uch void
     55  1.3.8.2  uch ARMArchitecture::systemInfo()
     56  1.3.8.2  uch {
     57  1.3.8.2  uch 	Architecture::systemInfo();
     58  1.3.8.2  uch 
     59  1.3.8.2  uch 	_kmode = SetKMode(1);
     60  1.3.8.2  uch 	DI();
     61  1.3.8.2  uch 	if ((GetCPSR() & 0x1f) != 0x1f)
     62  1.3.8.2  uch 		DPRINTF((TEXT("can't change to System mode\n")));
     63  1.3.8.2  uch 
     64  1.3.8.2  uch 	DPRINTF((TEXT("Reg0 :%08x\n"), GetCop15Reg0()));
     65  1.3.8.2  uch 	DPRINTF((TEXT("Reg1 :%08x\n"), GetCop15Reg1()));
     66  1.3.8.2  uch 	DPRINTF((TEXT("Reg2 :%08x\n"), GetCop15Reg2()));
     67  1.3.8.2  uch 	DPRINTF((TEXT("Reg3 :%08x\n"), GetCop15Reg3()));
     68  1.3.8.2  uch 	DPRINTF((TEXT("Reg5 :%08x\n"), GetCop15Reg5()));
     69  1.3.8.2  uch 	DPRINTF((TEXT("Reg6 :%08x\n"), GetCop15Reg6()));
     70  1.3.8.2  uch 	DPRINTF((TEXT("Reg13:%08x\n"), GetCop15Reg13()));
     71  1.3.8.2  uch 	DPRINTF((TEXT("Reg14:%08x\n"), GetCop15Reg14()));
     72  1.3.8.2  uch 	DPRINTF((TEXT("CPSR :%08x\n"), GetCPSR()));
     73  1.3.8.2  uch 	EI();
     74  1.3.8.2  uch 	SetKMode(_kmode);
     75  1.3.8.2  uch }
     76  1.3.8.2  uch 
     77  1.3.8.2  uch BOOL
     78  1.3.8.2  uch ARMArchitecture::init(void)
     79  1.3.8.2  uch {
     80  1.3.8.2  uch 	if (!_mem->init()) {
     81  1.3.8.2  uch 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     82  1.3.8.2  uch 		return FALSE;
     83  1.3.8.2  uch 	}
     84  1.3.8.2  uch 	// set D-RAM information
     85  1.3.8.2  uch 	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
     86  1.3.8.2  uch 	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
     87  1.3.8.2  uch 	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
     88  1.3.8.2  uch 	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);
     89  1.3.8.2  uch 
     90  1.3.8.2  uch 	return TRUE;
     91  1.3.8.2  uch }
     92  1.3.8.2  uch 
     93  1.3.8.2  uch BOOL
     94  1.3.8.2  uch ARMArchitecture::setupLoader()
     95  1.3.8.2  uch {
     96  1.3.8.2  uch 	vaddr_t v;
     97  1.3.8.2  uch 	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;
     98  1.3.8.2  uch 
     99  1.3.8.2  uch 	// chcek 2nd bootloader size.
    100  1.3.8.2  uch 	if (sz > _mem->getPageSize()) {
    101  1.3.8.2  uch 		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
    102  1.3.8.2  uch 		    sz, _mem->getPageSize()));
    103  1.3.8.2  uch 		return FALSE;
    104  1.3.8.2  uch 	}
    105  1.3.8.2  uch 
    106  1.3.8.2  uch 	// get physical mapped page and copy loader to there.
    107  1.3.8.2  uch 	// don't writeback D-cache here. make sure to writeback before jump.
    108  1.3.8.2  uch 	if (!_mem->getPage(v , _loader_addr)) {
    109  1.3.8.2  uch 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
    110  1.3.8.2  uch 		return FALSE;
    111  1.3.8.2  uch 	}
    112  1.3.8.2  uch 	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
    113  1.3.8.2  uch 	    (unsigned)v,(unsigned)_loader_addr));
    114  1.3.8.2  uch 
    115  1.3.8.2  uch 	memcpy(reinterpret_cast <LPVOID>(v),
    116  1.3.8.2  uch 	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
    117  1.3.8.2  uch 	DPRINTF((TEXT("2nd bootloader copy done.\n")));
    118  1.3.8.2  uch 
    119  1.3.8.2  uch 	return TRUE;
    120  1.3.8.2  uch }
    121  1.3.8.2  uch 
    122  1.3.8.2  uch void
    123  1.3.8.2  uch ARMArchitecture::jump(paddr_t info, paddr_t pvec)
    124  1.3.8.2  uch {
    125  1.3.8.2  uch 	kaddr_t sp;
    126  1.3.8.2  uch 	vaddr_t v;
    127  1.3.8.2  uch 	paddr_t p;
    128  1.3.8.2  uch 
    129  1.3.8.2  uch 	// stack for bootloader
    130  1.3.8.2  uch 	_mem->getPage(v, p);
    131  1.3.8.2  uch 	sp = ptokv(p) + _mem->getPageSize();
    132  1.3.8.2  uch 
    133  1.3.8.2  uch 	// writeback whole D-cache
    134  1.3.8.2  uch 	WritebackDCache();
    135  1.3.8.2  uch 
    136  1.3.8.2  uch 	SetKMode(1);
    137  1.3.8.2  uch 	FlatJump(info, pvec, sp, _loader_addr);
    138  1.3.8.2  uch 	// NOTREACHED
    139  1.3.8.2  uch }
    140  1.3.8.2  uch 
    141  1.3.8.2  uch void
    142  1.3.8.2  uch ARMArchitecture::testFramebuffer()
    143  1.3.8.2  uch {
    144  1.3.8.2  uch 	// get frame buffer address from LCD controller register.
    145  1.3.8.2  uch 	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
    146  1.3.8.2  uch 	// map frame buffer
    147  1.3.8.2  uch 	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
    148  1.3.8.2  uch 	    PAGE_READWRITE);
    149  1.3.8.2  uch 
    150  1.3.8.2  uch 	// test frame buffer
    151  1.3.8.2  uch 	int j, k;
    152  1.3.8.2  uch 	DI();
    153  1.3.8.2  uch 	for (j = 0; j < 480; j++)
    154  1.3.8.2  uch 		for (k = 0; k < 640; k++)
    155  1.3.8.2  uch 			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
    156  1.3.8.2  uch 			    = j * k & 0xff;
    157  1.3.8.2  uch 	for (j = 120; j < 360; j++)
    158  1.3.8.2  uch 		for (k = 120; k < 520; k++)
    159  1.3.8.2  uch 			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
    160  1.3.8.2  uch 	EI();
    161  1.3.8.2  uch 	_mem->unmapPhysicalPage(fbaddr_v);
    162  1.3.8.2  uch }
    163  1.3.8.2  uch 
    164  1.3.8.2  uch void
    165  1.3.8.2  uch ARMArchitecture::testUART()
    166  1.3.8.2  uch {
    167  1.3.8.2  uch #define TBY			VOLATILE_REF(uart + 0x20)
    168  1.3.8.2  uch #define UTDR			VOLATILE_REF(uart + 0x14)
    169  1.3.8.2  uch #define TBY_BUSY		while (TBY & 0x1)
    170  1.3.8.2  uch #define UTDR_PUTCHAR(c)		(UTDR =(c))
    171  1.3.8.2  uch #define _(c)								\
    172  1.3.8.2  uch __BEGIN_MACRO								\
    173  1.3.8.2  uch 	TBY_BUSY;							\
    174  1.3.8.2  uch 	UTDR_PUTCHAR(c);						\
    175  1.3.8.2  uch __END_MACRO
    176  1.3.8.2  uch 	vaddr_t uart =
    177  1.3.8.2  uch 	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
    178  1.3.8.2  uch 	_('H');_('e');_('l');_('l');_('o');_(' ');
    179  1.3.8.2  uch 	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
    180  1.3.8.2  uch 	_mem->unmapPhysicalPage(uart);
    181  1.3.8.2  uch }
    182