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

145 lines
6.9 KiB
C
Raw Normal View History

2019-05-30 12:44:56 +02:00
// The OS/K Team licenses this file to you under the MIT license.
2019-05-15 21:56:42 +02:00
// See the LICENSE file in the project root for more information.
2019-05-15 21:47:08 +02:00
2019-06-05 12:53:09 +02:00
#include <pc/arch.h>
2019-05-15 21:47:08 +02:00
2019-06-13 15:00:48 +02:00
//----------------------------------------------------------------------------//
2019-06-13 16:27:33 +02:00
#define DECV(v, p) \
2019-06-12 15:30:35 +02:00
ulong v; \
2019-06-13 16:27:33 +02:00
GETV(v, p)
#define GETV(v, p) \
2019-06-12 15:30:35 +02:00
if (ACC_FMT_IS_MEM(p->type)) \
v = readmem(ctx, p->addr, p->mlen); \
else v = p->val
2019-06-13 16:27:33 +02:00
#define DECVZX(v, p) \
2019-06-13 15:00:48 +02:00
ulong v; \
2019-06-13 16:27:33 +02:00
GETVZX(v, p)
#define GETVZX(v, p) \
2019-06-13 15:00:48 +02:00
if (ACC_FMT_IS_MEM(p->type)) \
v = readmemzx(ctx, p->addr, p->mlen); \
else v = p->val
//----------------------------------------------------------------------------//
2019-06-12 15:30:35 +02:00
2019-05-15 22:08:37 +02:00
#define IMPL_START_0(name) \
2019-07-09 21:02:26 +02:00
uint i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
2019-07-01 21:46:36 +02:00
ulong *r1, ulong *r2, ulong *r3) \
2019-05-30 20:23:27 +02:00
{
2019-05-15 22:08:37 +02:00
2019-05-15 21:47:08 +02:00
#define IMPL_START_1(name) \
2019-07-09 21:02:26 +02:00
IMPL_START_0(name) \
2019-06-13 16:27:33 +02:00
DECV(v1, p1);
2019-05-15 21:47:08 +02:00
2019-07-17 22:25:50 +02:00
#define IMPL_START_X_NOIN(name) \
2019-07-17 20:26:03 +02:00
IMPL_START_0(name) \
2019-07-17 22:25:50 +02:00
ulong v1, v2, v3; \
(void)v1; (void)v2; (void)v3;
2019-07-17 20:26:03 +02:00
2019-05-15 21:47:08 +02:00
#define IMPL_START_2(name) \
2019-07-09 21:02:26 +02:00
IMPL_START_1(name) \
2019-06-13 16:27:33 +02:00
DECV(v2, p2);
2019-05-16 16:48:45 +02:00
2019-07-04 20:33:49 +02:00
#define IMPL_START_2_ONLY(name) \
2019-07-09 21:02:26 +02:00
IMPL_START_0(name) \
ulong v1; \
2019-07-04 20:33:49 +02:00
DECV(v2, p2);
2019-07-01 21:46:36 +02:00
#define IMPL_START_3(name) \
2019-07-09 21:02:26 +02:00
IMPL_START_2(name) \
2019-07-01 21:46:36 +02:00
DECV(v3, p3);
2019-07-04 20:33:49 +02:00
//----------------------------------------------------------------------------//
#define IMPL_END \
return 0; \
}
2019-06-06 22:07:34 +02:00
2019-05-15 21:47:08 +02:00
#define IMPL_OUT \
2019-06-12 15:47:11 +02:00
*r1 = v1; \
2019-06-07 22:23:38 +02:00
return 1; \
2019-05-30 20:23:27 +02:00
}
2019-05-15 21:47:08 +02:00
2019-07-04 20:33:49 +02:00
#define IMPL_OUT_ZSF \
SET_ZSF(v1); \
IMPL_OUT
2019-06-05 22:59:32 +02:00
#define IMPL_OUT_2 \
2019-06-12 15:47:11 +02:00
*r1 = v1; \
*r2 = v2; \
return 2; \
2019-06-05 22:59:32 +02:00
}
2019-07-01 21:46:36 +02:00
#define IMPL_OUT_3 \
*r1 = v1; \
*r2 = v2; \
*r3 = v3; \
return 3; \
}
2019-07-04 20:33:49 +02:00
//----------------------------------------------------------------------------//
2019-07-17 22:25:50 +02:00
#define INTO() \
if (R(RFX) & OF) _except(ctx, E_OVF, "Overflow");
2019-07-17 20:26:03 +02:00
#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 SET_ZSPF(v) \
SET_ZF(v); \
SET_SF(v); \
SET_PF(v)
//----------------------------------------------------------------------------//
2019-07-18 22:49:31 +02:00
#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); \
2019-07-17 20:26:03 +02:00
\
if (_u1 < _u2) R(RFX) |= CF; \
else R(RFX) &= ~CF; \
\
2019-07-18 22:49:31 +02:00
if (((_u1 ^ _u3) & (_u1 ^ _u2)) >> 63) \
2019-07-17 20:26:03 +02:00
R(RFX) |= OF; \
else R(RFX) &= ~OF; \
2019-07-18 22:49:31 +02:00
\
SET_ZSF(_u3);
2019-07-17 20:26:03 +02:00
//----------------------------------------------------------------------------//
2019-05-16 16:48:45 +02:00
#define CHK_SUPERV() \
do { \
2019-07-11 18:34:21 +02:00
if ((R(CR0) & UF) > 0) { \
2019-05-16 16:48:45 +02:00
_except(ctx, E_SYS, "Supervisor-only INSTR"); \
} \
} while (0)
2019-05-15 21:47:08 +02:00
2019-06-13 15:00:48 +02:00
//----------------------------------------------------------------------------//