No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / arch.cpp
blob2c18165350d6bd12e3830d7eb739b4da75c9f8a3
1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.14 2006/03/05 04:05:39 uwe Exp $ */
3 /*-
4 * Copyright (c) 2001, 2002, 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 <hpcboot.h>
33 #include <hpcmenu.h>
35 #include <menu/window.h>
36 #include <menu/rootwindow.h> // MessageBox
38 #include <console.h>
39 #include <memory.h>
40 #include <load.h>
41 #include <arch.h>
42 #include <framebuffer.h>
44 Architecture::Architecture(Console *&cons, MemoryManager *&mem)
45 :_cons(cons), _mem(mem)
48 _loader_addr = 0;
49 _debug = FALSE;
50 _dll = 0;
53 Architecture::~Architecture(void)
56 if (_dll)
57 FreeLibrary(_dll);
60 BOOL
61 Architecture::allocateMemory(size_t sz)
63 //binary image.
64 sz = _mem->estimateTaggedPageSize(sz);
65 //pvec + BootArgs + 2 nd bootloader + bootloader stack.
66 sz += _mem->getPageSize() * 4;
67 sz = _mem->roundRegion(sz);
68 return _mem->reservePage(sz);
71 paddr_t
72 Architecture::setupBootInfo(Loader &loader)
74 HpcMenuInterface &menu = HpcMenuInterface::Instance();
75 vaddr_t v;
76 paddr_t p;
78 _mem->getPage(v, p);
79 _boot_arg = reinterpret_cast <struct BootArgs *>(v);
81 _boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
82 p + sizeof(struct BootArgs),
83 _mem->getTaggedPageSize() - sizeof(struct BootArgs));
84 _boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
85 menu.setup_bootinfo(_boot_arg->bi);
86 _boot_arg->bi.bi_cnuse = _cons->getBootConsole();
88 _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
89 _boot_arg->kernel_entry = loader.jumpAddr();
91 struct bootinfo &bi = _boot_arg->bi;
92 DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
93 bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
94 bi.fb_addr));
95 DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
97 return p;
100 void *
101 Architecture::_load_func(const TCHAR * name)
104 if (_dll == NULL)
105 _dll = LoadLibrary(TEXT("coredll.dll"));
107 if (_dll == NULL) {
108 HWND owner = HpcMenuInterface::Instance()._root->_window;
109 MessageBox(owner,
110 TEXT("Can't load coredll.dll."), TEXT("WARNING"),
111 MB_ICONWARNING | MB_OK);
112 UpdateWindow(owner);
114 return NULL;
117 return reinterpret_cast <void *>(GetProcAddress(_dll, name));
120 void
121 Architecture::systemInfo(void)
123 uint32_t val = 0;
124 SYSTEM_INFO si;
126 DPRINTF((TEXT("_WIN32_WCE = %d\n"), _WIN32_WCE));
128 // WCE200 ... GetVersionEx
129 // WCE210 or later ... GetVersionExA or GetVersionExW
130 // see winbase.h
132 BOOL (*getVersionEx)(LPOSVERSIONINFO);
133 getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
134 (_load_func(TEXT("GetVersionEx")));
136 if (getVersionEx) {
137 getVersionEx(&WinCEVersion);
138 DPRINTF((TEXT("GetVersionEx\n")));
139 } else {
140 GetVersionEx(&WinCEVersion);
141 DPRINTF((TEXT("GetVersionExW\n")));
144 DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
145 WinCEVersion.dwMinorVersion));
147 GetSystemInfo(&si);
148 DPRINTF((TEXT("GetSystemInfo:\n")));
149 #if _WIN32_WCE >= 200
150 DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"),
151 si.wProcessorArchitecture));
152 DPRINTF((TEXT("wProcessorLevel 0x%x\n"),
153 si.wProcessorLevel));
154 DPRINTF((TEXT("wProcessorRevision 0x%x\n"),
155 si.wProcessorRevision));
156 #endif
157 DPRINTF((TEXT("dwPageSize 0x%x\n"),
158 si.dwPageSize));
159 DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"),
160 si.dwAllocationGranularity));
161 DPRINTF((TEXT("dwProcessorType 0x%x\n"),
162 si.dwProcessorType));
163 // inquire default setting.
164 FrameBufferInfo fb(0, 0);
165 DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
166 fb.bpp()));
169 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
172 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
173 (_load_func(TEXT("LockPages")));
176 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
179 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
180 (_load_func(TEXT("UnlockPages")));