mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
209 lines
3.5 KiB
C
209 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 <in/instrs.h>
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(jmp, 1) { R(RIP) = p1->val; return 0; }
|
|
|
|
IMPL_START(loop, 1) {
|
|
if (R(RCX) > 0) {
|
|
R(RCX)--;
|
|
R(RIP) = p1->val;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(bch, 3)
|
|
{
|
|
SRCP(p1);
|
|
SRCP(p2);
|
|
|
|
COMPARE_SUB(p1->val, p2->val);
|
|
|
|
if (eval_cond(ctx->cond))
|
|
R(RIP) = p3->val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(cmp, 2)
|
|
{
|
|
SRCP(p1);
|
|
|
|
COMPARE_SUB(p1->val, p2->val);
|
|
|
|
return 0;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(lea, 2) { *r1 = p2->addr; return 1; }
|
|
IMPL_START(mov, 2) { XSRCP(*r1, p2, sx); return 1; }
|
|
IMPL_START(movzx, 2) { XSRCP(*r1, p2, zx); return 1; }
|
|
|
|
IMPL_START(movsxb, 2) { SRCP(p2); *r1 = (ulong)(long)(char)p2->val; return 1; }
|
|
IMPL_START(movsxw, 2) { SRCP(p2); *r1 = (ulong)(long)(short)p2->val; return 1; }
|
|
IMPL_START(movsxd, 2) { SRCP(p2); *r1 = (ulong)(long)(int)p2->val; return 1; }
|
|
|
|
IMPL_START(xchg, 2)
|
|
{
|
|
SRCP(p1);
|
|
SRCP(p2);
|
|
|
|
*r2 = p1->val;
|
|
*r1 = p2->val;
|
|
|
|
return 2;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(push, 1)
|
|
{
|
|
XSRCP(p1->val, p1, zx);
|
|
|
|
R(RSP) -= 8;
|
|
writemem(p1->val, R(RSP), 8);
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(push, 2)
|
|
{
|
|
XSRCP(p1->val, p1, zx);
|
|
XSRCP(p2->val, p2, zx);
|
|
|
|
R(RSP) -= 16;
|
|
writemem(p1->val, R(RSP) + 8, 8);
|
|
writemem(p2->val, R(RSP) + 0, 8);
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(push, 3)
|
|
{
|
|
XSRCP(p1->val, p1, zx);
|
|
XSRCP(p2->val, p2, zx);
|
|
XSRCP(p3->val, p3, zx);
|
|
|
|
R(RSP) -= 24;
|
|
writemem(p1->val, R(RSP) + 16, 8);
|
|
writemem(p2->val, R(RSP) + 8, 8);
|
|
writemem(p3->val, R(RSP) + 0, 8);
|
|
|
|
return 0;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(pop, 1)
|
|
{
|
|
*r1 = readmemzx(R(RSP), 8);
|
|
R(RSP) += 8;
|
|
|
|
return 1;
|
|
}
|
|
|
|
IMPL_START(pop, 2)
|
|
{
|
|
*r1 = readmemzx(R(RSP) + 0, 8);
|
|
*r2 = readmemzx(R(RSP) + 8, 8);
|
|
R(RSP) += 16;
|
|
|
|
return 2;
|
|
}
|
|
|
|
IMPL_START(pop, 3)
|
|
{
|
|
*r1 = readmemzx(R(RSP) + 0, 8);
|
|
*r2 = readmemzx(R(RSP) + 8, 8);
|
|
*r3 = readmemzx(R(RSP) + 16, 8);
|
|
R(RSP) += 24;
|
|
|
|
return 3;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(call, 1)
|
|
{
|
|
SRCP(p1);
|
|
|
|
R(RSP) -= 8;
|
|
writemem(R(RIP), R(RSP), 8);
|
|
R(RIP) = p1->val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(call, 2)
|
|
{
|
|
SRCP(p1);
|
|
SRCP(p2);
|
|
|
|
R(RSP) -= 8;
|
|
writemem(R(RIP), R(RSP), 8);
|
|
|
|
R(RIP) = p1->val;
|
|
R(AX0) = p2->val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(call, 3)
|
|
{
|
|
SRCP(p1);
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
R(RSP) -= 8;
|
|
writemem(R(RIP), R(RSP), 8);
|
|
|
|
R(RIP) = p1->val;
|
|
R(AX0) = p2->val;
|
|
R(AX1) = p3->val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(ret, 0)
|
|
{
|
|
R(RIP) = readmemzx(R(RSP), 8);
|
|
R(RSP) += 8;
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(enter, 0)
|
|
{
|
|
R(RSP) -= 8;
|
|
writemem(R(RBP), R(RSP), 8);
|
|
R(RBP) = R(RSP);
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(enter, 1)
|
|
{
|
|
writemem(R(RBP), R(RSP) - 8, 8);
|
|
R(RBP) = R(RSP) - 8;
|
|
R(RSP) -= (p1->val + 1) * 8;
|
|
|
|
return 0;
|
|
}
|
|
|
|
IMPL_START(leave, 0)
|
|
{
|
|
R(RSP) = R(RBP) + 8;
|
|
R(RBP) = readmemzx(R(RBP), 8);
|
|
|
|
return 0;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|