mips_boot.cpp revision 1.6 1 /* -*-C++-*- $NetBSD: mips_boot.cpp,v 1.6 2004/08/06 18:33:09 uch Exp $ */
2
3 /*-
4 * Copyright (c) 2001 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 <console.h>
41
42 #include <arch.h>
43 #include <memory.h>
44
45 #include <mips/mips_arch.h>
46 #include <mips/mips_boot.h>
47 #include <mips/mips_vr41.h>
48 #include <mips/mips_tx39.h>
49 #include <mips/mips_console.h>
50
51 MIPSBoot::MIPSBoot()
52 {
53 }
54
55 MIPSBoot::~MIPSBoot()
56 {
57 if (_mem)
58 delete _mem;
59 if (_arch)
60 delete _arch;
61
62 MIPSConsole::Destroy();
63 }
64
65 BOOL
66 MIPSBoot::setup()
67 {
68 struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
69
70 platid_t platid;
71 platid.dw.dw0 = pref.platid_hi;
72 platid.dw.dw1 = pref.platid_lo;
73
74 if (platid_match(&platid, &platid_mask_CPU_MIPS_VR)) {
75 args.architecture = ARCHITECTURE_MIPS_VR41;
76 } else if (platid_match(&platid, &platid_mask_CPU_MIPS_TX_3900)) {
77 args.architecture = ARCHITECTURE_MIPS_TX3900;
78 } else if (platid_match(&platid, &platid_mask_CPU_MIPS_TX_3920)) {
79 args.architecture = ARCHITECTURE_MIPS_TX3920;
80 } else {
81 DPRINTF((TEXT("unknown MIPS variants.\n")));
82 return FALSE;
83 }
84
85 return super::setup();
86 }
87
88 BOOL
89 MIPSBoot::create()
90 {
91 SYSTEM_INFO sysinfo;
92 size_t pagesz;
93 int shift;
94 BOOL(*lock_pages)(LPVOID, DWORD, PDWORD, int);
95 BOOL(*unlock_pages)(LPVOID, DWORD);
96
97 // Console
98 if (args.console == CONSOLE_SERIAL) {
99 _cons = MIPSConsole::Instance();
100 if (!_cons->init()) {
101 _cons = Console::Instance();
102 DPRINTF((TEXT("use LCD console instead.\n")));
103 }
104 } else {
105 _cons = Console::Instance();
106 }
107
108 // Architercure dependent ops.
109 switch(args.architecture) {
110 default:
111 DPRINTF((TEXT("unsupported architecture.\n")));
112 return FALSE;
113 case ARCHITECTURE_MIPS_TX3900:
114 // FALLTHROUGH
115 case ARCHITECTURE_MIPS_TX3920:
116 _arch = new TX39XX(_cons, _mem, args.architecture);
117 pagesz = 4096;
118 shift = 0;
119 break;
120 case ARCHITECTURE_MIPS_VR41:
121 _arch = new VR41XX(_cons, _mem);
122 GetSystemInfo(&sysinfo);
123 DPRINTF((TEXT("sysinfo.dwPageSize = %d\n"),
124 sysinfo.dwPageSize));
125 pagesz = sysinfo.dwPageSize;
126 shift = 4; // VR41 specific shift. for LockPages()
127 break;
128 }
129 _arch->setDebug() = args.architectureDebug;
130
131 // Memory manager.
132 // LockPages API exists in Windows CE 2.11 or later. check it.
133 lock_pages = _arch->_load_LockPages();
134 unlock_pages = _arch->_load_UnlockPages();
135 if (lock_pages == 0 || unlock_pages == 0)
136 args.memory = MEMORY_MANAGER_VIRTUALCOPY;
137 else
138 args.memory = MEMORY_MANAGER_LOCKPAGES;
139
140 switch(args.memory) {
141 default:
142 break;
143 case MEMORY_MANAGER_SOFTMMU:
144 // FALLTHROUGH
145 case MEMORY_MANAGER_HARDMMU:
146 DPRINTF((TEXT("unsupported memory address detection method.\n")));
147 return FALSE;
148 case MEMORY_MANAGER_LOCKPAGES:
149 _mem = new MemoryManager_LockPages(lock_pages, unlock_pages,
150 _cons, pagesz, shift);
151 break;
152 case MEMORY_MANAGER_VIRTUALCOPY:
153 _mem = new MemoryManager_VirtualCopy(_cons, pagesz);
154 break;
155 }
156 _mem->setDebug() = args.memorymanagerDebug;
157
158 // File Manager, Loader
159 return super::create();
160 }
161