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