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/string.c

242 lines
4.0 KiB
C
Raw Normal View History

2019-06-13 15:32:24 +02:00
// 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 <in/instrs.h>
//----------------------------------------------------------------------------//
2019-06-13 16:27:33 +02:00
#define STR_MOVE(reg, len) \
if ((flg & DF) == 0) \
R(reg) += len; \
else \
R(reg) -= len;
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 16:27:33 +02:00
{
2019-06-17 20:59:30 +02:00
DECV(v2, p2);
2019-06-13 16:27:33 +02:00
2019-06-17 20:59:30 +02:00
writemem(ctx, v2, R(p1->reg), len);
2019-06-13 16:27:33 +02:00
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
2019-06-13 16:27:33 +02:00
}
2019-06-13 15:32:24 +02:00
IMPL_START_0(stosb)
{
2019-06-13 16:27:33 +02:00
stos_impl(ctx, p1, p2, 1);
2019-06-13 15:32:24 +02:00
}
IMPL_END;
2019-06-13 17:13:59 +02:00
IMPL_START_0(stosw)
{
stos_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(stosl)
{
stos_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(stosq)
{
stos_impl(ctx, p1, p2, 8);
}
IMPL_END;
2019-06-13 15:47:20 +02:00
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void lods_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 16:27:33 +02:00
{
2019-06-17 20:59:30 +02:00
R(p1->reg) = readmem(ctx, R(p2->reg), len);
2019-06-13 22:20:35 +02:00
2019-06-17 20:59:30 +02:00
flg = (R(p1->reg) == 0 ? flg|ZF : flg&~ZF);
2019-06-13 22:20:35 +02:00
2019-06-17 20:59:30 +02:00
STR_MOVE(p2->reg, len);
2019-06-13 16:27:33 +02:00
}
2019-06-13 15:32:24 +02:00
IMPL_START_0(lodsb)
{
2019-06-13 16:27:33 +02:00
lods_impl(ctx, p1, p2, 1);
2019-06-13 15:32:24 +02:00
}
IMPL_END;
2019-06-13 17:13:59 +02:00
IMPL_START_0(lodsw)
{
lods_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(lodsl)
{
lods_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(lodsq)
{
lods_impl(ctx, p1, p2, 8);
}
IMPL_END;
2019-06-13 15:47:20 +02:00
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void scas_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 22:20:35 +02:00
{
2019-06-17 20:59:30 +02:00
DECV(v2, p2);
2019-06-13 22:20:35 +02:00
2019-06-17 20:59:30 +02:00
ulong x = readmem(ctx, R(p1->reg), len);
COMPARE(x, v2);
2019-06-13 22:20:35 +02:00
2019-06-17 20:59:30 +02:00
if (x == 0) {
flg |= ZF;
2019-06-13 22:20:35 +02:00
}
2019-06-17 20:59:30 +02:00
else if (!(flg&ZF)) {
STR_MOVE(p1->reg, len);
2019-06-13 22:20:35 +02:00
}
}
2019-06-13 15:47:20 +02:00
IMPL_START_0(scasb)
{
2019-06-13 22:20:35 +02:00
scas_impl(ctx, p1, p2, 1);
}
IMPL_END;
IMPL_START_0(scasw)
{
scas_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(scasl)
{
scas_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(scasq)
{
scas_impl(ctx, p1, p2, 8);
2019-06-13 15:47:20 +02:00
}
IMPL_END;
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void cmps_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 22:20:35 +02:00
{
2019-06-17 20:59:30 +02:00
ulong x1 = readmem(ctx, R(p1->reg), len);
ulong x2 = readmem(ctx, R(p2->reg), len);
2019-06-13 22:20:35 +02:00
COMPARE(x1, x2);
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
STR_MOVE(p2->reg, len);
2019-06-13 22:20:35 +02:00
}
2019-06-13 15:47:20 +02:00
IMPL_START_0(cmpsb)
{
2019-06-13 22:20:35 +02:00
cmps_impl(ctx, p1, p2, 1);
}
IMPL_END;
IMPL_START_0(cmpsw)
{
cmps_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(cmpsl)
{
cmps_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(cmpsq)
{
cmps_impl(ctx, p1, p2, 8);
2019-06-13 15:47:20 +02:00
}
IMPL_END;
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void cmpzs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 22:20:35 +02:00
{
2019-06-17 20:59:30 +02:00
ulong x1 = readmem(ctx, R(p1->reg), len);
ulong x2 = readmem(ctx, R(p2->reg), len);
2019-06-13 22:20:35 +02:00
COMPARE(x1, x2);
if (!x1 && !x2)
flg &= ~ZF;
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
STR_MOVE(p2->reg, len);
2019-06-13 22:20:35 +02:00
}
IMPL_START_0(cmpzsb)
{
cmpzs_impl(ctx, p1, p2, 1);
}
IMPL_END;
2019-06-17 13:15:57 +02:00
IMPL_START_0(cmpzsw)
2019-06-13 22:20:35 +02:00
{
cmpzs_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(cmpzsl)
{
cmpzs_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(cmpzsq)
{
cmpzs_impl(ctx, p1, p2, 8);
}
IMPL_END;
//----------------------------------------------------------------------------//
2019-06-16 19:42:10 +02:00
static void movs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
2019-06-13 22:20:35 +02:00
{
2019-06-17 20:59:30 +02:00
ulong x = readmem(ctx, R(p2->reg), len);
writemem(ctx, x, R(p1->reg), len);
2019-06-13 22:20:35 +02:00
flg = (x == 0 ? flg|ZF : flg&~ZF);
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
STR_MOVE(p2->reg, len);
2019-06-13 22:20:35 +02:00
}
2019-06-13 15:32:24 +02:00
IMPL_START_0(movsb)
{
2019-06-13 22:20:35 +02:00
movs_impl(ctx, p1, p2, 1);
}
IMPL_END;
IMPL_START_0(movsw)
{
movs_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(movsl)
{
movs_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(movsq)
{
movs_impl(ctx, p1, p2, 8);
2019-06-13 15:32:24 +02:00
}
IMPL_END;
//----------------------------------------------------------------------------//