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/pc/dump.c
julianb0 6f59eebedb
vm
2019-07-01 21:46:36 +02:00

147 lines
2.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>
char *cond_suffixes[] =
{
"-",
"c", "o", "z", "s", "p",
"a", "ae", "b", "be",
"g", "ge", "l", "le",
"cxz",
"?"
};
#ifndef _ATT_STYLE
#define _ATT_STYLE 0
#endif
void dump_acc(ctx_t *ctx, acc_t *p);
void dump_instr(ctx_t *ctx,
instr_t *in,
acc_t *p1,
acc_t *p2,
acc_t *p3,
bool lock,
bool rep,
uint cond)
{
/*
trace("%03lu 0x%lX:\t", ctx->ninstrs, pc);
*/
trace("0x%lX:\t", rpc);
if (lock)
trace("lock");
trace("%s", in->name);
if (rep)
trace(".rep");
if (cond)
{
trace(".");
if (cond & (1 << 4))
{
cond &= ~(1 << 4);
trace("n");
}
assert(cond <= sizeof(cond_suffixes)/sizeof(char *));
trace("%s", cond_suffixes[cond]);
}
if (!rep) trace("\t\t");
else
trace("\t");
if (p1)
dump_acc(ctx, p1);
if (p2) {
trace(", ");
dump_acc(ctx, p2);
}
if (p3) {
trace(", ");
dump_acc(ctx, p3);
}
trace("\n");
}
void dump_acc(ctx_t *ctx, acc_t *p)
{
uint mfmt;
sym_t *sym;
if (p->type == A_REG)
trace("%s", ctx->r[p->reg].name);
else if (p->type == A_IMM64)
{
if (p->val < 0xA)
trace("%lu", p->val);
else
{
sym = find_sym_by_addr(p->val);
if (sym)
trace("$%s(0x%lX)", sym->name, sym->addr);
else
trace("0x%lX", p->val);
}
}
else
{
trace("%c[", getmempref(p->mlen));
mfmt = p->type & AM_MFMT_MASK;
if (mfmt == AM_IMM64)
trace("0x%lX]", p->addr);
else if (mfmt == AM_RR)
{
if (p->reg1 && p->reg2)
trace("%s+%s]", ctx->r[p->reg1].name, ctx->r[p->reg2].name);
else trace("%s]", ctx->r[p->reg1 ? p->reg1 : p->reg2].name);
}
else if (mfmt == AM_RRI)
{
if (p->reg1 && p->reg2)
trace("%s+%s+%hd]", ctx->r[p->reg1].name,
ctx->r[p->reg2].name, p->imm2);
else trace("%s+%hd]",
ctx->r[p->reg1 ? p->reg1 : p->reg2].name, p->imm2);
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
trace("%s+%s*%u+%hd]",
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
p->imm1, p->imm2);
else
trace("%s*%u+%hd]",
ctx->r[p->reg2].name,
p->imm1, p->imm2);
}
}
}