Kprintf

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Kprintf

Post by TyRaNiD »

Oki been awhile since I posted anything of worth so here is some code to enable your own Kprintf handler. Most of the kernel code calls Kprintf when it errors, or for status information, but installing your own handler you can write to the screen etc anything interesting, could help with debugging kernel functions.

Big NOTE: The handler must be installed in kernel mode (using the previous trick that has already been discussed). It also relies on direct calls as you cannot link kmode and user mode libs in one app, therefore it is dependant on the version of the psp you are running. You have been warned :P

Have fun.

Code: Select all

#ifdef VERSION_10
void (*sceKernelRegisterKprintfHandler)(void *fn, void *arg) = (void*) 0x88007598;
void (*Kprintf)(const char *str, ...) = (void *)0x88007D4C;
#else
void (*sceKernelRegisterKprintfHandler)(void *fn, void *arg) = (void*) 0x8800B5F8;
void (*Kprintf)(const char *str, ...) = (void *)0x8800B550;
#endif

int kprintf_handler(void *arg, const char *str, u32 *args)
{
    printf(str, args[0], args[1], args[2], args[3]);

    return 0;
}

// Main function in kernel mode
int kmain(void)
{
    u32 addr;

    addr = (u32) kprintf_handler;
    addr |= 0x80000000;
    sceKernelRegisterKprintfHandler((void *) addr, NULL);

    return 0;
}
adresd
Posts: 43
Joined: Sat Jan 17, 2004 11:32 am

Post by adresd »

Nice find Tyranid.

Could see that being very useful :)
Post Reply