sh_arch.cpp revision 1.9.16.1 1 /* $NetBSD: sh_arch.cpp,v 1.9.16.1 2004/08/12 11:41:05 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <hpcboot.h>
40 #include <hpcmenu.h>
41 #include <sh3/sh_arch.h>
42
43 SH_BOOT_FUNC_(7709);
44 SH_BOOT_FUNC_(7709A);
45 SH_BOOT_FUNC_(7750);
46
47 static int _cpu_type;
48
49 int
50 SHArchitecture::cpu_type()
51 {
52 if (_cpu_type == 0) {
53 #if _WIN32_WCE == 101
54 _cpu_type = 3;
55 #else
56 SYSTEM_INFO si;
57 GetSystemInfo(&si);
58 _cpu_type = si.wProcessorLevel;
59 #endif
60 }
61
62 return _cpu_type;
63 }
64
65 BOOL
66 SHArchitecture::init()
67 {
68
69 if (!_mem->init()) {
70 DPRINTF((TEXT("can't initialize memory manager.\n")));
71 return FALSE;
72 }
73 // D-RAM information
74 DPRINTF((TEXT("Memory Bank:\n")));
75
76 return TRUE;
77 }
78
79 void
80 SHArchitecture::systemInfo()
81 {
82
83 // Windows CE common infomation.
84 super::systemInfo();
85
86 // CPU specific.
87 _dev->dump(HPC_MENU._cons_parameter);
88 }
89
90 BOOL
91 SHArchitecture::setupLoader()
92 {
93 vaddr_t v;
94
95 if (!_mem->getPage(v , _loader_addr)) {
96 DPRINTF((TEXT("can't get page for 2nd loader.\n")));
97 return FALSE;
98 }
99 _loader_addr = ptokv(_loader_addr);
100
101 DPRINTF((TEXT("2nd bootloader address U0: 0x%08x P1: 0x%08x\n"),
102 (unsigned)v,(unsigned)_loader_addr));
103
104 memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
105
106 return TRUE;
107 }
108
109 void
110 SHArchitecture::jump(paddr_t info, paddr_t pvec)
111 {
112 kaddr_t sp;
113 vaddr_t v;
114 paddr_t p;
115
116 // stack for bootloader
117 _mem->getPage(v, p);
118 sp = ptokv(p + _mem->getPageSize() / 2);
119
120 info = ptokv(info);
121 pvec = ptokv(pvec);
122
123 DPRINTF((TEXT("boot arg: 0x%08x stack: 0x%08x\nBooting kernel...\n"),
124 info, sp));
125
126 // Change to privilege-mode.
127 SetKMode(1);
128
129 // Cache flush(for 2nd bootloader)
130 //
131 // SH4 uses WinCE CacheSync(). this routine may causes TLB
132 // exception. so calls before suspendIntr().
133 //
134 cache_flush();
135
136 // Disable external interrupt.
137 suspendIntr();
138
139 // jump to 2nd loader.(run P1) at this time I still use MMU.
140 __asm(
141 "mov r6, r15\n"
142 "jmp @r7\n"
143 "nop \n", info, pvec, sp, _loader_addr);
144 // NOTREACHED
145 }
146
147 // disable external interrupt and save its priority.
148 u_int32_t
149 suspendIntr()
150 {
151 u_int32_t sr;
152
153 __asm(
154 "stc sr, r0\n"
155 "mov.l r0, @r4\n"
156 "or r5, r0\n"
157 "ldc r0, sr\n", &sr, 0x000000f0);
158 return sr & 0x000000f0;
159 }
160
161 // resume external interrupt priority.
162 void
163 resumeIntr(u_int32_t s)
164 {
165
166 __asm(
167 "stc sr, r0\n"
168 "and r5, r0\n"
169 "or r4, r0\n"
170 "ldc r0, sr\n", s, 0xffffff0f);
171 }
172