1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.7 2002/03/25 17:23:19 uch Exp $ */ 2 3 /*- 4 * Copyright (c) 2001, 2002 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 <hpcmenu.h> 41 42 #include <menu/window.h> 43 #include <menu/rootwindow.h> // MessageBox 44 45 #include <console.h> 46 #include <memory.h> 47 #include <load.h> 48 #include <arch.h> 49 #include <framebuffer.h> 50 51 Architecture::Architecture(Console *&cons, MemoryManager *&mem) 52 :_cons(cons), _mem(mem) 53 { 54 55 _loader_addr = 0; 56 _debug = FALSE; 57 _dll = 0; 58 } 59 60 Architecture::~Architecture(void) 61 { 62 63 if (_dll) 64 FreeLibrary(_dll); 65 } 66 67 BOOL 68 Architecture::allocateMemory(size_t sz) 69 { 70 //binary image. 71 sz = _mem->estimateTaggedPageSize(sz); 72 //pvec + BootArgs + 2 nd bootloader + bootloader stack. 73 sz += _mem->getPageSize() * 4; 74 sz = _mem->roundRegion(sz); 75 return _mem->reservePage(sz); 76 } 77 78 paddr_t 79 Architecture::setupBootInfo(Loader &loader) 80 { 81 HpcMenuInterface &menu = HpcMenuInterface::Instance(); 82 vaddr_t v; 83 paddr_t p; 84 85 _mem->getPage(v, p); 86 _boot_arg = reinterpret_cast <struct BootArgs *>(v); 87 88 _boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs), 89 p + sizeof(struct BootArgs), 90 _mem->getTaggedPageSize() - sizeof(struct BootArgs)); 91 _boot_arg->argv = ptokv(p + sizeof(struct BootArgs)); 92 menu.setup_bootinfo(_boot_arg->bi); 93 _boot_arg->bi.bi_cnuse = _cons->getBootConsole(); 94 95 _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi)); 96 _boot_arg->kernel_entry = loader.jumpAddr(); 97 98 struct bootinfo &bi = _boot_arg->bi; 99 DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"), 100 bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes, 101 bi.fb_addr)); 102 DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse)); 103 104 return p; 105 } 106 107 void * 108 Architecture::_load_func(const TCHAR * name) 109 { 110 111 if (_dll == NULL) 112 _dll = LoadLibrary(TEXT("coredll.dll")); 113 114 if (_dll == NULL) { 115 MessageBox(HpcMenuInterface::Instance()._root->_window, 116 TEXT("Can't load Coredll.dll"), TEXT("WARNING"), 0); 117 118 return NULL; 119 } 120 121 return reinterpret_cast <void *>(GetProcAddress(_dll, name)); 122 } 123 124 void 125 Architecture::systemInfo(void) 126 { 127 u_int32_t val = 0; 128 SYSTEM_INFO si; 129 HDC hdc; 130 BOOL (*getVersionEx)(LPOSVERSIONINFO); 131 132 // 133 // WCE200 ... GetVersionEx 134 // WCE210 or later ... GetVersionExA or GetVersionExW 135 // see winbase.h 136 // 137 getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)> 138 (_load_func(TEXT("GetVersionEx"))); 139 140 if (getVersionEx) { 141 getVersionEx(&WinCEVersion); 142 DPRINTF((TEXT("GetVersionEx\n"))); 143 } else { 144 GetVersionEx(&WinCEVersion); 145 DPRINTF((TEXT("GetVersionExW\n"))); 146 } 147 148 DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion, 149 WinCEVersion.dwMinorVersion)); 150 151 GetSystemInfo(&si); 152 DPRINTF((TEXT("GetSystemInfo:\n"))); 153 DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"), 154 si.wProcessorArchitecture)); 155 DPRINTF((TEXT("dwPageSize 0x%x\n"), 156 si.dwPageSize)); 157 DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"), 158 si.dwAllocationGranularity)); 159 DPRINTF((TEXT("dwProcessorType 0x%x\n"), 160 si.dwProcessorType)); 161 DPRINTF((TEXT("wProcessorLevel 0x%x\n"), 162 si.wProcessorLevel)); 163 DPRINTF((TEXT("wProcessorRevision 0x%x\n"), 164 si.wProcessorRevision)); 165 166 // inquire default setting. 167 FrameBufferInfo fb(0, 0); 168 DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(), 169 fb.bpp())); 170 171 ReleaseDC(0, hdc); 172 } 173 174 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int) 175 { 176 177 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)> 178 (_load_func(TEXT("LockPages"))); 179 } 180 181 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD) 182 { 183 184 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)> 185 (_load_func(TEXT("UnlockPages"))); 186 } 187