This commit is contained in:
Chiharu Shirasaka 2020-10-01 23:15:40 +09:00
parent c3c333e6cf
commit b6921e60a8

View File

@ -74,7 +74,7 @@ typedef void (*NKForceCleanBootProc)(BOOL);
#define UART_BASE_ADDR 0x80074000 #define UART_BASE_ADDR 0x80074000
unsigned int *UARTMappedAddr; unsigned int *UARTMappedAddr;
static serialout(char text){ static void serialout(char text){
*UARTMappedAddr=(unsigned int)text; *UARTMappedAddr=(unsigned int)text;
return; return;
} }
@ -99,7 +99,10 @@ unsigned char digit=8;
print("0x"); print("0x");
while (digit) { while (digit) {
int weight = pow(16, digit - 1); int weight = pow(16, digit - 1);
int ans = num / weight; int ans;
for(ans=0;weight<=num;ans++){
num -= weight;
}
if (ans < 10){ if (ans < 10){
serialout('0' + ans); serialout('0' + ans);
} }
@ -151,11 +154,11 @@ static void EDNA2_physicalInvoker(){
static void EDNA2_installPhysicalInvoker(){ static void EDNA2_installPhysicalInvoker(){
void *ptr=(void *)0xa8000000; void *ptr=(void *)0xa8000000;
print("BrainLILO: Invoker copying to ",1); print("BrainLILO: Invoker copying to ");
printhex((int)(ptr),1); printhex((int)(ptr));
print(" from ",1); print(" from ");
printhex((int)(&EDNA2_physicalInvoker),1); printhex((int)(&EDNA2_physicalInvoker));
print("\n",1); print("\n");
memcpy(ptr, (const void *)&EDNA2_physicalInvoker, 64*4); memcpy(ptr, (const void *)&EDNA2_physicalInvoker, 64*4);
//clearCache(); //clearCache();
} }
@ -199,11 +202,11 @@ static void EDNA2_runPhysicalInvoker(unsigned long bootloaderphysaddr,DWORD size
__attribute__((noreturn)) __attribute__((noreturn))
static DWORD EDNA2_callKernelEntryPoint(unsigned long bootloaderphysaddr,DWORD size){ static DWORD EDNA2_callKernelEntryPoint(unsigned long bootloaderphysaddr,DWORD size){
print(L"BrainLILO: disabling interrupts\n"); print("BrainLILO: disabling interrupts\n");
disableInterrupts(); disableInterrupts();
print(L"BrainLILO: injecting code to internal ram\n"); print("BrainLILO: injecting code to internal ram\n");
EDNA2_installPhysicalInvoker(); EDNA2_installPhysicalInvoker();
print(L"BrainLILO: invoking\n"); print("BrainLILO: invoking\n");
EDNA2_runPhysicalInvoker(bootloaderphysaddr,size); EDNA2_runPhysicalInvoker(bootloaderphysaddr,size);
} }
@ -219,19 +222,19 @@ static bool doLinux(){
dll=LoadLibrary(TEXT("COREDLL.DLL")); dll=LoadLibrary(TEXT("COREDLL.DLL"));
if (dll == NULL) { if (dll == NULL) {
print(L"Cant load DLL\n"); print("Cant load DLL\n");
return false; return false;
} }
AllocPhysMem=(AllocPhysMemProc)GetProcAddress(dll,TEXT("AllocPhysMem")); AllocPhysMem=(AllocPhysMemProc)GetProcAddress(dll,TEXT("AllocPhysMem"));
if (AllocPhysMem == NULL) { if (AllocPhysMem == NULL) {
print(L"Cant load AllocPhysMem function\n"); print("Cant load AllocPhysMem function\n");
return false; return false;
} }
print(L"BrainLILO: loading bootloader.\n"); print("BrainLILO: loading bootloader.\n");
hFile = CreateFile(bootloaderFileName , GENERIC_READ , 0 , NULL ,OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL); hFile = CreateFile(bootloaderFileName , GENERIC_READ , 0 , NULL ,OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
if (hFile == INVALID_HANDLE_VALUE) { if (hFile == INVALID_HANDLE_VALUE) {
print(L"Cant load bootloader\n"); print("Cant load bootloader\n");
return false; return false;
} }
bootloaderdata = (char *)malloc(GetFileSize(hFile , NULL)); bootloaderdata = (char *)malloc(GetFileSize(hFile , NULL));
@ -245,7 +248,7 @@ static bool doLinux(){
printhex((int)(bootloaderdata)); printhex((int)(bootloaderdata));
print("\n"); print("\n");
memcpy(bootloaderptr,bootloaderdata,wReadSize); memcpy(bootloaderptr,bootloaderdata,wReadSize);
print(L"BrainLILO: bootloader preloaded\n"); print("BrainLILO: bootloader preloaded\n");
free(bootloaderdata); free(bootloaderdata);
FreeLibrary(dll); FreeLibrary(dll);
EDNA2_callKernelEntryPoint(bootloaderphysaddr,wReadSize); EDNA2_callKernelEntryPoint(bootloaderphysaddr,wReadSize);
@ -288,7 +291,7 @@ extern "C" BRAINLILODRV_API DWORD LIN_Seek(DWORD handle, long lDistance, DWORD d
extern "C" BRAINLILODRV_API void LIN_PowerUp(void){ extern "C" BRAINLILODRV_API void LIN_PowerUp(void){
print(L"BrainLILO: resuming."); print("BrainLILO: resuming.");
} }
@ -348,8 +351,9 @@ extern "C" BOOL APIENTRY DllMainCRTStartup( HANDLE hModule,
FileSystemPowerFunction=(FileSystemPowerFunctionProc) FileSystemPowerFunction=(FileSystemPowerFunctionProc)
GetProcAddress(LoadLibrary(L"COREDLL"), GetProcAddress(LoadLibrary(L"COREDLL"),
L"FileSystemPowerFunction"); L"FileSystemPowerFunction");
PHYSICAL_ADDRESS pa;
UARTMappedAddr=MmMapIoSpace(UART_BASE_ADDR,0x48,FALSE);//Map to Virtual Addr pa.QuadPart = UART_BASE_ADDR;
UARTMappedAddr=(unsigned int*)MmMapIoSpace(pa,0x48,FALSE);//Map to Virtual Addr
*(UARTMappedAddr+0x38)=0;//Interrupt Disable *(UARTMappedAddr+0x38)=0;//Interrupt Disable
*(UARTMappedAddr+0x30)=0b0100000100000001;//RTS Hardware Flow Control, Transmit, UART Enable *(UARTMappedAddr+0x30)=0b0100000100000001;//RTS Hardware Flow Control, Transmit, UART Enable