diff --git a/examples/1-nsmbw-osreport.cpp b/examples/1-nsmbw-osreport.cpp index 842697b..bea8fa3 100644 --- a/examples/1-nsmbw-osreport.cpp +++ b/examples/1-nsmbw-osreport.cpp @@ -1,4 +1,5 @@ #include +#include // NOTE: bss _must_ be init'ed to zero! // todo: modify the Riiv patcher to take this into account! diff --git a/k_stdlib/base/hooks.h b/k_stdlib/base/hooks.h deleted file mode 100644 index 0c1cf32..0000000 --- a/k_stdlib/base/hooks.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __KAMEK_BASE_HOOKS_H -#define __KAMEK_BASE_HOOKS_H - -// allow Kamek hooks to be defined from C++ source files -#pragma section ".kamek" - -// hook type IDs _must_ match what's in the Kamek source! -#define kctWrite 1 -#define kctConditionalWrite 2 -#define kctInjectBranch 3 -#define kctInjectCall 4 -#define kctPatchExit 5 - - -#define kmIdentifier(key, counter) \ - _k##key##counter -#define kmHookInt(counter) \ - __declspec (section ".kamek") static const u32 kmIdentifier(Hook, counter) - -// general hook definition macros -// TODO: debugging data (file, line, ...) for diagnostic use by Kamek maybe? :3 -#define kmHook0(type) \ - kmHookInt(__COUNTER__)[2] = { 0, (type) } -#define kmHook1(type, arg0) \ - kmHookInt(__COUNTER__)[3] = { 1, (type), (u32)(arg0) } -#define kmHook2(type, arg0, arg1) \ - kmHookInt(__COUNTER__)[4] = { 2, (type), (u32)(arg0), (u32)(arg1) } -#define kmHook3(type, arg0, arg1, arg2) \ - kmHookInt(__COUNTER__)[5] = { 3, (type), (u32)(arg0), (u32)(arg1), (u32)(arg2) } -#define kmHook4(type, arg0, arg1, arg2, arg3) \ - kmHookInt(__COUNTER__)[6] = { 4, (type), (u32)(arg0), (u32)(arg1), (u32)(arg2), (u32)(arg3) } - -// kmCondWrite -// Write value to address, conditionally -#define kmCondWritePointer(addr, original, value) kmHook4(kctConditionalWrite, 1, (addr), (value), (original)) -#define kmCondWrite32(addr, original, value) kmHook4(kctConditionalWrite, 2, (addr), (value), (original)) -#define kmCondWrite16(addr, original, value) kmHook4(kctConditionalWrite, 3, (addr), (value), (original)) -#define kmCondWrite8(addr, original, value) kmHook4(kctConditionalWrite, 4, (addr), (value), (original)) - -// kmWrite -// Write value to address -#define kmWritePointer(addr, ptr) kmHook3(kctWrite, 1, (addr), (ptr)) -#define kmWrite32(addr, value) kmHook3(kctWrite, 2, (addr), (value)) -#define kmWrite16(addr, value) kmHook3(kctWrite, 3, (addr), (value)) -#define kmWrite8(addr, value) kmHook3(kctWrite, 4, (addr), (value)) - -// kmPatchExitPoint -// Force the end of a Kamek function to always jump to a specific address -// (if the address is 0, the end remains as-is (i.e. blr)) -#define kmPatchExitPoint(funcStart, dest) kmHook2(kctPatchExit, (funcStart), (dest)) - -// kmBranch, kmCall -// Set up a branch from a specific instruction to a specific address -#define kmBranch(addr, ptr) kmHook2(kctInjectBranch, (addr), (ptr)) -#define kmCall(addr, ptr) kmHook2(kctInjectCall, (addr), (ptr)) - -// kmBranchDefCpp, kmBranchDefAsm -// Set up a branch (b) from a specific instruction to a function defined -// directly underneath. If exitPoint is not NULL, the function will -// branch to exitPoint when done; otherwise, it executes blr as normal -#define kmBranchDefInt(counter, addr, exitPoint, returnType, ...) \ - static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__); \ - kmBranch(addr, kmIdentifier(UserFunc, counter)); \ - kmPatchExitPoint(kmIdentifier(UserFunc, counter), exitPoint); \ - static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__) - -#define kmBranchDefCpp(addr, exitPoint, returnType, ...) \ - kmBranchDefInt(__COUNTER__, addr, exitPoint, returnType, __VA_ARGS__) -#define kmBranchDefAsm(addr, exitPoint) \ - kmBranchDefInt(__COUNTER__, addr, exitPoint, asm void, ) - -// kmCallDefCpp, kmCallDefAsm -// Set up a branch with link (bl) from a specific instruction to a function -// defined directly underneath. -#define kmCallDefInt(counter, addr, returnType, ...) \ - static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__); \ - kmCall(addr, kmIdentifier(UserFunc, counter)); \ - static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__) - -#define kmCallDefCpp(addr, returnType, ...) \ - kmCallDefInt(__COUNTER__, addr, returnType, __VA_ARGS__) -#define kmCallDefAsm(addr) \ - kmCallDefInt(__COUNTER__, addr, asm void, ) - -#endif diff --git a/k_stdlib/base/c_stdlib.h b/k_stdlib/k_sdk/c_stdlib.h similarity index 100% rename from k_stdlib/base/c_stdlib.h rename to k_stdlib/k_sdk/c_stdlib.h diff --git a/k_stdlib/egg.h b/k_stdlib/k_sdk/egg.h similarity index 99% rename from k_stdlib/egg.h rename to k_stdlib/k_sdk/egg.h index 79f80e4..cad8732 100644 --- a/k_stdlib/egg.h +++ b/k_stdlib/k_sdk/egg.h @@ -1,7 +1,7 @@ #ifndef __KAMEK_EGG_H #define __KAMEK_EGG_H -#include "kamek.h" +#include "../kamek.h" #include "nw4r.h" namespace EGG { diff --git a/k_stdlib/nw4r.h b/k_stdlib/k_sdk/nw4r.h similarity index 99% rename from k_stdlib/nw4r.h rename to k_stdlib/k_sdk/nw4r.h index 02bac3f..941ecb7 100644 --- a/k_stdlib/nw4r.h +++ b/k_stdlib/k_sdk/nw4r.h @@ -1,7 +1,7 @@ #ifndef __KAMEK_NW4R_H #define __KAMEK_NW4R_H -#include "kamek.h" +#include "../kamek.h" namespace nw4r { namespace ut { diff --git a/k_stdlib/base/rvl_sdk.h b/k_stdlib/k_sdk/rvl_sdk.h similarity index 100% rename from k_stdlib/base/rvl_sdk.h rename to k_stdlib/k_sdk/rvl_sdk.h diff --git a/k_stdlib/k_sdk/types.h b/k_stdlib/k_sdk/types.h new file mode 100644 index 0000000..baf46d6 --- /dev/null +++ b/k_stdlib/k_sdk/types.h @@ -0,0 +1,29 @@ +#ifndef __KAMEK_TYPES_H +#define __KAMEK_TYPES_H + +#define NULL 0 + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; +typedef float f32; +typedef double f64; +typedef volatile s64 vs64; +typedef volatile s32 vs32; +typedef volatile s16 vs16; +typedef volatile s8 vs8; +typedef volatile u64 vu64; +typedef volatile u32 vu32; +typedef volatile u16 vu16; +typedef volatile u8 vu8; +typedef volatile f64 vf64; +typedef volatile f32 vf32; + +typedef unsigned long size_t; + +#endif diff --git a/k_stdlib/kamek.h b/k_stdlib/kamek.h index 2c4e528..954fd41 100644 --- a/k_stdlib/kamek.h +++ b/k_stdlib/kamek.h @@ -11,34 +11,85 @@ #error "Kamek requires the CodeWarrior compiler!" #endif -#define NULL 0 - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; -typedef signed char s8; -typedef signed short s16; -typedef signed int s32; -typedef signed long long s64; -typedef float f32; -typedef double f64; -typedef volatile s64 vs64; -typedef volatile s32 vs32; -typedef volatile s16 vs16; -typedef volatile s8 vs8; -typedef volatile u64 vu64; -typedef volatile u32 vu32; -typedef volatile u16 vu16; -typedef volatile u8 vu8; -typedef volatile f64 vf64; -typedef volatile f32 vf32; - -typedef unsigned long size_t; - -#include "base/hooks.h" -#include "base/c_stdlib.h" -#include "base/rvl_sdk.h" +// allow Kamek hooks to be defined from C++ source files +#pragma section ".kamek" -#endif +// hook type IDs _must_ match what's in the Kamek source! +#define kctWrite 1 +#define kctConditionalWrite 2 +#define kctInjectBranch 3 +#define kctInjectCall 4 +#define kctPatchExit 5 + + +#define kmIdentifier(key, counter) \ + _k##key##counter +#define kmHookInt(counter) \ + __declspec (section ".kamek") static const unsigned int kmIdentifier(Hook, counter) + +// general hook definition macros +// TODO: debugging data (file, line, ...) for diagnostic use by Kamek maybe? :3 +#define kmHook0(type) \ + kmHookInt(__COUNTER__)[2] = { 0, (type) } +#define kmHook1(type, arg0) \ + kmHookInt(__COUNTER__)[3] = { 1, (type), (unsigned int)(arg0) } +#define kmHook2(type, arg0, arg1) \ + kmHookInt(__COUNTER__)[4] = { 2, (type), (unsigned int)(arg0), (unsigned int)(arg1) } +#define kmHook3(type, arg0, arg1, arg2) \ + kmHookInt(__COUNTER__)[5] = { 3, (type), (unsigned int)(arg0), (unsigned int)(arg1), (unsigned int)(arg2) } +#define kmHook4(type, arg0, arg1, arg2, arg3) \ + kmHookInt(__COUNTER__)[6] = { 4, (type), (unsigned int)(arg0), (unsigned int)(arg1), (unsigned int)(arg2), (unsigned int)(arg3) } + +// kmCondWrite +// Write value to address, conditionally +#define kmCondWritePointer(addr, original, value) kmHook4(kctConditionalWrite, 1, (addr), (value), (original)) +#define kmCondWrite32(addr, original, value) kmHook4(kctConditionalWrite, 2, (addr), (value), (original)) +#define kmCondWrite16(addr, original, value) kmHook4(kctConditionalWrite, 3, (addr), (value), (original)) +#define kmCondWrite8(addr, original, value) kmHook4(kctConditionalWrite, 4, (addr), (value), (original)) + +// kmWrite +// Write value to address +#define kmWritePointer(addr, ptr) kmHook3(kctWrite, 1, (addr), (ptr)) +#define kmWrite32(addr, value) kmHook3(kctWrite, 2, (addr), (value)) +#define kmWrite16(addr, value) kmHook3(kctWrite, 3, (addr), (value)) +#define kmWrite8(addr, value) kmHook3(kctWrite, 4, (addr), (value)) + +// kmPatchExitPoint +// Force the end of a Kamek function to always jump to a specific address +// (if the address is 0, the end remains as-is (i.e. blr)) +#define kmPatchExitPoint(funcStart, dest) kmHook2(kctPatchExit, (funcStart), (dest)) +// kmBranch, kmCall +// Set up a branch from a specific instruction to a specific address +#define kmBranch(addr, ptr) kmHook2(kctInjectBranch, (addr), (ptr)) +#define kmCall(addr, ptr) kmHook2(kctInjectCall, (addr), (ptr)) + +// kmBranchDefCpp, kmBranchDefAsm +// Set up a branch (b) from a specific instruction to a function defined +// directly underneath. If exitPoint is not NULL, the function will +// branch to exitPoint when done; otherwise, it executes blr as normal +#define kmBranchDefInt(counter, addr, exitPoint, returnType, ...) \ + static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__); \ + kmBranch(addr, kmIdentifier(UserFunc, counter)); \ + kmPatchExitPoint(kmIdentifier(UserFunc, counter), exitPoint); \ + static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__) + +#define kmBranchDefCpp(addr, exitPoint, returnType, ...) \ + kmBranchDefInt(__COUNTER__, addr, exitPoint, returnType, __VA_ARGS__) +#define kmBranchDefAsm(addr, exitPoint) \ + kmBranchDefInt(__COUNTER__, addr, exitPoint, asm void, ) + +// kmCallDefCpp, kmCallDefAsm +// Set up a branch with link (bl) from a specific instruction to a function +// defined directly underneath. +#define kmCallDefInt(counter, addr, returnType, ...) \ + static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__); \ + kmCall(addr, kmIdentifier(UserFunc, counter)); \ + static returnType kmIdentifier(UserFunc, counter) (__VA_ARGS__) + +#define kmCallDefCpp(addr, returnType, ...) \ + kmCallDefInt(__COUNTER__, addr, returnType, __VA_ARGS__) +#define kmCallDefAsm(addr) \ + kmCallDefInt(__COUNTER__, addr, asm void, ) + +#endif diff --git a/k_stdlib/kamek_sdk.h b/k_stdlib/kamek_sdk.h new file mode 100644 index 0000000..f85637a --- /dev/null +++ b/k_stdlib/kamek_sdk.h @@ -0,0 +1,8 @@ +#ifndef __KAMEK_SDK_H +#define __KAMEK_SDK_H + +#include "k_sdk/types.h" +#include "k_sdk/c_stdlib.h" +#include "k_sdk/rvl_sdk.h" + +#endif diff --git a/loader/kamekLoader.h b/loader/kamekLoader.h index 5641dc9..81f1305 100644 --- a/loader/kamekLoader.h +++ b/loader/kamekLoader.h @@ -1,4 +1,5 @@ #include +#include struct DVDHandle { diff --git a/shield-fix/shield-fix.cpp b/shield-fix/shield-fix.cpp index 4f4762c..1ef9ba0 100644 --- a/shield-fix/shield-fix.cpp +++ b/shield-fix/shield-fix.cpp @@ -1,4 +1,5 @@ #include +#include /* * A tiny patch to make the Nvidia Shield port of NSMBW work on Dolphin.