#include <hpcboot.h>
#include <hpcmenu.h>
#include <menu/window.h>
#include <menu/rootwindow.h>
#include <console.h>
#include <memory.h>
#include <load.h>
#include <arch.h>
#include <framebuffer.h>
Architecture::Architecture(Console *&cons, MemoryManager *&mem)
:_cons(cons), _mem(mem)
{
_loader_addr = 0;
_debug = FALSE;
_dll = 0;
}
Architecture::~Architecture(void)
{
if (_dll)
FreeLibrary(_dll);
}
BOOL
Architecture::allocateMemory(size_t sz)
{
sz = _mem->estimateTaggedPageSize(sz);
sz += _mem->getPageSize() * 4;
sz = _mem->roundRegion(sz);
return _mem->reservePage(sz);
}
paddr_t
Architecture::setupBootInfo(Loader &loader)
{
HpcMenuInterface &menu = HpcMenuInterface::Instance();
vaddr_t v;
paddr_t p;
_mem->getPage(v, p);
_boot_arg = reinterpret_cast <struct BootArgs *>(v);
_boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
p + sizeof(struct BootArgs),
_mem->getTaggedPageSize() - sizeof(struct BootArgs));
_boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
menu.setup_bootinfo(_boot_arg->bi);
_boot_arg->bi.bi_cnuse = _cons->getBootConsole();
_boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
_boot_arg->kernel_entry = loader.jumpAddr();
struct bootinfo &bi = _boot_arg->bi;
DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
bi.fb_addr));
DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
return p;
}
void *
Architecture::_load_func(const TCHAR * name)
{
if (_dll == NULL)
_dll = LoadLibrary(TEXT("coredll.dll"));
if (_dll == NULL) {
HWND owner = HpcMenuInterface::Instance()._root->_window;
MessageBox(owner,
TEXT("Can't load coredll.dll."), TEXT("WARNING"),
MB_ICONWARNING | MB_OK);
UpdateWindow(owner);
return NULL;
}
return reinterpret_cast <void *>(GetProcAddress(_dll, name));
}
void
Architecture::systemInfo(void)
{
uint32_t val = 0;
SYSTEM_INFO si;
DPRINTF((TEXT("_WIN32_WCE = %d\n"), _WIN32_WCE));
BOOL (*getVersionEx)(LPOSVERSIONINFO);
getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
(_load_func(TEXT("GetVersionEx")));
if (getVersionEx) {
getVersionEx(&WinCEVersion);
DPRINTF((TEXT("GetVersionEx\n")));
} else {
GetVersionEx(&WinCEVersion);
DPRINTF((TEXT("GetVersionExW\n")));
}
DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
WinCEVersion.dwMinorVersion));
GetSystemInfo(&si);
DPRINTF((TEXT("GetSystemInfo:\n")));
#if _WIN32_WCE >= 200
DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"),
si.wProcessorArchitecture));
DPRINTF((TEXT("wProcessorLevel 0x%x\n"),
si.wProcessorLevel));
DPRINTF((TEXT("wProcessorRevision 0x%x\n"),
si.wProcessorRevision));
#endif
DPRINTF((TEXT("dwPageSize 0x%x\n"),
si.dwPageSize));
DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"),
si.dwAllocationGranularity));
DPRINTF((TEXT("dwProcessorType 0x%x\n"),
si.dwProcessorType));
FrameBufferInfo fb(0, 0);
DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
fb.bpp()));
}
BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
{
return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
(_load_func(TEXT("LockPages")));
}
BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
{
return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
(_load_func(TEXT("UnlockPages")));
}