TuxSH 7074ac1166 Move hb:ldr from Rosalina to Loader
Let's not pretend in 2022 that it needed things from rosalina sysmodule
- it did not.

This moves 3DSX loading from Rosalina to Loader, and also removes all
the dependencies Loader had to other Luma3DS components (if kernel ext.
is missing, a default config will be used). This means that, as long as
you replace Loader to the one in here, you will be able to properly load
3DSX files.

Changes:
- hb:ldr is now hosted in loader
- hb:ldr LoadProcess, PatchExHeaderInfo, DebugNextApplicationByForce:
  all removed
- fix a bug where some malformed 3DSX files were not rejected
- grant access to CONFIG11 registers to 3DSX homebrew
- move dirty homebrew chainload (when HM. isn't loaded nor loadable) to
  pm
- pm:dbg (ext.) PrepareToChainloadHomebrew: removed
2022-12-25 23:27:48 +01:00

68 lines
2.1 KiB
C

#include <3ds.h>
#include <string.h>
#include "launch.h"
#include "info.h"
#include "util.h"
#include "manager.h"
void pmDbgHandleCommands(void *ctx)
{
(void)ctx;
u32 *cmdbuf = getThreadCommandBuffer();
u32 cmdhdr = cmdbuf[0];
FS_ProgramInfo programInfo;
Handle debug;
u32 pid;
u32 launchFlags;
switch (cmdhdr >> 16) {
case 1:
debug = 0;
memcpy(&programInfo, cmdbuf + 1, sizeof(FS_ProgramInfo));
cmdbuf[1] = LaunchAppDebug(&debug, &programInfo, cmdbuf[5]);
cmdbuf[0] = IPC_MakeHeader(1, 1, 2);
cmdbuf[2] = IPC_Desc_MoveHandles(1);
cmdbuf[3] = debug;
break;
case 2:
memcpy(&programInfo, cmdbuf + 1, sizeof(FS_ProgramInfo));
cmdbuf[1] = LaunchApp(&programInfo, cmdbuf[5]);
cmdbuf[0] = IPC_MakeHeader(2, 1, 0);
break;
case 3:
debug = 0;
cmdbuf[1] = RunQueuedProcess(&debug);
cmdbuf[0] = IPC_MakeHeader(3, 1, 2);
cmdbuf[2] = IPC_Desc_MoveHandles(1);
cmdbuf[3] = debug;
break;
// Custom
case 0x100:
cmdbuf[1] = GetCurrentAppInfo(&programInfo, &pid, &launchFlags);
cmdbuf[0] = IPC_MakeHeader(0x100, 7, 0);
memcpy(cmdbuf + 2, &programInfo, sizeof(FS_ProgramInfo));
cmdbuf[6] = pid;
cmdbuf[7] = launchFlags;
break;
case 0x101:
cmdbuf[1] = DebugNextApplicationByForce(cmdbuf[1] != 0);
cmdbuf[0] = IPC_MakeHeader(0x101, 1, 0);
break;
case 0x102:
debug = 0;
memcpy(&programInfo, cmdbuf + 1, sizeof(FS_ProgramInfo));
cmdbuf[1] = LaunchTitleDebug(&debug, &programInfo, cmdbuf[5]);
cmdbuf[0] = IPC_MakeHeader(0x102, 1, 2);
cmdbuf[2] = IPC_Desc_MoveHandles(1);
cmdbuf[3] = debug;
break;
case 0x103: // PrepareToChainloadHomebrew (removed)
default:
cmdbuf[0] = IPC_MakeHeader(0, 1, 0);
cmdbuf[1] = 0xD900182F;
break;
}
}