Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/1-nsmbw-osreport.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <kamek.h>
#include <kamek_sdk.h>

// NOTE: bss _must_ be init'ed to zero!
// todo: modify the Riiv patcher to take this into account!
Expand Down
85 changes: 0 additions & 85 deletions k_stdlib/base/hooks.h

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion k_stdlib/egg.h → k_stdlib/k_sdk/egg.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __KAMEK_EGG_H
#define __KAMEK_EGG_H

#include "kamek.h"
#include "../kamek.h"
#include "nw4r.h"

namespace EGG {
Expand Down
2 changes: 1 addition & 1 deletion k_stdlib/nw4r.h → k_stdlib/k_sdk/nw4r.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __KAMEK_NW4R_H
#define __KAMEK_NW4R_H

#include "kamek.h"
#include "../kamek.h"

namespace nw4r {
namespace ut {
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions k_stdlib/k_sdk/types.h
Original file line number Diff line number Diff line change
@@ -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
109 changes: 80 additions & 29 deletions k_stdlib/kamek.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions k_stdlib/kamek_sdk.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions loader/kamekLoader.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <kamek.h>
#include <kamek_sdk.h>

struct DVDHandle
{
Expand Down
1 change: 1 addition & 0 deletions shield-fix/shield-fix.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <kamek.h>
#include <kamek_sdk.h>

/*
* A tiny patch to make the Nvidia Shield port of NSMBW work on Dolphin.
Expand Down