No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / boot.cpp
blob5878ff87f8cfa39aebe1c3b443f15abe596df501
1 /* $NetBSD: boot.cpp,v 1.6 2005/12/11 12:17:28 christos Exp $ */
3 /*-
4 * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <hpcdefs.h>
33 #include <hpcboot.h>
34 #include <boot.h>
36 #include <load.h>
37 #include <load_elf.h>
38 #include <load_coff.h>
39 #undef DPRINTF // trash coff_machdep.h's DPRINTF
41 #include <console.h>
43 #include <file.h>
45 #ifdef ARM
46 #include <arm/arm_boot.h>
47 #endif
48 #ifdef MIPS
49 #include <mips/mips_boot.h>
50 #endif
51 #ifdef SHx
52 #include <sh3/sh_boot.h>
53 #endif
55 Boot *Boot::_instance = 0;
57 Boot &
58 Boot::Instance()
61 if (_instance)
62 return *_instance;
64 // register bootloader to menu system.
65 // (will be invoked by boot button)
66 struct HpcMenuInterface::boot_hook_args bha;
67 bha.func = hpcboot;
68 bha.arg = 0;
69 HPC_MENU.register_boot_hook(bha);
71 #ifdef ARM
72 _instance = new ARMBoot();
73 #endif
74 #ifdef MIPS
75 _instance = new MIPSBoot();
76 #endif
77 #ifdef SHx
78 _instance = new SHBoot();
79 #endif
81 memset(&_instance->args, 0, sizeof(struct BootSetupArgs));
82 _instance->args.consoleEnable = TRUE;
84 return *_instance;
87 void
88 Boot::Destroy()
91 if (_instance)
92 delete _instance;
95 BOOL
96 Boot::setup()
98 struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
100 args.console = pref.boot_serial ? CONSOLE_SERIAL : CONSOLE_LCD;
102 // file path.
103 TCHAR *dir = pref.dir_user_path;
104 if (wcsstr(dir, TEXT("http://")))
105 args.file = FILE_HTTP;
106 else
107 args.file = wcschr(dir, TEXT('/')) ? FILE_UFS : FILE_FAT;
108 wcscpy(args.fileRoot, dir);
110 // file name.
111 wcscpy(args.fileName, pref.kernel_user_file);
112 args.loadmfs = (pref.rootfs == 2);
113 if (args.loadmfs)
114 wcscpy(args.mfsName, pref.rootfs_file);
116 // debug options.
117 args.loaderDebug = FALSE;
118 args.architectureDebug = FALSE;
119 args.memorymanagerDebug = FALSE;
120 args.fileDebug = FALSE;
122 return TRUE;
125 Boot::Boot()
127 _arch = 0;
128 _mem = 0;
129 _file = 0;
130 _loader = 0;
131 // set default console
132 _cons = Console::Instance();
135 Boot::~Boot()
138 if (_file)
139 delete _file;
140 if (_loader)
141 delete _loader;
144 BOOL
145 Boot::create()
148 // Set this console (setuped by machine dependent part) as default.
149 Console::changeConsole(*_cons);
151 // File manager.
152 _file = new FileManager(_cons, args.file);
153 _file->setDebug() = args.fileDebug;
155 return TRUE;
158 BOOL
159 Boot::attachLoader()
162 switch (Loader::objectFormat(*_file)) {
163 case LOADER_ELF:
164 _loader = new ElfLoader(_cons, _mem);
165 break;
166 case LOADER_COFF:
167 _loader = new CoffLoader(_cons, _mem);
168 break;
169 default:
170 DPRINTF((TEXT("unknown file format.\n")));
171 return FALSE;
174 return TRUE;