Home | History | Annotate | Line # | Download | only in hpcboot
      1 /* -*-C++-*-	$NetBSD: arch.cpp,v 1.15 2008/04/28 20:23:20 martin Exp $	 */
      2 
      3 /*-
      4  * Copyright (c) 2001, 2002, 2004 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  *
     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.
     30  */
     31 
     32 #include <hpcboot.h>
     33 #include <hpcmenu.h>
     34 
     35 #include <menu/window.h>
     36 #include <menu/rootwindow.h>	// MessageBox
     37 
     38 #include <console.h>
     39 #include <memory.h>
     40 #include <load.h>
     41 #include <arch.h>
     42 #include <framebuffer.h>
     43 
     44 Architecture::Architecture(Console *&cons, MemoryManager *&mem)
     45 	:_cons(cons), _mem(mem)
     46 {
     47 
     48 	_loader_addr = 0;
     49 	_debug = FALSE;
     50 	_dll = 0;
     51 }
     52 
     53 Architecture::~Architecture(void)
     54 {
     55 
     56 	if (_dll)
     57 		FreeLibrary(_dll);
     58 }
     59 
     60 BOOL
     61 Architecture::allocateMemory(size_t sz)
     62 {
     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);
     69 }
     70 
     71 paddr_t
     72 Architecture::setupBootInfo(Loader &loader)
     73 {
     74 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
     75 	vaddr_t v;
     76 	paddr_t p;
     77 
     78 	_mem->getPage(v, p);
     79 	_boot_arg = reinterpret_cast <struct BootArgs *>(v);
     80 
     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();
     87 
     88 	_boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
     89 	_boot_arg->kernel_entry = loader.jumpAddr();
     90 
     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));
     96 
     97 	return p;
     98 }
     99 
    100 void *
    101 Architecture::_load_func(const TCHAR * name)
    102 {
    103 
    104 	if (_dll == NULL)
    105 		_dll = LoadLibrary(TEXT("coredll.dll"));
    106 
    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);
    113 
    114 		return NULL;
    115 	}
    116 
    117 	return reinterpret_cast <void *>(GetProcAddress(_dll, name));
    118 }
    119 
    120 void
    121 Architecture::systemInfo(void)
    122 {
    123 	uint32_t val = 0;
    124 	SYSTEM_INFO si;
    125 
    126 	DPRINTF((TEXT("_WIN32_WCE = %d\n"), _WIN32_WCE));
    127 	//
    128 	// WCE200 ... GetVersionEx
    129 	// WCE210 or later ... GetVersionExA or GetVersionExW
    130 	// see winbase.h
    131 	//
    132 	BOOL (*getVersionEx)(LPOSVERSIONINFO);
    133 	getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
    134 	    (_load_func(TEXT("GetVersionEx")));
    135 
    136 	if (getVersionEx) {
    137 		getVersionEx(&WinCEVersion);
    138 		DPRINTF((TEXT("GetVersionEx\n")));
    139 	} else {
    140 		GetVersionEx(&WinCEVersion);
    141 		DPRINTF((TEXT("GetVersionExW\n")));
    142 	}
    143 
    144 	DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
    145 	    WinCEVersion.dwMinorVersion));
    146 
    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()));
    167 }
    168 
    169 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
    170 {
    171 
    172 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
    173 	    (_load_func(TEXT("LockPages")));
    174 }
    175 
    176 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
    177 {
    178 
    179 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
    180 	    (_load_func(TEXT("UnlockPages")));
    181 }
    182