USBSerialLoggingModule/source/main.cpp

60 lines
1.9 KiB
C++
Raw Permalink Normal View History

2021-10-31 16:35:33 +01:00
#include "kernel.h"
#include "logger.h"
#include "version.h"
2022-02-04 17:48:14 +01:00
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <kernel/kernel.h>
2022-09-04 22:46:59 +02:00
#include <mocha/mocha.h>
2022-02-04 17:48:14 +01:00
#include <wums.h>
2021-10-31 16:35:33 +01:00
WUMS_MODULE_EXPORT_NAME("homebrew_usbseriallogging");
2022-01-26 14:20:14 +01:00
WUMS_MODULE_SKIP_INIT_FINI();
2023-01-07 13:52:40 +01:00
WUMS_DEPENDS_ON(homebrew_kernel);
2021-10-31 16:35:33 +01:00
2023-07-22 11:08:20 +02:00
#define MODULE_VERSION "v0.1.1"
2021-10-31 16:35:33 +01:00
extern "C" void SC_0x51();
2021-12-07 20:57:22 +01:00
WUMS_INITIALIZE() {
initLogging();
2022-09-04 22:46:59 +02:00
int res;
if ((res = Mocha_InitLibrary()) != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Mocha_InitLibrary() failed %d", res);
return;
}
if (Mocha_StartUSBLogging(false) != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Mocha_StartUSBLogging failed");
return;
2021-10-31 16:35:33 +01:00
}
// Patch loader.elf to spit out less warnings when loading .rpx built with wut
KernelNOPAtPhysicalAddress(0x0100b770 - 0x01000000 + 0x32000000);
KernelNOPAtPhysicalAddress(0x0100b800 - 0x01000000 + 0x32000000);
KernelNOPAtPhysicalAddress(0x0100b7b8 - 0x01000000 + 0x32000000);
ICInvalidateRange(reinterpret_cast<void *>(0x0100b770), 0x04);
ICInvalidateRange(reinterpret_cast<void *>(0x0100b800), 0x04);
ICInvalidateRange(reinterpret_cast<void *>(0x0100b7b8), 0x04);
KernelPatchSyscall(0x51, (uint32_t) &IopShellInitInternal);
// Start iopshell on kernel
SC_0x51();
deinitLogging();
2021-10-31 16:35:33 +01:00
}
2022-02-04 17:48:14 +01:00
#define IopShell_UserCallback (0x101C400 + 0x1926c)
#define IopShell_RegisterCallback ((void (*)(uint32_t, uint32_t, uint32_t, uint32_t))(0x101C400 + 0x19638))
#define IopShell_CreateThread ((void (*)(void))(0x101C400 + 0x19504))
2021-10-31 16:35:33 +01:00
WUMS_APPLICATION_STARTS() {
OSReport("Running USBSerialLoggingModule " MODULE_VERSION MODULE_VERSION_EXTRA "\n");
initLogging();
DEBUG_FUNCTION_LINE("Register IopShell_UserCallback");
2021-10-31 16:35:33 +01:00
IopShell_RegisterCallback(IopShell_UserCallback, 0x100978f8, 0x10097900, 0x10097c40);
DEBUG_FUNCTION_LINE("IopShell create thread");
2021-10-31 16:35:33 +01:00
IopShell_CreateThread();
deinitLogging();
2021-10-31 16:35:33 +01:00
}