PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
debug.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Licenced under Academic Free License version 2.0
7# Review ps2sdk README & LICENSE files for further details.
8*/
9
10#include "kernel.h"
11#include "syscallnr.h"
12
13void InitDebug(void)
14{
15 void (*krnl_print)(const char* format, ...) = NULL;
16
17 // Get the address of ResetEE so we can find where printf is located.
18 u32* resetEEAddress = (u32*)GetSyscallHandler(__NR_ResetEE);
19
20 // Find the first JAL instruction in ResetEE which should be a printf call.
21 ee_kmode_enter();
22 for (int i = 0; i < 15; i++)
23 {
24 // Check if the current instruction is a JAL.
25 u32 jalPrintf = resetEEAddress[i];
26 if ((jalPrintf & 0xFC000000) == 0xC000000)
27 {
28 // Get the call target which is the address of printf.
29 krnl_print = (void(*)(const char*, ...))(0x80000000 + ((jalPrintf & 0x3FFFFFF) << 2));
30 break;
31 }
32 }
33 ee_kmode_exit();
34
35 // If we found the printf function address re-enable the printf syscall.
36 if (krnl_print != NULL)
37 SetSyscall(__NR__print, krnl_print);
38}