ReXGlue SDK
Loading...
Searching...
No Matches
midasm.h File Reference
#include <array>
#include <cstddef>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <rex/memory/mapped_ptr.h>
#include <rex/ppc/context.h>
#include <rex/types.h>

Go to the source code of this file.

Namespaces

namespace  rex
namespace  rex::ppc

Macros

#define REX_MIDASM_HOOK(name, params)
#define REX_MIDASM_BRANCH(name, params)
#define REX_MIDASM_RETURN_IF(name, params)
#define REX_MIDASM_AT(name, address, placement, ...)

Detailed Description

License
BSD 3-Clause License See LICENSE file in the project root for full license text.

Macro Definition Documentation

◆ REX_MIDASM_AT

#define REX_MIDASM_AT ( name,
address,
placement,
... )
Value:
static_assert(rex::ppc::detail::IsMidAsmAddress(address), \
"REX_MIDASM_AT address must be a nonzero multiple of 4"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kBadPlacement, \
"REX_MIDASM_AT placement must be before or after"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kUnexpectedTarget, \
"REX_MIDASM_AT takes a target only for a branch body"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kMissingTarget, \
"REX_MIDASM_AT needs the target of a branch body first"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kBadTarget, \
"REX_MIDASM_AT target must be a nonzero multiple of 4"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kBadRegister, \
"REX_MIDASM_AT register must be r0 to r31 except r1, f0 to f31, " \
"v0 to v127, cr0 to cr7, ctr, xer, fpscr, reserved or ctx"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kCountMismatch, \
"REX_MIDASM_AT register count must equal the body parameters"); \
REX_DETAIL_MIDASM_AT_CHECK(name, #placement, #__VA_ARGS__, kTypeMismatch, \
"REX_MIDASM_AT register type does not fit its parameter")

Attaches a mid asm body at an instruction address. A branch body takes its target first, then every body takes one register token per parameter, ctx for a PPCContext parameter. A line that does not fit its body fails to compile.

Parameters
nameName of the body.
addressThe instruction address, a literal.
placementThe token before or after.
...The branch target for a branch body, then the register tokens.
REX_MIDASM_AT(ExampleStep, 0x82000100, after, f10);
#define REX_MIDASM_AT(name, address, placement,...)
Definition midasm.h:1009

◆ REX_MIDASM_BRANCH

#define REX_MIDASM_BRANCH ( name,
params )
Value:
REX_DETAIL_MIDASM_BODY(kBranch, bool, name, params)

Declares a mid asm body that returns bool and makes the generated code jump to the target of its REX_MIDASM_AT line when it returns true.

Parameters
nameName of the body and of its linked symbol.
paramsThe parameter list in parentheses, with names.
REX_MIDASM_BRANCH(ExampleSkip, (u32 size)) {
return size == 0;
}
REX_MIDASM_AT(ExampleSkip, 0x82000300, before, 0x8200030C, r5);
#define REX_MIDASM_BRANCH(name, params)
Definition midasm.h:960

◆ REX_MIDASM_HOOK

#define REX_MIDASM_HOOK ( name,
params )
Value:
REX_DETAIL_MIDASM_BODY(kHook, void, name, params)

Declares a mid asm body that returns void. A pointer or MappedPtr parameter takes an integer register holding a guest address and receives the host pointer, null for 0.

Parameters
nameName of the body and of its linked symbol.
paramsThe parameter list in parentheses, with names.
REX_MIDASM_HOOK(ExampleStep, (PPCRegister& step)) {
step.f64 *= 2.0;
}
REX_MIDASM_AT(ExampleStep, 0x82000100, after, f10);
#define REX_MIDASM_HOOK(name, params)
Definition midasm.h:944

◆ REX_MIDASM_RETURN_IF

#define REX_MIDASM_RETURN_IF ( name,
params )
Value:
REX_DETAIL_MIDASM_BODY(kReturnIf, bool, name, params)

Declares a mid asm body that returns bool and makes the generated code return from the function when it returns true.

Parameters
nameName of the body and of its linked symbol.
paramsThe parameter list in parentheses, with names.
REX_MIDASM_RETURN_IF(ExampleSkipAll, (u32 count)) {
return count == 0;
}
REX_MIDASM_AT(ExampleSkipAll, 0x82000400, before, r3);
#define REX_MIDASM_RETURN_IF(name, params)
Definition midasm.h:976