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

160 lines
3.3 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>
2019-07-02 20:57:40 +02:00
#define ABS(x) ((short)(x) < 0 ? -x : x)
2019-07-24 17:42:42 +02:00
static const char *cond_suffixes[] =
2019-06-12 15:30:35 +02:00
{
2019-06-12 15:36:52 +02:00
"-",
"c", "o", "z", "s", "p",
2019-07-22 14:41:50 +02:00
"be", "l", "le", "axz",
"bxz", "cxz",
2019-06-12 15:36:52 +02:00
"?"
2019-06-12 15:30:35 +02:00
};
2019-08-03 19:01:12 +02:00
static void dump_acc(acc_t *p);
2019-06-16 19:42:10 +02:00
2019-08-03 19:01:12 +02:00
void dump_instr(instr_t *in,
2019-06-16 19:42:10 +02:00
acc_t *p1,
acc_t *p2,
2019-07-01 21:46:36 +02:00
acc_t *p3,
2019-06-16 19:42:10 +02:00
bool lock,
2019-07-02 20:13:05 +02:00
bool rep)
2019-06-16 19:42:10 +02:00
{
2019-07-02 20:13:05 +02:00
uint cond = ctx->cond;
2019-06-23 12:40:18 +02:00
2019-07-24 16:52:26 +02:00
trace("0x%lX:\t", ctx->cur_pc);
2019-06-16 19:42:10 +02:00
if (lock)
2019-06-19 21:41:22 +02:00
trace("lock");
2019-06-16 19:42:10 +02:00
2019-06-19 21:41:22 +02:00
trace("%s", in->name);
2019-06-16 19:44:34 +02:00
2019-06-16 19:42:10 +02:00
if (rep)
2019-06-19 21:41:22 +02:00
trace(".rep");
2019-06-16 19:42:10 +02:00
if (cond)
{
2019-06-19 21:41:22 +02:00
trace(".");
2019-06-16 19:42:10 +02:00
if (cond & (1 << 4))
2019-06-19 21:41:22 +02:00
trace("n");
2019-06-16 19:42:10 +02:00
2019-07-08 17:48:45 +02:00
assert((cond & ~(1 << 4)) <= sizeof(cond_suffixes)/sizeof(char *));
2019-06-16 19:42:10 +02:00
2019-07-08 17:48:45 +02:00
trace("%s", cond_suffixes[cond & ~(1 << 4)]);
2019-06-16 19:42:10 +02:00
}
2019-07-08 17:48:45 +02:00
if (!rep && cond != ((1 << 4) | CD_CXZ))
trace("\t\t");
2019-06-16 19:42:10 +02:00
else
2019-06-19 21:41:22 +02:00
trace("\t");
2019-06-16 19:42:10 +02:00
2019-06-16 19:52:32 +02:00
if (p1)
2019-08-03 19:01:12 +02:00
dump_acc(p1);
2019-07-01 21:46:36 +02:00
if (p2) {
trace(", ");
2019-08-03 19:01:12 +02:00
dump_acc(p2);
2019-07-01 21:46:36 +02:00
}
if (p3) {
trace(", ");
2019-08-03 19:01:12 +02:00
dump_acc(p3);
2019-06-16 19:44:34 +02:00
}
2019-06-16 19:42:10 +02:00
2019-06-19 21:41:22 +02:00
trace("\n");
2019-06-16 19:42:10 +02:00
}
2019-08-03 19:01:12 +02:00
static void dump_acc(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)
2019-06-19 21:41:22 +02:00
trace("%s", ctx->r[p->reg].name);
2019-06-12 15:30:35 +02:00
else if (p->type == A_IMM64)
2019-07-24 16:52:26 +02:00
{
if (p->val < 0xA) trace("%lu", p->val);
else trace("0x%lX", p->val);
}
else if (p->type == A_IMM32)
2019-06-14 16:47:01 +02:00
{
if (p->val < 0xA)
2019-06-19 21:41:22 +02:00
trace("%lu", p->val);
2019-06-14 16:47:01 +02:00
else
2019-06-19 13:47:10 +02:00
{
sym = find_sym_by_addr(p->val);
if (sym)
2019-06-19 21:41:22 +02:00
trace("$%s(0x%lX)", sym->name, sym->addr);
2019-06-19 13:47:10 +02:00
else
2019-06-19 21:41:22 +02:00
trace("0x%lX", p->val);
2019-06-19 13:47:10 +02:00
}
2019-06-14 16:47:01 +02:00
}
2019-06-12 15:30:35 +02:00
2019-07-24 16:52:26 +02:00
else if (p->type == A_IMM16)
{
if (p->val < 0xA) trace("%lu", p->val);
else trace("0x%hX", (ushort)p->val);
}
else if (p->type == A_IMM8)
{
if (p->val < 0xA) trace("%lu", p->val);
else trace("0x%hhX", (uchar)p->val);
}
2019-06-12 15:30:35 +02:00
else
{
2019-06-19 21:41:22 +02:00
trace("%c[", getmempref(p->mlen));
2019-06-12 15:30:35 +02:00
2019-07-24 16:52:26 +02:00
mfmt = p->type;
2019-06-14 16:47:01 +02:00
2019-07-24 16:52:26 +02:00
if (mfmt == AM_RR)
2019-06-12 15:30:35 +02:00
{
if (p->reg1 && p->reg2)
2019-06-19 21:41:22 +02:00
trace("%s+%s]", ctx->r[p->reg1].name, ctx->r[p->reg2].name);
2019-06-12 15:30:35 +02:00
2019-06-19 21:41:22 +02:00
else trace("%s]", ctx->r[p->reg1 ? p->reg1 : p->reg2].name);
2019-06-12 15:30:35 +02:00
}
else if (mfmt == AM_RRI)
{
if (p->reg1 && p->reg2)
2019-07-24 16:52:26 +02:00
trace("%s+%s%c%ld]",
2019-07-02 20:57:40 +02:00
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
2019-07-24 16:52:26 +02:00
(p->imm2 < 0 ? '-' : '+'),
2019-07-02 20:57:40 +02:00
ABS(p->imm2));
2019-07-24 16:52:26 +02:00
else trace("%s%c%ld]",
2019-07-02 20:57:40 +02:00
ctx->r[p->reg1 ? p->reg1 : p->reg2].name,
2019-07-24 16:52:26 +02:00
(p->imm2 < 0 ? '-' : '+'),
2019-07-02 20:57:40 +02:00
ABS(p->imm2));
2019-06-12 15:30:35 +02:00
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
2019-07-24 16:52:26 +02:00
trace("%s+%s*%hhd%c%ld]",
2019-06-12 15:30:35 +02:00
ctx->r[p->reg1].name,
2019-07-02 20:57:40 +02:00
ctx->r[p->reg2].name, p->imm1,
2019-07-24 16:52:26 +02:00
(p->imm2 < 0 ? '-' : '+'),
2019-07-02 20:57:40 +02:00
ABS(p->imm2));
2019-06-12 15:30:35 +02:00
else
2019-07-24 16:52:26 +02:00
trace("%s*%hhd%c%ld]",
2019-07-02 20:57:40 +02:00
ctx->r[p->reg2].name, p->imm1,
2019-07-24 16:52:26 +02:00
(p->imm2 < 0 ? '-' : '+'),
2019-07-02 20:57:40 +02:00
ABS(p->imm2));
2019-06-12 15:30:35 +02:00
}
}
}