1 1.15 martin /* -*-C++-*- $NetBSD: arch.cpp,v 1.15 2008/04/28 20:23:20 martin Exp $ */ 2 1.1 uch 3 1.1 uch /*- 4 1.11 uch * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc. 5 1.1 uch * All rights reserved. 6 1.1 uch * 7 1.1 uch * This code is derived from software contributed to The NetBSD Foundation 8 1.1 uch * by UCHIYAMA Yasushi. 9 1.1 uch * 10 1.1 uch * Redistribution and use in source and binary forms, with or without 11 1.1 uch * modification, are permitted provided that the following conditions 12 1.1 uch * are met: 13 1.1 uch * 1. Redistributions of source code must retain the above copyright 14 1.1 uch * notice, this list of conditions and the following disclaimer. 15 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 uch * notice, this list of conditions and the following disclaimer in the 17 1.1 uch * documentation and/or other materials provided with the distribution. 18 1.1 uch * 19 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 uch * POSSIBILITY OF SUCH DAMAGE. 30 1.1 uch */ 31 1.1 uch 32 1.1 uch #include <hpcboot.h> 33 1.1 uch #include <hpcmenu.h> 34 1.1 uch 35 1.4 uch #include <menu/window.h> 36 1.4 uch #include <menu/rootwindow.h> // MessageBox 37 1.4 uch 38 1.1 uch #include <console.h> 39 1.1 uch #include <memory.h> 40 1.1 uch #include <load.h> 41 1.1 uch #include <arch.h> 42 1.1 uch #include <framebuffer.h> 43 1.1 uch 44 1.1 uch Architecture::Architecture(Console *&cons, MemoryManager *&mem) 45 1.1 uch :_cons(cons), _mem(mem) 46 1.1 uch { 47 1.4 uch 48 1.1 uch _loader_addr = 0; 49 1.1 uch _debug = FALSE; 50 1.1 uch _dll = 0; 51 1.1 uch } 52 1.1 uch 53 1.1 uch Architecture::~Architecture(void) 54 1.1 uch { 55 1.4 uch 56 1.1 uch if (_dll) 57 1.1 uch FreeLibrary(_dll); 58 1.1 uch } 59 1.1 uch 60 1.1 uch BOOL 61 1.1 uch Architecture::allocateMemory(size_t sz) 62 1.1 uch { 63 1.1 uch //binary image. 64 1.1 uch sz = _mem->estimateTaggedPageSize(sz); 65 1.1 uch //pvec + BootArgs + 2 nd bootloader + bootloader stack. 66 1.1 uch sz += _mem->getPageSize() * 4; 67 1.1 uch sz = _mem->roundRegion(sz); 68 1.1 uch return _mem->reservePage(sz); 69 1.1 uch } 70 1.1 uch 71 1.1 uch paddr_t 72 1.2 uch Architecture::setupBootInfo(Loader &loader) 73 1.1 uch { 74 1.1 uch HpcMenuInterface &menu = HpcMenuInterface::Instance(); 75 1.1 uch vaddr_t v; 76 1.1 uch paddr_t p; 77 1.1 uch 78 1.1 uch _mem->getPage(v, p); 79 1.2 uch _boot_arg = reinterpret_cast <struct BootArgs *>(v); 80 1.1 uch 81 1.2 uch _boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs), 82 1.7 uch p + sizeof(struct BootArgs), 83 1.7 uch _mem->getTaggedPageSize() - sizeof(struct BootArgs)); 84 1.2 uch _boot_arg->argv = ptokv(p + sizeof(struct BootArgs)); 85 1.2 uch menu.setup_bootinfo(_boot_arg->bi); 86 1.2 uch _boot_arg->bi.bi_cnuse = _cons->getBootConsole(); 87 1.2 uch 88 1.2 uch _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi)); 89 1.2 uch _boot_arg->kernel_entry = loader.jumpAddr(); 90 1.2 uch 91 1.2 uch struct bootinfo &bi = _boot_arg->bi; 92 1.2 uch DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"), 93 1.3 uch bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes, 94 1.3 uch bi.fb_addr)); 95 1.2 uch DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse)); 96 1.1 uch 97 1.1 uch return p; 98 1.1 uch } 99 1.1 uch 100 1.1 uch void * 101 1.1 uch Architecture::_load_func(const TCHAR * name) 102 1.1 uch { 103 1.4 uch 104 1.4 uch if (_dll == NULL) 105 1.1 uch _dll = LoadLibrary(TEXT("coredll.dll")); 106 1.1 uch 107 1.4 uch if (_dll == NULL) { 108 1.10 uwe HWND owner = HpcMenuInterface::Instance()._root->_window; 109 1.10 uwe MessageBox(owner, 110 1.8 uwe TEXT("Can't load coredll.dll."), TEXT("WARNING"), 111 1.8 uwe MB_ICONWARNING | MB_OK); 112 1.10 uwe UpdateWindow(owner); 113 1.4 uch 114 1.4 uch return NULL; 115 1.4 uch } 116 1.12 uch 117 1.4 uch return reinterpret_cast <void *>(GetProcAddress(_dll, name)); 118 1.1 uch } 119 1.1 uch 120 1.1 uch void 121 1.1 uch Architecture::systemInfo(void) 122 1.1 uch { 123 1.14 uwe uint32_t val = 0; 124 1.4 uch SYSTEM_INFO si; 125 1.11 uch 126 1.11 uch DPRINTF((TEXT("_WIN32_WCE = %d\n"), _WIN32_WCE)); 127 1.6 uch // 128 1.6 uch // WCE200 ... GetVersionEx 129 1.6 uch // WCE210 or later ... GetVersionExA or GetVersionExW 130 1.6 uch // see winbase.h 131 1.6 uch // 132 1.11 uch BOOL (*getVersionEx)(LPOSVERSIONINFO); 133 1.6 uch getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)> 134 1.6 uch (_load_func(TEXT("GetVersionEx"))); 135 1.11 uch 136 1.6 uch if (getVersionEx) { 137 1.6 uch getVersionEx(&WinCEVersion); 138 1.6 uch DPRINTF((TEXT("GetVersionEx\n"))); 139 1.6 uch } else { 140 1.6 uch GetVersionEx(&WinCEVersion); 141 1.6 uch DPRINTF((TEXT("GetVersionExW\n"))); 142 1.6 uch } 143 1.6 uch 144 1.6 uch DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion, 145 1.6 uch WinCEVersion.dwMinorVersion)); 146 1.1 uch 147 1.4 uch GetSystemInfo(&si); 148 1.4 uch DPRINTF((TEXT("GetSystemInfo:\n"))); 149 1.11 uch #if _WIN32_WCE >= 200 150 1.4 uch DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"), 151 1.12 uch si.wProcessorArchitecture)); 152 1.11 uch DPRINTF((TEXT("wProcessorLevel 0x%x\n"), 153 1.12 uch si.wProcessorLevel)); 154 1.11 uch DPRINTF((TEXT("wProcessorRevision 0x%x\n"), 155 1.12 uch si.wProcessorRevision)); 156 1.11 uch #endif 157 1.4 uch DPRINTF((TEXT("dwPageSize 0x%x\n"), 158 1.12 uch si.dwPageSize)); 159 1.4 uch DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"), 160 1.12 uch si.dwAllocationGranularity)); 161 1.4 uch DPRINTF((TEXT("dwProcessorType 0x%x\n"), 162 1.12 uch si.dwProcessorType)); 163 1.1 uch // inquire default setting. 164 1.1 uch FrameBufferInfo fb(0, 0); 165 1.4 uch DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(), 166 1.3 uch fb.bpp())); 167 1.1 uch } 168 1.1 uch 169 1.1 uch BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int) 170 1.1 uch { 171 1.4 uch 172 1.1 uch return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)> 173 1.3 uch (_load_func(TEXT("LockPages"))); 174 1.1 uch } 175 1.1 uch 176 1.1 uch BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD) 177 1.1 uch { 178 1.4 uch 179 1.1 uch return reinterpret_cast <BOOL(*)(LPVOID, DWORD)> 180 1.3 uch (_load_func(TEXT("UnlockPages"))); 181 1.1 uch } 182