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