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