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

139 lines
2.7 KiB
C
Raw Normal View History

2019-06-12 15:30:35 +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 <pc/arch.h>
char *cond_suffixes[] =
{
2019-06-12 15:36:52 +02:00
"-",
"c", "o", "z", "s", "p",
"a", "ae", "b", "be",
"g", "ge", "l", "le",
"cxz",
"?"
2019-06-12 15:30:35 +02:00
};
2019-06-16 19:52:32 +02:00
#ifndef _ATT_STYLE
2019-06-17 13:15:57 +02:00
#define _ATT_STYLE 0
2019-06-16 19:52:32 +02:00
#endif
2019-06-16 19:42:10 +02:00
static void dump_acc(ctx_t *ctx, acc_t *p);
void dump_instr(ctx_t *ctx,
instr_t *in,
acc_t *p1,
acc_t *p2,
bool lock,
bool rep,
uint cond,
ulong pc)
{
2019-06-16 19:47:17 +02:00
log("0x%lX:\t", pc);
2019-06-16 19:42:10 +02:00
if (lock)
log("lock");
2019-06-16 19:47:17 +02:00
log("%s", in->name);
2019-06-16 19:44:34 +02:00
2019-06-16 19:42:10 +02:00
if (rep)
2019-06-16 19:44:34 +02:00
log(".rep");
2019-06-16 19:42:10 +02:00
if (cond)
{
log(".");
if (cond & (1 << 4))
{
cond &= ~(1 << 4);
log("n");
}
assert(cond <= sizeof(cond_suffixes)/sizeof(char *));
log("%s", cond_suffixes[cond]);
}
2019-06-19 13:47:10 +02:00
if (!rep) log("\t\t");
2019-06-16 19:42:10 +02:00
else
log("\t");
2019-06-16 19:52:32 +02:00
if (p1)
{
2019-06-16 19:42:10 +02:00
dump_acc(ctx, p1);
if (p2) {
log(", ");
dump_acc(ctx, p2);
}
2019-06-16 19:44:34 +02:00
}
2019-06-16 19:42:10 +02:00
log("\n");
}
void dump_acc(ctx_t *ctx, acc_t *p)
2019-06-12 15:30:35 +02:00
{
uint mfmt;
2019-06-19 13:47:10 +02:00
sym_t *sym;
2019-06-12 15:30:35 +02:00
if (p->type == A_REG)
log("%s", ctx->r[p->reg].name);
else if (p->type == A_IMM64)
2019-06-14 16:47:01 +02:00
{
if (p->val < 0xA)
log("%lu", p->val);
else
2019-06-19 13:47:10 +02:00
{
sym = find_sym_by_addr(p->val);
if (sym)
log("$%s(0x%lX)", sym->name, sym->addr);
else
log("0x%lX", p->val);
}
2019-06-14 16:47:01 +02:00
}
2019-06-12 15:30:35 +02:00
else
{
log("%c[", getmempref(p->mlen));
mfmt = p->type & AM_MFMT_MASK;
if (mfmt == AM_IMM64)
log("0x%lX]", p->addr);
2019-06-14 16:47:01 +02:00
2019-06-12 15:30:35 +02:00
else if (mfmt == AM_RR)
{
if (p->reg1 && p->reg2)
log("%s+%s]", ctx->r[p->reg1].name, ctx->r[p->reg2].name);
else log("%s]", ctx->r[p->reg1 ? p->reg1 : p->reg2].name);
}
else if (mfmt == AM_RRI)
{
if (p->reg1 && p->reg2)
2019-06-12 15:58:57 +02:00
log("%s+%s+%hd]", ctx->r[p->reg1].name,
ctx->r[p->reg2].name, p->imm2);
2019-06-12 15:30:35 +02:00
2019-06-16 19:42:10 +02:00
else log("%s+%hd]",
ctx->r[p->reg1 ? p->reg1 : p->reg2].name, p->imm2);
2019-06-12 15:30:35 +02:00
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
2019-06-12 15:58:57 +02:00
log("%s+%s*%u+%hd]",
2019-06-12 15:30:35 +02:00
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
p->imm1, p->imm2);
else
2019-06-12 15:58:57 +02:00
log("%s*%u+%hd]",
2019-06-12 15:30:35 +02:00
ctx->r[p->reg2].name,
p->imm1, p->imm2);
}
}
}