#include <hpcboot.h>
#include <arch.h>
#include <memory.h>
#include <sh3/sh_arch.h>
#include <sh3/sh_mmu.h>
#include <sh3/sh_console.h>
#include <sh3/sh_boot.h>
SHBoot::SHBoot()
{
}
SHBoot::~SHBoot()
{
if (_mem)
delete _mem;
if (_arch)
delete _arch;
SHConsole::Destroy();
}
BOOL
SHBoot::setup()
{
struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
platid_t platid;
platid.dw.dw0 = pref.platid_hi;
platid.dw.dw1 = pref.platid_lo;
if (platid_match(&platid, &platid_mask_CPU_SH_3_7707)) {
args.architecture = ARCHITECTURE_SH3_7707;
} else if (platid_match(&platid, &platid_mask_CPU_SH_3_7709)) {
args.architecture = ARCHITECTURE_SH3_7709;
} else if (platid_match(&platid, &platid_mask_CPU_SH_3_7709A)) {
args.architecture = ARCHITECTURE_SH3_7709A;
} else if (platid_match(&platid, &platid_mask_CPU_SH_4_7750)) {
args.architecture = ARCHITECTURE_SH4_7750;
} else {
DPRINTF((TEXT("CPU not supported.")));
return FALSE;
}
return super::setup();
}
BOOL
SHBoot::create()
{
BOOL(*lock_pages)(LPVOID, DWORD, PDWORD, int);
BOOL(*unlock_pages)(LPVOID, DWORD);
size_t page_size;
if (args.console == CONSOLE_SERIAL) {
_cons = new SHConsole;
if (!_cons->init()) {
_cons = Console::Instance();
DPRINTF((TEXT("use LCD console instead.\n")));
}
} else {
_cons = Console::Instance();
SHConsole::selectBootConsole(*_cons, SHConsole::VIDEO);
}
switch(args.architecture) {
default:
DPRINTF((TEXT("unsupported architecture.\n")));
return FALSE;
case ARCHITECTURE_SH3_7707:
_arch = new SH7707(_cons, _mem, SH7707::boot_func);
page_size = SH3_PAGE_SIZE;
if (SHArchitecture::cpu_type() != 3)
goto cpu_mismatch;
break;
case ARCHITECTURE_SH3_7709:
_arch = new SH7709(_cons, _mem, SH7709::boot_func);
page_size = SH3_PAGE_SIZE;
if (SHArchitecture::cpu_type() != 3)
goto cpu_mismatch;
break;
case ARCHITECTURE_SH3_7709A:
_arch = new SH7709A(_cons, _mem, SH7709A::boot_func);
page_size = SH3_PAGE_SIZE;
if (SHArchitecture::cpu_type() != 3)
goto cpu_mismatch;
break;
case ARCHITECTURE_SH4_7750:
_arch = new SH7750(_cons, _mem, SH7750::boot_func);
page_size = SH4_PAGE_SIZE;
if (SHArchitecture::cpu_type() != 4)
goto cpu_mismatch;
break;
}
_arch->setDebug() = args.architectureDebug;
lock_pages = _arch->_load_LockPages();
unlock_pages = _arch->_load_UnlockPages();
if (lock_pages == 0 || unlock_pages == 0)
args.memory = MEMORY_MANAGER_HARDMMU;
else
args.memory = MEMORY_MANAGER_LOCKPAGES;
switch(args.memory) {
default:
case MEMORY_MANAGER_VIRTUALCOPY:
case MEMORY_MANAGER_SOFTMMU:
DPRINTF((TEXT("unsupported address detection method.\n")));
return FALSE;
case MEMORY_MANAGER_HARDMMU:
if (args.architecture == ARCHITECTURE_SH4_7750) {
DPRINTF((TEXT("No SH4 MMU code.\n")));
return FALSE;
}
_mem = new MemoryManager_SHMMU(_cons, page_size);
break;
case MEMORY_MANAGER_LOCKPAGES:
_mem = new MemoryManager_LockPages(lock_pages, unlock_pages,
_cons, page_size);
break;
}
_mem->setDebug() = args.memorymanagerDebug;
return super::create();
cpu_mismatch:
DPRINTF((TEXT("CPU mismatch. CPU is SH%d\n"),
SHArchitecture::cpu_type()));
return FALSE;
}