boot.cpp revision 1.1.4.1 1 /* $NetBSD: boot.cpp,v 1.1.4.1 2001/06/21 19:22:40 nathanw 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 <hpcdefs.h>
40 #include <hpcboot.h>
41 #include <boot.h>
42
43 #include <load.h>
44 #include <load_elf.h>
45 #include <load_coff.h>
46 #undef DPRINTF // trash coff_machdep.h's DPRINTF
47
48 #include <console.h>
49
50 #include <file.h>
51 #include <file_fat.h>
52 #include <file_http.h>
53 #include <file_ufs.h>
54
55 #ifdef ARM
56 #include <arm/arm_boot.h>
57 #endif
58 #ifdef MIPS
59 #include <mips/mips_boot.h>
60 #endif
61 #ifdef SHx
62 #include <sh3/sh_boot.h>
63 #endif
64
65 Boot *Boot::_instance = 0;
66
67 Boot &
68 Boot::Instance()
69 {
70 if (_instance)
71 return *_instance;
72
73 // register bootloader to menu system.
74 // (will be invoked by boot button)
75 struct HpcMenuInterface::boot_hook_args bha;
76 bha.func = hpcboot;
77 bha.arg = 0;
78 HPC_MENU.register_boot_hook(bha);
79
80 #ifdef ARM
81 _instance = new ARMBoot();
82 #endif
83 #ifdef MIPS
84 _instance = new MIPSBoot();
85 #endif
86 #ifdef SHx
87 _instance = new SHBoot();
88 #endif
89
90 memset(&_instance->args, 0, sizeof(struct BootSetupArgs));
91 _instance->args.consoleEnable = TRUE;
92
93 return *_instance;
94 }
95
96 void
97 Boot::Destroy()
98 {
99 if (_instance)
100 delete _instance;
101 }
102
103 BOOL
104 Boot::setup()
105 {
106 struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
107
108 args.console = pref.boot_serial ? CONSOLE_SERIAL : CONSOLE_LCD;
109
110 // file path.
111 TCHAR *dir = pref.dir_user_path;
112 if (wcsstr(dir, TEXT("http://")))
113 args.file = FILE_HTTP;
114 else
115 args.file = wcschr(dir, TEXT('/')) ? FILE_UFS : FILE_FAT;
116 wcscpy(args.fileRoot, dir);
117
118 // file name.
119 wcscpy(args.fileName, pref.kernel_user_file);
120 args.loadmfs = (pref.rootfs == 2);
121 if (args.loadmfs)
122 wcscpy(args.mfsName, pref.rootfs_file);
123
124 // debug options.
125 args.loaderDebug = FALSE;
126 args.architectureDebug = FALSE;
127 args.memorymanagerDebug = FALSE;
128 args.fileDebug = FALSE;
129
130 return TRUE;
131 }
132
133 Boot::Boot()
134 {
135 _arch = 0;
136 _mem = 0;
137 _file = 0;
138 _loader = 0;
139 // set default console
140 _cons = Console::Instance();
141 }
142
143 Boot::~Boot()
144 {
145 if (_file)
146 delete _file;
147 if (_loader)
148 delete _loader;
149 }
150
151 BOOL
152 Boot::create()
153 {
154 // File manager.
155 _file = new FileManager(_cons, args.file);
156 _file->setDebug() = args.fileDebug;
157
158 return TRUE;
159 }
160
161 BOOL
162 Boot::attachLoader()
163 {
164 switch (Loader::objectFormat(*_file)) {
165 case LOADER_ELF:
166 _loader = new ElfLoader(_cons, _mem);
167 break;
168 case LOADER_COFF:
169 _loader = new CoffLoader(_cons, _mem);
170 break;
171 default:
172 DPRINTF((TEXT("unknown file format.\n")));
173 return FALSE;
174 }
175
176 return TRUE;
177 }
178