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