boot.cpp revision 1.1.2.2 1 /* $NetBSD: boot.cpp,v 1.1.2.2 2001/02/11 19:09:48 bouyer 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 struct HpcMenuInterface::boot_hook_args bha;
74 bha.func = hpcboot;
75 bha.arg = 0;
76 HpcMenuInterface::Instance().register_boot_hook(bha);
77
78 #ifdef ARM
79 _instance = new ARMBoot();
80 #endif
81 #ifdef MIPS
82 _instance = new MIPSBoot();
83 #endif
84 #ifdef SHx
85 _instance = new SHBoot();
86 #endif
87
88 memset(&_instance->args, 0, sizeof(struct BootSetupArgs));
89 _instance->args.consoleEnable = TRUE;
90
91 return *_instance;
92 }
93
94 void
95 Boot::Destroy()
96 {
97 if (_instance)
98 delete _instance;
99 }
100
101 BOOL
102 Boot::setup(struct HpcMenuInterface::HpcMenuPreferences &pref)
103 {
104 args.console = pref.boot_serial ? CONSOLE_SERIAL : CONSOLE_LCD;
105
106 // file path.
107 TCHAR *dir = pref.dir_user_path;
108 if (wcsstr(dir, TEXT("http://")))
109 args.file = FILE_HTTP;
110 else
111 args.file = wcschr(dir, TEXT('/')) ? FILE_UFS : FILE_FAT;
112 wcscpy(args.fileRoot, dir);
113
114 // file name.
115 wcscpy(args.fileName, pref.kernel_user_file);
116 args.loadmfs = (pref.rootfs == 2);
117 if (args.loadmfs)
118 wcscpy(args.mfsName, pref.rootfs_file);
119
120 // debug options.
121 args.loaderDebug = FALSE;
122 args.architectureDebug = FALSE;
123 args.memorymanagerDebug = FALSE;
124 args.fileDebug = FALSE;
125
126 return TRUE;
127 }
128
129 Boot::Boot()
130 {
131 _arch = 0;
132 _mem = 0;
133 _file = 0;
134 _loader = 0;
135 // set default console
136 _cons = Console::Instance();
137 }
138
139 Boot::~Boot()
140 {
141 if (_file)
142 delete _file;
143 if (_loader)
144 delete _loader;
145 }
146
147 BOOL
148 Boot::create()
149 {
150 // File manager.
151 _file = new FileManager(_cons, args.file);
152 _file->setDebug() = args.fileDebug;
153
154 return TRUE;
155 }
156
157 BOOL
158 Boot::attachLoader()
159 {
160 switch (Loader::objectFormat(*_file)) {
161 case LOADER_ELF:
162 _loader = new ElfLoader(_cons, _mem);
163 break;
164 case LOADER_COFF:
165 _loader = new CoffLoader(_cons, _mem);
166 break;
167 default:
168 DPRINTF((TEXT("unknown file format.\n")));
169 return FALSE;
170 }
171
172 return TRUE;
173 }
174