From 8f9a2edd1a1f6462c9f658e682da61df55fadcea Mon Sep 17 00:00:00 2001 From: smea Date: Tue, 23 Dec 2014 21:05:55 -0800 Subject: [PATCH] additional HB stuff --- libctru/include/3ds/services/hb.h | 11 +++++++++++ libctru/source/services/hb.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libctru/include/3ds/services/hb.h b/libctru/include/3ds/services/hb.h index 4c9db57..e71dd0f 100644 --- a/libctru/include/3ds/services/hb.h +++ b/libctru/include/3ds/services/hb.h @@ -10,7 +10,18 @@ Result initHb(); void exitHb(); +// flushes/invalidates entire data/instruction cache +// can be useful when writing code to executable pages +Result HB_FlushInvalidateCache(void); + +// fetches the address for ninjhax bootloader addresses, useful for running 3dsx executables +// void (*callBootloader)(Handle hb, Handle file); +// void (*setArgs)(u32* src, u32 length); Result HB_GetBootloaderAddresses(void** load3dsx, void** setArgv); + +// changes the permissions of a given number of pages at address addr to mode +// should it fail, the appropriate kernel error code will be returned and *reprotectedPages (if not NULL) +// will be set to the number of sequential pages which were successfully reprotected + 1 Result HB_ReprotectMemory(u32* addr, u32 pages, u32 mode, u32* reprotectedPages); #endif diff --git a/libctru/source/services/hb.c b/libctru/source/services/hb.c index 8221a4e..cf21f07 100644 --- a/libctru/source/services/hb.c +++ b/libctru/source/services/hb.c @@ -15,6 +15,21 @@ void exitHb() svcCloseHandle(hbHandle); } +Result HB_FlushInvalidateCache(void) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x00010042; + cmdbuf[1] = 0x00000000; + cmdbuf[2] = 0x00000000; + cmdbuf[3] = 0xFFFF8001; + + if((ret = svcSendSyncRequest(hbHandle))!=0) return ret; + + return (Result)cmdbuf[1]; +} + Result HB_GetBootloaderAddresses(void** load3dsx, void** setArgv) { Result ret = 0;