Home | History | Annotate | Line # | Download | only in hpcboot
arch.cpp revision 1.4
      1  1.4  uch /* -*-C++-*-	$NetBSD: arch.cpp,v 1.4 2002/02/04 17:31:34 uch Exp $	 */
      2  1.1  uch 
      3  1.1  uch /*-
      4  1.4  uch  * Copyright (c) 2001, 2002 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  * 3. All advertising materials mentioning features or use of this software
     19  1.1  uch  *    must display the following acknowledgement:
     20  1.1  uch  *        This product includes software developed by the NetBSD
     21  1.1  uch  *        Foundation, Inc. and its contributors.
     22  1.1  uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  uch  *    contributors may be used to endorse or promote products derived
     24  1.1  uch  *    from this software without specific prior written permission.
     25  1.1  uch  *
     26  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  uch  */
     38  1.1  uch 
     39  1.1  uch #include <hpcboot.h>
     40  1.1  uch #include <hpcmenu.h>
     41  1.1  uch 
     42  1.4  uch #include <menu/window.h>
     43  1.4  uch #include <menu/rootwindow.h>	// MessageBox
     44  1.4  uch 
     45  1.1  uch #include <console.h>
     46  1.1  uch #include <memory.h>
     47  1.1  uch #include <load.h>
     48  1.1  uch #include <arch.h>
     49  1.1  uch #include <framebuffer.h>
     50  1.1  uch 
     51  1.1  uch Architecture::Architecture(Console *&cons, MemoryManager *&mem)
     52  1.1  uch 	:_cons(cons), _mem(mem)
     53  1.1  uch {
     54  1.4  uch 
     55  1.1  uch 	_loader_addr = 0;
     56  1.1  uch 	_debug = FALSE;
     57  1.1  uch 	_dll = 0;
     58  1.1  uch }
     59  1.1  uch 
     60  1.1  uch Architecture::~Architecture(void)
     61  1.1  uch {
     62  1.4  uch 
     63  1.1  uch 	if (_dll)
     64  1.1  uch 		FreeLibrary(_dll);
     65  1.1  uch }
     66  1.1  uch 
     67  1.1  uch BOOL
     68  1.1  uch Architecture::allocateMemory(size_t sz)
     69  1.1  uch {
     70  1.1  uch 	//binary image.
     71  1.1  uch 	sz = _mem->estimateTaggedPageSize(sz);
     72  1.1  uch 	//pvec + BootArgs + 2 nd bootloader + bootloader stack.
     73  1.1  uch 	sz += _mem->getPageSize() * 4;
     74  1.1  uch 	sz = _mem->roundRegion(sz);
     75  1.1  uch 	return _mem->reservePage(sz);
     76  1.1  uch }
     77  1.1  uch 
     78  1.1  uch paddr_t
     79  1.2  uch Architecture::setupBootInfo(Loader &loader)
     80  1.1  uch {
     81  1.1  uch 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
     82  1.1  uch 	vaddr_t v;
     83  1.1  uch 	paddr_t p;
     84  1.1  uch 
     85  1.1  uch 	_mem->getPage(v, p);
     86  1.2  uch 	_boot_arg = reinterpret_cast <struct BootArgs *>(v);
     87  1.1  uch 
     88  1.2  uch 	_boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
     89  1.3  uch 	    p + sizeof(struct BootArgs));
     90  1.2  uch 	_boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
     91  1.2  uch 	menu.setup_bootinfo(_boot_arg->bi);
     92  1.2  uch 	_boot_arg->bi.bi_cnuse = _cons->getBootConsole();
     93  1.2  uch 
     94  1.2  uch 	_boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
     95  1.2  uch 	_boot_arg->kernel_entry = loader.jumpAddr();
     96  1.2  uch 
     97  1.2  uch 	struct bootinfo &bi = _boot_arg->bi;
     98  1.2  uch 	DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
     99  1.3  uch 	    bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
    100  1.3  uch 	    bi.fb_addr));
    101  1.2  uch 	DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
    102  1.1  uch 
    103  1.1  uch 	return p;
    104  1.1  uch }
    105  1.1  uch 
    106  1.1  uch void *
    107  1.1  uch Architecture::_load_func(const TCHAR * name)
    108  1.1  uch {
    109  1.4  uch 
    110  1.4  uch 	if (_dll == NULL)
    111  1.1  uch 		_dll = LoadLibrary(TEXT("coredll.dll"));
    112  1.1  uch 
    113  1.4  uch 	if (_dll == NULL) {
    114  1.4  uch 		MessageBox(HpcMenuInterface::Instance()._root->_window,
    115  1.4  uch 		    TEXT("Can't load Coredll.dll"), TEXT("WARNING"), 0);
    116  1.4  uch 
    117  1.4  uch 		return NULL;
    118  1.4  uch 	}
    119  1.4  uch 
    120  1.4  uch 	return reinterpret_cast <void *>(GetProcAddress(_dll, name));
    121  1.1  uch }
    122  1.1  uch 
    123  1.1  uch void
    124  1.1  uch Architecture::systemInfo(void)
    125  1.1  uch {
    126  1.1  uch 	u_int32_t val = 0;
    127  1.4  uch 	SYSTEM_INFO si;
    128  1.1  uch 	HDC hdc;
    129  1.1  uch 
    130  1.4  uch 	GetSystemInfo(&si);
    131  1.4  uch 	DPRINTF((TEXT("GetSystemInfo:\n")));
    132  1.4  uch 	DPRINTF((TEXT("wProcessorArchitecture      0x%x\n"),
    133  1.4  uch 	    si.wProcessorArchitecture));
    134  1.4  uch 	DPRINTF((TEXT("dwPageSize                  0x%x\n"),
    135  1.4  uch 	    si.dwPageSize));
    136  1.4  uch 	DPRINTF((TEXT("dwAllocationGranularity     0x%08x\n"),
    137  1.4  uch 	    si.dwAllocationGranularity));
    138  1.4  uch 	DPRINTF((TEXT("dwProcessorType             0x%x\n"),
    139  1.4  uch 	    si.dwProcessorType));
    140  1.4  uch 	DPRINTF((TEXT("wProcessorLevel             0x%x\n"),
    141  1.4  uch 	    si.wProcessorLevel));
    142  1.4  uch 	DPRINTF((TEXT("wProcessorRevision          0x%x\n"),
    143  1.4  uch 	    si.wProcessorRevision));
    144  1.4  uch 
    145  1.1  uch 	// inquire default setting.
    146  1.1  uch 	FrameBufferInfo fb(0, 0);
    147  1.4  uch 	DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
    148  1.3  uch 	    fb.bpp()));
    149  1.1  uch 
    150  1.1  uch 	ReleaseDC(0, hdc);
    151  1.1  uch }
    152  1.1  uch 
    153  1.1  uch BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
    154  1.1  uch {
    155  1.4  uch 
    156  1.1  uch 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
    157  1.3  uch 	    (_load_func(TEXT("LockPages")));
    158  1.1  uch }
    159  1.1  uch 
    160  1.1  uch BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
    161  1.1  uch {
    162  1.4  uch 
    163  1.1  uch 	return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
    164  1.3  uch 	    (_load_func(TEXT("UnlockPages")));
    165  1.1  uch }
    166  1.1  uch 
    167  1.1  uch //
    168  1.1  uch // Debug support.
    169  1.1  uch //
    170  1.1  uch void
    171  1.1  uch Architecture::_bitdisp(u_int32_t a, int s, int e, int m, int c)
    172  1.1  uch {
    173  1.1  uch 	u_int32_t j, j1;
    174  1.1  uch 	int i, n;
    175  1.1  uch 
    176  1.1  uch 	n = 31;	// 32bit only.
    177  1.1  uch 	j1 = 1 << n;
    178  1.1  uch 	e = e ? e : n;
    179  1.1  uch 	for (j = j1, i = n; j > 0; j >>=1, i--) {
    180  1.1  uch 		if (i > e || i < s) {
    181  1.1  uch 			DPRINTF((TEXT("%c"), a & j ? '+' : '-'));
    182  1.1  uch 		} else {
    183  1.1  uch 			DPRINTF((TEXT("%c"), a & j ? '|' : '.'));
    184  1.1  uch 		}
    185  1.1  uch 	}
    186  1.1  uch 	if (m) {
    187  1.1  uch 		DPRINTF((TEXT("[%s]"),(char*)m));
    188  1.1  uch 	}
    189  1.1  uch 	if (c) {
    190  1.1  uch 		for (j = j1, i = n; j > 0; j >>=1, i--) {
    191  1.1  uch 			if (!(i > e || i < s) &&(a & j)) {
    192  1.1  uch 				DPRINTF((TEXT(" %d"), i));
    193  1.1  uch 			}
    194  1.1  uch 		}
    195  1.1  uch 	}
    196  1.1  uch 	DPRINTF((TEXT(" [0x%08x] %d"), a, a));
    197  1.1  uch 	DPRINTF((TEXT("\n")));
    198  1.1  uch }
    199  1.1  uch 
    200  1.1  uch void
    201  1.1  uch Architecture::_dbg_bit_print(u_int32_t reg, u_int32_t mask, const char *name)
    202  1.1  uch {
    203  1.1  uch 	static const char onoff[3] = "_x";
    204  1.4  uch 
    205  1.1  uch 	DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));
    206  1.1  uch }
    207