1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/vm/in/instrs.h
julianb0 e1299836de
vm
2019-08-03 19:01:12 +02:00

78 lines
3.9 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>
//----------------------------------------------------------------------------//
#define IMPL_START(name) \
uint i_##name(acc_t *p1, acc_t *p2, acc_t *p3, \
ulong *r1, ulong *r2, ulong *r3) \
#define XSRCP(v, p, x) \
if (ACC_FMT_IS_MEM(p->type)) \
v = readmem##x(p->addr, p->mlen); \
else v = p->val; \
#define SRCP(p) \
if (__builtin_expect(ACC_FMT_IS_MEM(p->type), 0)) \
p->val = readmemsx(p->addr, p->mlen); \
//----------------------------------------------------------------------------//
#define INTO() \
if (R(RFX) & OF) _except(E_OVF, "Overflow");
#define PARITY(v) __builtin_parity(v)
#define SET_ZF(v) \
R(RFX) = ((v) == 0 ? (R(RFX)|ZF) : (R(RFX)&~ZF))
#define SET_SF(v) \
R(RFX) = ((long)(v) < 0 ? (R(RFX)|SF) : (R(RFX)&~SF))
#define SET_PF(v) \
R(RFX) = (PARITY(v) == 1 ? (R(RFX)|PF) : (R(RFX)&~PF))
#define SET_ZSF(v) \
SET_ZF(v); \
SET_SF(v)
//----------------------------------------------------------------------------//
#define COMPARE_ADD(v1, v2) \
ulong _u1 = (ulong)v1, _u2 = (ulong)v2, _u3 = (_u1 + _u2); \
\
if (_u1 + _u2 < _u2) R(RFX) |= CF; \
else R(RFX) &= ~CF; \
\
if (((_u1 ^ _u3) & (_u2 ^ _u3)) >> 63) \
R(RFX) |= OF; \
else R(RFX) &= ~OF; \
\
SET_ZSF(_u3);
#define COMPARE_SUB(v1, v2) \
ulong _u1 = (ulong)v1, _u2 = (ulong)v2, _u3 = (_u1 - _u2); \
\
if (_u1 < _u2) R(RFX) |= CF; \
else R(RFX) &= ~CF; \
\
if (((_u1 ^ _u3) & (_u1 ^ _u2)) >> 63) \
R(RFX) |= OF; \
else R(RFX) &= ~OF; \
\
SET_ZSF(_u3);
//----------------------------------------------------------------------------//
#define CHK_SUPERV() \
do { \
if ((R(CR0) & UF) > 0) { \
_except(E_SYS, "Supervisor-only INSTR"); \
} \
} while (0)
//----------------------------------------------------------------------------//