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