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

86 lines
1.8 KiB
C
Raw Normal View History

2019-05-16 16:48:45 +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.
2019-06-05 12:53:09 +02:00
#include <pc/arch.h>
2019-05-16 16:48:45 +02:00
void dumpmem(ctx_t *ctx, ulong start, ulong size)
{
uint i;
for (i = 0; i < size/sizeof(ushort); i++) {
if (i % 4 == 0) {
if (i > 0) {
if (i % 8 == 0) log("\n");
else log(" ");
}
log("[0x%08lX]=0x", start + i * 2);
}
log("%04hX", ctx->mp[addr2real(start) + i]);
}
log("\n");
}
void dumpfwstack(ctx_t *ctx)
{
2019-05-16 17:14:37 +02:00
//log("\nFirmware stack:\n");
//dumpmem(ctx, FWSTACK - 128, 128 + 64);
2019-05-16 16:48:45 +02:00
}
2019-05-16 21:42:23 +02:00
void d_log(ctx_t *ctx, char *fmt, ...)
{
va_list ap;
2019-05-30 12:44:56 +02:00
2019-05-16 21:42:23 +02:00
va_start(ap, fmt);
2019-05-30 12:44:56 +02:00
2019-05-16 21:42:23 +02:00
if (ctx->disf) {
vfprintf(ctx->disf, fmt, ap);
fflush(ctx->disf);
}
else
vlog(fmt, ap);
2019-05-30 12:44:56 +02:00
2019-05-16 21:42:23 +02:00
va_end(ap);
}
2019-06-02 16:33:28 +02:00
void dumpinstr(ctx_t *ctx, ulong _rip, uint rep,
2019-05-29 16:57:22 +02:00
ushort c, acc_t *p1, acc_t *p2)
2019-05-16 16:48:45 +02:00
{
acc_t *p = 0;
instr_t *i = &ctx->i[c];
2019-05-16 21:42:23 +02:00
2019-06-02 16:33:28 +02:00
d_log(ctx, "0x%08lX: %s%s", _rip,
2019-05-29 16:57:22 +02:00
(rep ? "rep " : ""),
i->name);
2019-05-30 12:44:56 +02:00
2019-05-16 16:48:45 +02:00
if (i->prm1 != NOPRM)
p = p1;
lp:
if (p != 0) {
2019-06-06 15:06:34 +02:00
if (p->mem) d_log(ctx, " %c[", getmempref(p->mlen));
2019-05-16 21:42:23 +02:00
else d_log(ctx, " ");
2019-05-30 12:44:56 +02:00
2019-05-16 16:48:45 +02:00
if (p->type == A_REG)
2019-05-16 21:42:23 +02:00
d_log(ctx, "%s", ctx->r[p->val].name);
2019-05-16 16:48:45 +02:00
else
2019-06-06 15:06:34 +02:00
d_log(ctx, "%c0x%lX", getmempref(p->ilen), p->val);
2019-05-30 12:44:56 +02:00
2019-05-16 16:48:45 +02:00
if (p->mem) {
2019-06-06 15:06:34 +02:00
if (p->offreg)
d_log(ctx, "+%s", ctx->r[p->offreg].name);
2019-05-16 16:48:45 +02:00
if (p->off)
2019-05-16 21:42:23 +02:00
d_log(ctx, "+%hd", p->off);
d_log(ctx, "]");
2019-05-16 16:48:45 +02:00
}
if (p == p1 && i->prm2 != NOPRM) {
p = p2;
2019-05-16 21:42:23 +02:00
d_log(ctx, ",");
2019-05-16 16:48:45 +02:00
goto lp;
}
}
2019-05-16 21:42:23 +02:00
d_log(ctx, "\n");
2019-05-16 16:48:45 +02:00
}