arm_arch.cpp revision 1.1 1 1.1 uch /* $NetBSD: arm_arch.cpp,v 1.1 2001/02/09 18:34:49 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
39 1.1 uch #include <arm/arm_arch.h>
40 1.1 uch #include <console.h>
41 1.1 uch #include <memory.h>
42 1.1 uch #include <arm/arm_sa1100.h>
43 1.1 uch
44 1.1 uch ARMArchitecture::ARMArchitecture(Console *&cons, MemoryManager *&mem)
45 1.1 uch : Architecture(cons, mem)
46 1.1 uch {
47 1.1 uch DPRINTF((TEXT("ARM architecture.\n")));
48 1.1 uch }
49 1.1 uch
50 1.1 uch ARMArchitecture::~ARMArchitecture(void)
51 1.1 uch {
52 1.1 uch }
53 1.1 uch
54 1.1 uch void
55 1.1 uch ARMArchitecture::systemInfo()
56 1.1 uch {
57 1.1 uch Architecture::systemInfo();
58 1.1 uch
59 1.1 uch _kmode = SetKMode(1);
60 1.1 uch DI();
61 1.1 uch if ((GetCPSR() & 0x1f) != 0x1f)
62 1.1 uch DPRINTF((TEXT("can't change to System mode\n")));
63 1.1 uch
64 1.1 uch DPRINTF((TEXT("Reg0 :%08x\n"), GetCop15Reg0()));
65 1.1 uch DPRINTF((TEXT("Reg1 :%08x\n"), GetCop15Reg1()));
66 1.1 uch DPRINTF((TEXT("Reg2 :%08x\n"), GetCop15Reg2()));
67 1.1 uch DPRINTF((TEXT("Reg3 :%08x\n"), GetCop15Reg3()));
68 1.1 uch DPRINTF((TEXT("Reg5 :%08x\n"), GetCop15Reg5()));
69 1.1 uch DPRINTF((TEXT("Reg6 :%08x\n"), GetCop15Reg6()));
70 1.1 uch DPRINTF((TEXT("Reg13:%08x\n"), GetCop15Reg13()));
71 1.1 uch DPRINTF((TEXT("Reg14:%08x\n"), GetCop15Reg14()));
72 1.1 uch DPRINTF((TEXT("CPSR :%08x\n"), GetCPSR()));
73 1.1 uch EI();
74 1.1 uch SetKMode(_kmode);
75 1.1 uch }
76 1.1 uch
77 1.1 uch BOOL
78 1.1 uch ARMArchitecture::init(void)
79 1.1 uch {
80 1.1 uch if (!_mem->init()) {
81 1.1 uch DPRINTF((TEXT("can't initialize memory manager.\n")));
82 1.1 uch return FALSE;
83 1.1 uch }
84 1.1 uch // set D-RAM information
85 1.1 uch _mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
86 1.1 uch _mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
87 1.1 uch _mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
88 1.1 uch _mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);
89 1.1 uch
90 1.1 uch return TRUE;
91 1.1 uch }
92 1.1 uch
93 1.1 uch BOOL
94 1.1 uch ARMArchitecture::setupLoader()
95 1.1 uch {
96 1.1 uch vaddr_t v;
97 1.1 uch vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;
98 1.1 uch
99 1.1 uch // chcek 2nd bootloader size.
100 1.1 uch if (sz > _mem->getPageSize()) {
101 1.1 uch DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
102 1.1 uch sz, _mem->getPageSize()));
103 1.1 uch return FALSE;
104 1.1 uch }
105 1.1 uch
106 1.1 uch // get physical mapped page and copy loader to there.
107 1.1 uch // don't writeback D-cache here. make sure to writeback before jump.
108 1.1 uch if (!_mem->getPage(v , _loader_addr)) {
109 1.1 uch DPRINTF((TEXT("can't get page for 2nd loader.\n")));
110 1.1 uch return FALSE;
111 1.1 uch }
112 1.1 uch DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
113 1.1 uch (unsigned)v,(unsigned)_loader_addr));
114 1.1 uch
115 1.1 uch memcpy(reinterpret_cast <LPVOID>(v),
116 1.1 uch reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
117 1.1 uch DPRINTF((TEXT("2nd bootloader copy done.\n")));
118 1.1 uch
119 1.1 uch return TRUE;
120 1.1 uch }
121 1.1 uch
122 1.1 uch void
123 1.1 uch ARMArchitecture::jump(paddr_t info, paddr_t pvec)
124 1.1 uch {
125 1.1 uch kaddr_t sp;
126 1.1 uch vaddr_t v;
127 1.1 uch paddr_t p;
128 1.1 uch
129 1.1 uch // stack for bootloader
130 1.1 uch _mem->getPage(v, p);
131 1.1 uch sp = ptokv(p);
132 1.1 uch
133 1.1 uch // writeback whole D-cache
134 1.1 uch WritebackDCache();
135 1.1 uch
136 1.1 uch SetKMode(1);
137 1.1 uch FlatJump(info, pvec, sp, _loader_addr);
138 1.1 uch // NOTREACHED
139 1.1 uch }
140 1.1 uch
141 1.1 uch void
142 1.1 uch ARMArchitecture::testFramebuffer()
143 1.1 uch {
144 1.1 uch // get frame buffer address from LCD controller register.
145 1.1 uch paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
146 1.1 uch // map frame buffer
147 1.1 uch vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
148 1.1 uch PAGE_READWRITE);
149 1.1 uch
150 1.1 uch // test frame buffer
151 1.1 uch int j, k;
152 1.1 uch DI();
153 1.1 uch for (j = 0; j < 480; j++)
154 1.1 uch for (k = 0; k < 640; k++)
155 1.1 uch VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
156 1.1 uch = j * k & 0xff;
157 1.1 uch for (j = 120; j < 360; j++)
158 1.1 uch for (k = 120; k < 520; k++)
159 1.1 uch VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
160 1.1 uch EI();
161 1.1 uch _mem->unmapPhysicalPage(fbaddr_v);
162 1.1 uch }
163 1.1 uch
164 1.1 uch void
165 1.1 uch ARMArchitecture::testUART()
166 1.1 uch {
167 1.1 uch #define TBY VOLATILE_REF(uart + 0x20)
168 1.1 uch #define UTDR VOLATILE_REF(uart + 0x14)
169 1.1 uch #define TBY_BUSY while (TBY & 0x1)
170 1.1 uch #define UTDR_PUTCHAR(c) (UTDR =(c))
171 1.1 uch #define _(c) \
172 1.1 uch __BEGIN_MACRO \
173 1.1 uch TBY_BUSY; \
174 1.1 uch UTDR_PUTCHAR(c); \
175 1.1 uch __END_MACRO
176 1.1 uch vaddr_t uart =
177 1.1 uch _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
178 1.1 uch _('H');_('e');_('l');_('l');_('o');_(' ');
179 1.1 uch _('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
180 1.1 uch _mem->unmapPhysicalPage(uart);
181 1.1 uch }
182