mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
117 lines
5.8 KiB
C
117 lines
5.8 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 DECV(v, p) \
|
|
ulong v; \
|
|
GETV(v, p)
|
|
|
|
#define GETV(v, p) \
|
|
assert(p); \
|
|
if (ACC_FMT_IS_MEM(p->type)) \
|
|
v = readmem(ctx, p->addr, p->mlen); \
|
|
else v = p->val
|
|
|
|
#define DECVZX(v, p) \
|
|
ulong v; \
|
|
GETVZX(v, p)
|
|
|
|
#define GETVZX(v, p) \
|
|
assert(p); \
|
|
if (ACC_FMT_IS_MEM(p->type)) \
|
|
v = readmemzx(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, acc_t *p3, \
|
|
ulong *r1, ulong *r2, ulong *r3) \
|
|
{
|
|
|
|
#define IMPL_START_1(name) \
|
|
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
|
|
ulong *r1, ulong *r2, ulong *r3) \
|
|
{ \
|
|
DECV(v1, p1);
|
|
|
|
#define IMPL_START_2(name) \
|
|
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
|
|
ulong *r1, ulong *r2, ulong *r3) \
|
|
{ \
|
|
DECV(v1, p1); \
|
|
DECV(v2, p2);
|
|
|
|
#define IMPL_START_2_ONLY(name) \
|
|
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
|
|
ulong *r1, ulong *r2, ulong *r3) \
|
|
{ \
|
|
ulong v1; (void)v1; \
|
|
DECV(v2, p2);
|
|
|
|
#define IMPL_START_3(name) \
|
|
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
|
|
ulong *r1, ulong *r2, ulong *r3) \
|
|
{ \
|
|
DECV(v1, p1); \
|
|
DECV(v2, p2); \
|
|
DECV(v3, p3);
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#define IMPL_END \
|
|
return 0; \
|
|
}
|
|
|
|
#define IMPL_OUT \
|
|
*r1 = v1; \
|
|
return 1; \
|
|
}
|
|
|
|
#define IMPL_OUT_ZSF \
|
|
SET_ZSF(v1); \
|
|
IMPL_OUT
|
|
|
|
#define IMPL_OUT_2 \
|
|
*r1 = v1; \
|
|
*r2 = v2; \
|
|
return 2; \
|
|
}
|
|
|
|
#define IMPL_OUT_3 \
|
|
*r1 = v1; \
|
|
*r2 = v2; \
|
|
*r3 = v3; \
|
|
return 3; \
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#define ALU_GET_SRCS() \
|
|
ulong src1, src2; \
|
|
if (p3) { \
|
|
src1 = v2; \
|
|
GETV(src2, p3); \
|
|
} else { \
|
|
src1 = v1; \
|
|
src2 = v2; \
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#define CHK_SUPERV() \
|
|
do { \
|
|
if ((cr0 & UF) > 0) { \
|
|
_except(ctx, E_SYS, "Supervisor-only INSTR"); \
|
|
} \
|
|
} while (0)
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|