kvisc/vm/in/instrs.h

85 lines
3.5 KiB
C

// The OS/K Team licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include <pc/arch.h>
#include <in/flags.h>
#include <in/arch_i.h>
#define GETV(v, p) \
ulong v; \
assert(p); \
if (ACC_FMT_IS_MEM(p->type)) \
v = readmem(ctx, p->addr, p->mlen); \
else v = p->val
#define IMPL_START_0(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *ret) \
{
#define IMPL_START_1(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *ret) \
{ \
GETV(v1, p1);
#define IMPL_START_2(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *ret) \
{ \
GETV(v1, p1); \
GETV(v2, p2);
#define IMPL_OUT_ZSF \
SET_ZSF(v1); \
IMPL_OUT
#define IMPL_OUT \
*ret = v1; \
return 1; \
}
// XXX
#define IMPL_OUT_2 \
*ret = v1; \
return 1; \
}
#define IMPL_END \
return 0; \
}
//
// Consistency checks
//
#define CHK_SUPERV() \
do { \
if ((cr0 & UF) == 1) { \
_except(ctx, E_SYS, "Supervisor-only INSTR"); \
} \
} while (0)
#define CHK_STACK(op) \
if (rsp % 8 > 0 || rbp % 8 > 0) { \
_except(ctx, E_STA, "Misaligned stack REGS"); \
} \
if (rbp op rsp) { \
_except(ctx, E_STU, "Stack underflow"); \
}
//
// Common operations
//
#define PUSH(v) \
rsp -= 8; \
writemem64(ctx, v, rsp);
#define POP(v) \
v = readmem64(ctx, rsp); \
rsp += 8;
#define JUMP(v) \
rip = v + cr1