From 5f2414755e09195862d8f400ae09cfac7c23fc7e Mon Sep 17 00:00:00 2001 From: wiidev Date: Thu, 16 Feb 2023 23:40:02 +0000 Subject: [PATCH] Correctly boot ELF files --- source/appboot.c | 7 ------ source/boot/source/main.c | 47 +++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/source/appboot.c b/source/appboot.c index d8c6a21..e6cc0ed 100644 --- a/source/appboot.c +++ b/source/appboot.c @@ -14,8 +14,6 @@ #include "iospatch.h" #include "video.h" -extern void __exception_closeall(); - struct __argv arguments; char* m_argv[256]; @@ -178,12 +176,7 @@ void LaunchApp(void) } printf("-> And we're outta here!\n"); - - *(vu32*)0x800000F8 = 0x0E7BE2C0; // Bus Speed - *(vu32*)0x800000FC = 0x2B73A840; // CPU Speed - //SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); - __exception_closeall(); entry(); printf("--> Well.. this shouldn't happen\n"); diff --git a/source/boot/source/main.c b/source/boot/source/main.c index 43c02d4..f2eddeb 100644 --- a/source/boot/source/main.c +++ b/source/boot/source/main.c @@ -5,10 +5,11 @@ #include #include #include +#include #include "loader.h" -extern void __exception_setreload(int t); +extern void __exception_closeall(); static void* xfb = NULL; static GXRModeObj* rmode = NULL; @@ -24,18 +25,28 @@ void VideoInit(void) VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); + console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); - if(rmode->viTVMode&VI_NON_INTERLACE) + if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); printf("\x1b[2;0H"); } +bool IsDollZ(const u8* buffer) +{ + return (buffer[0x100] == 0x3C); +} + +bool IsSpecialELF(const u8* buffer) +{ + return (read32((u32)buffer) == 0x7F454C46 && buffer[0x24] == 0); +} + int main(void) { VideoInit(); @@ -66,23 +77,31 @@ int main(void) DCFlushRange(&execPtr[0x20], 1); } - u32 argumentsSize = *(vu32*)0x91000000; - if (argumentsSize > 0) + if (!IsDollZ(buffer) && !IsSpecialELF(buffer)) { - u32* ptr = (u32*)entry; - - if (ptr[1] == 0x5F617267) + u32 argumentsSize = *(vu32*)0x91000000; + if (argumentsSize > 0) { - struct Arguments* argv = (struct Arguments*)&ptr[2]; + u32* ptr = (u32*)entry; - argv->magic = 0x5F617267; - argv->cmdLine = (char*)0x91000020; - argv->length = argumentsSize; + if (ptr[1] == 0x5F617267) + { + struct Arguments* argv = (struct Arguments*)&ptr[2]; - DCFlushRange(&ptr[2], 4); + argv->magic = 0x5F617267; + argv->cmdLine = (char*)0x91000020; + argv->length = argumentsSize; + + DCFlushRange(&ptr[2], 4); + } } } - + + SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); + u32 level = IRQ_Disable(); + __exception_closeall(); entry(); + IRQ_Restore(level); + return 0; }