Home | History | Annotate | Line # | Download | only in hpcboot
arch.cpp revision 1.6
      1 /* -*-C++-*-	$NetBSD: arch.cpp,v 1.6 2002/03/02 22:01:05 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 	_boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
     91 	menu.setup_bootinfo(_boot_arg->bi);
     92 	_boot_arg->bi.bi_cnuse = _cons->getBootConsole();
     93 
     94 	_boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
     95 	_boot_arg->kernel_entry = loader.jumpAddr();
     96 
     97 	struct bootinfo &bi = _boot_arg->bi;
     98 	DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
     99 	    bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
    100 	    bi.fb_addr));
    101 	DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
    102 
    103 	return p;
    104 }
    105 
    106 void *
    107 Architecture::_load_func(const TCHAR * name)
    108 {
    109 
    110 	if (_dll == NULL)
    111 		_dll = LoadLibrary(TEXT("coredll.dll"));
    112 
    113 	if (_dll == NULL) {
    114 		MessageBox(HpcMenuInterface::Instance()._root->_window,
    115 		    TEXT("Can't load Coredll.dll"), TEXT("WARNING"), 0);
    116 
    117 		return NULL;
    118 	}
    119 
    120 	return reinterpret_cast <void *>(GetProcAddress(_dll, name));
    121 }
    122 
    123 void
    124 Architecture::systemInfo(void)
    125 {
    126 	u_int32_t val = 0;
    127 	SYSTEM_INFO si;
    128 	HDC hdc;
    129 	BOOL (*getVersionEx)(LPOSVERSIONINFO);
    130 
    131 	//
    132 	// WCE200 ... GetVersionEx
    133 	// WCE210 or later ... GetVersionExA or GetVersionExW
    134 	// see winbase.h
    135 	//
    136 	getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
    137 	    (_load_func(TEXT("GetVersionEx")));
    138 
    139 	if (getVersionEx) {
    140 		getVersionEx(&WinCEVersion);
    141 		DPRINTF((TEXT("GetVersionEx\n")));
    142 	} else {
    143 		GetVersionEx(&WinCEVersion);
    144 		DPRINTF((TEXT("GetVersionExW\n")));
    145 	}
    146 
    147 	DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
    148 	    WinCEVersion.dwMinorVersion));
    149 
    150 	GetSystemInfo(&si);
    151 	DPRINTF((TEXT("GetSystemInfo:\n")));
    152 	DPRINTF((TEXT("wProcessorArchitecture      0x%x\n"),
    153 	    si.wProcessorArchitecture));
    154 	DPRINTF((TEXT("dwPageSize                  0x%x\n"),
    155 	    si.dwPageSize));
    156 	DPRINTF((TEXT("dwAllocationGranularity     0x%08x\n"),
    157 	    si.dwAllocationGranularity));
    158 	DPRINTF((TEXT("dwProcessorType             0x%x\n"),
    159 	    si.dwProcessorType));
    160 	DPRINTF((TEXT("wProcessorLevel             0x%x\n"),
    161 	    si.wProcessorLevel));
    162 	DPRINTF((TEXT("wProcessorRevision          0x%x\n"),
    163 	    si.wProcessorRevision));
    164 
    165 	// inquire default setting.
    166 	FrameBufferInfo fb(0, 0);
    167 	DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
    168 	    fb.bpp()));
    169 
    170 	ReleaseDC(0, hdc);
    171 }
    172 
    173 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
    174 {
    175 
    176 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
    177 	    (_load_func(TEXT("LockPages")));
    178 }
    179 
    180 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
    181 {
    182 
    183 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
    184 	    (_load_func(TEXT("UnlockPages")));
    185 }
    186