1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00

it's a trap!

This commit is contained in:
julianb0 2019-07-09 21:02:26 +02:00
parent e6d0c9ec20
commit 622fcdfde7
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
6 changed files with 29 additions and 71 deletions

View File

@ -13,7 +13,6 @@
GETV(v, p) GETV(v, p)
#define GETV(v, p) \ #define GETV(v, p) \
assert(p); \
if (ACC_FMT_IS_MEM(p->type)) \ if (ACC_FMT_IS_MEM(p->type)) \
v = readmem(ctx, p->addr, p->mlen); \ v = readmem(ctx, p->addr, p->mlen); \
else v = p->val else v = p->val
@ -23,7 +22,6 @@
GETVZX(v, p) GETVZX(v, p)
#define GETVZX(v, p) \ #define GETVZX(v, p) \
assert(p); \
if (ACC_FMT_IS_MEM(p->type)) \ if (ACC_FMT_IS_MEM(p->type)) \
v = readmemzx(ctx, p->addr, p->mlen); \ v = readmemzx(ctx, p->addr, p->mlen); \
else v = p->val else v = p->val
@ -31,36 +29,25 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#define IMPL_START_0(name) \ #define IMPL_START_0(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \ uint i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \
ulong *r1, ulong *r2, ulong *r3) \ ulong *r1, ulong *r2, ulong *r3) \
{ {
#define IMPL_START_1(name) \ #define IMPL_START_1(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \ IMPL_START_0(name) \
ulong *r1, ulong *r2, ulong *r3) \
{ \
DECV(v1, p1); DECV(v1, p1);
#define IMPL_START_2(name) \ #define IMPL_START_2(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \ IMPL_START_1(name) \
ulong *r1, ulong *r2, ulong *r3) \
{ \
DECV(v1, p1); \
DECV(v2, p2); DECV(v2, p2);
#define IMPL_START_2_ONLY(name) \ #define IMPL_START_2_ONLY(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \ IMPL_START_0(name) \
ulong *r1, ulong *r2, ulong *r3) \ ulong v1; \
{ \
ulong v1; (void)v1; \
DECV(v2, p2); DECV(v2, p2);
#define IMPL_START_3(name) \ #define IMPL_START_3(name) \
bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, acc_t *p3, \ IMPL_START_2(name) \
ulong *r1, ulong *r2, ulong *r3) \
{ \
DECV(v1, p1); \
DECV(v2, p2); \
DECV(v3, p3); DECV(v3, p3);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -77,7 +77,7 @@ struct instr_t
uint prm2; uint prm2;
uint prm3; uint prm3;
bool (*func)(ctx_t *, acc_t *, acc_t *, acc_t *, uint (*func)(ctx_t *, acc_t *, acc_t *, acc_t *,
ulong *, ulong *, ulong *); ulong *, ulong *, ulong *);
}; };

View File

@ -12,15 +12,15 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
uint code = _code; uint code = _code;
uint effcode; uint effcode;
ulong orig_frame, orig_rpc, orig_rip; ulong orig_frame;
logerr("\nException %u - ", code); trace("\nException %u - ", code);
va_start(ap, fmt); va_start(ap, fmt);
vlog(fmt, ap); vlog(fmt, ap);
va_end(ap); va_end(ap);
logerr("\n\n"); trace("\n\n");
// //
// Interrupted earlier? // Interrupted earlier?
@ -44,7 +44,7 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
if (code == E_DBF) if (code == E_DBF)
effcode = E_DBF; effcode = E_DBF;
if (code < 512) else if (code < 512)
effcode = 0; effcode = 0;
else if (code < 768) else if (code < 768)
@ -83,8 +83,6 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
if (rfs[handler] != NULL) if (rfs[handler] != NULL)
{ {
orig_frame = rfs_current_idx; orig_frame = rfs_current_idx;
orig_rpc = rpc;
orig_rip = rip;
ctx->rf = rfs[handler]; ctx->rf = rfs[handler];
rfs_current_idx = handler; rfs_current_idx = handler;
@ -94,8 +92,6 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
R(R11) = effcode; R(R11) = effcode;
R(R12) = orig_frame; R(R12) = orig_frame;
R(R13) = rip; R(R13) = rip;
R(R14) = orig_rpc;
R(R15) = orig_rip;
idt_handling[effcode]++; idt_handling[effcode]++;

View File

@ -53,7 +53,7 @@ void exec_instr(ctx_t *ctx,
bool lock, bool lock,
bool rep) bool rep)
{ {
bool out; uint out;
ulong r1 = 0, r2 = 0, r3 = 0; ulong r1 = 0, r2 = 0, r3 = 0;
// Global instruction counter // Global instruction counter
@ -78,49 +78,22 @@ do_rep:
out = in->func(ctx, p1, p2, p3, &r1, &r2, &r3); out = in->func(ctx, p1, p2, p3, &r1, &r2, &r3);
#define OUTPUT(p, r) { \
if (p->type == A_REG) \
R(p->reg) = r1; \
else if (p1->type == A_IMM64) \
_except(ctx, E_ACC, "Trying to output to an IMM64"); \
else { \
assert(ACC_IS_MEM(p)); \
writemem(ctx, r, p->addr, p->mlen); \
} }
if (out) if (out)
{ {
if (p1->type == A_REG) OUTPUT(p1, r1);
R(p1->reg) = r1; if (out >= 2) OUTPUT(p2, r2);
if (out >= 3) OUTPUT(p3, r3);
else if (p1->type == A_IMM64)
_except(ctx, E_ACC, "Trying to output to an IMM64");
else
{
assert(ACC_IS_MEM(p1));
writemem(ctx, r1, p1->addr, p1->mlen);
}
}
if (out >= 2)
{
if (p2->type == A_REG)
R(p2->reg) = r2;
else if (p2->type == A_IMM64)
_except(ctx, E_ACC, "Trying to output to an IMM64");
else
{
assert(ACC_IS_MEM(p2));
writemem(ctx, r2, p2->addr, p2->mlen);
}
}
if (out >= 3)
{
if (p3->type == A_REG)
R(p3->reg) = r3;
else if (p3->type == A_IMM64)
_except(ctx, E_ACC, "Trying to output to an IMM64");
else
{
assert(ACC_IS_MEM(p3));
writemem(ctx, r3, p3->addr, p3->mlen);
}
} }
if (rep) if (rep)

View File

@ -25,6 +25,6 @@ void logerr(const char *fmt, ...)
void vlog(const char *fmt, va_list ap) void vlog(const char *fmt, va_list ap)
{ {
vfprintf(stderr, fmt, ap); vfprintf(stdout, fmt, ap);
} }

View File

@ -55,6 +55,8 @@ jmp_buf exc_jmp_buf;
// //
void main_loop(void) void main_loop(void)
{ {
trace("\n\n\n");
setjmp(exc_jmp_buf); setjmp(exc_jmp_buf);
// //