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

att style for the lol

This commit is contained in:
julianb0 2019-06-16 19:42:10 +02:00
parent 88f1606927
commit 791e52dafd
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
4 changed files with 160 additions and 68 deletions

View File

@ -5,7 +5,10 @@
; Main function
;
main:
jmp bswap_test
call bswap_test
call str_test
call itoa_test
call movzx_test
bswap_test:
mov rdx, 0x1122334455667788
@ -20,10 +23,10 @@ bswap_test:
ret
ramdev_test:
call DevGetMemOff
call MEM.GetMemOff
mov rdx, rax
call DevGetMemSize
call MEM.GetMemSize
ret
stosb_test:

View File

@ -13,7 +13,7 @@
//----------------------------------------------------------------------------//
void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg, val;
@ -65,7 +65,7 @@ IMPL_END;
//----------------------------------------------------------------------------//
void lods_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void lods_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg1, reg2;
@ -117,7 +117,7 @@ IMPL_END;
//----------------------------------------------------------------------------//
void scas_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void scas_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg, val;
@ -170,7 +170,7 @@ IMPL_END;
//----------------------------------------------------------------------------//
void cmps_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void cmps_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg1, reg2;
@ -224,7 +224,7 @@ IMPL_END;
//----------------------------------------------------------------------------//
void cmpzs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void cmpzs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg1, reg2;
@ -281,7 +281,7 @@ IMPL_END;
//----------------------------------------------------------------------------//
void movs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
static void movs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong reg1, reg2;

View File

@ -13,62 +13,10 @@ char *cond_suffixes[] =
"?"
};
static void dump_acc(ctx_t *ctx, acc_t *p)
{
uint mfmt;
// Comment the following line to get back intel syntax
#define _ATT_STYLE 1
if (p->type == A_REG)
log("%s", ctx->r[p->reg].name);
else if (p->type == A_IMM64)
{
if (p->val < 0xA)
log("%lu", p->val);
else
log("0x%lX", p->val);
}
else
{
log("%c[", getmempref(p->mlen));
mfmt = p->type & AM_MFMT_MASK;
if (mfmt == AM_IMM64)
log("0x%lX]", p->addr);
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)
log("%s+%s+%hd]", ctx->r[p->reg1].name,
ctx->r[p->reg2].name, p->imm2);
else log("%s+%d]", ctx->r[p->reg1 ? p->reg1 : p->reg2].name, p->imm2);
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
log("%s+%s*%u+%hd]",
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
p->imm1, p->imm2);
else
log("%s*%u+%hd]",
ctx->r[p->reg2].name,
p->imm1, p->imm2);
}
}
}
static void dump_acc(ctx_t *ctx, acc_t *p);
void dump_instr(ctx_t *ctx,
instr_t *in,
@ -108,8 +56,9 @@ void dump_instr(ctx_t *ctx,
else
log("\t");
#ifndef _ATT_STYLE
log("%s\t", in->name);
if (p1) {
dump_acc(ctx, p1);
@ -119,6 +68,147 @@ void dump_instr(ctx_t *ctx,
}
}
#else
char s1[2] = {0, 0}, s2[2] = {0, 0};
if (p1 && ACC_IS_MEM(p1))
s1[0] = getmempref(p1->mlen);
if (p2 && ACC_IS_MEM(p2))
s2[0] = getmempref(p2->mlen);
log("%s%s%s\t", in->name, s1, s2);
if (p1) {
if (p2) {
dump_acc(ctx, p2);
log(", ");
}
dump_acc(ctx, p1);
}
#endif
log("\n");
}
#ifndef _ATT_STYLE
void dump_acc(ctx_t *ctx, acc_t *p)
{
uint mfmt;
if (p->type == A_REG)
log("%s", ctx->r[p->reg].name);
else if (p->type == A_IMM64)
{
if (p->val < 0xA)
log("%lu", p->val);
else
log("0x%lX", p->val);
}
else
{
log("%c[", getmempref(p->mlen));
mfmt = p->type & AM_MFMT_MASK;
if (mfmt == AM_IMM64)
log("0x%lX]", p->addr);
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)
log("%s+%s+%hd]", ctx->r[p->reg1].name,
ctx->r[p->reg2].name, p->imm2);
else log("%s+%hd]",
ctx->r[p->reg1 ? p->reg1 : p->reg2].name, p->imm2);
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
log("%s+%s*%u+%hd]",
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
p->imm1, p->imm2);
else
log("%s*%u+%hd]",
ctx->r[p->reg2].name,
p->imm1, p->imm2);
}
}
}
#else
void dump_acc(ctx_t *ctx, acc_t *p)
{
uint mfmt;
if (p->type == A_REG)
log("%%%s", ctx->r[p->reg].name);
else if (p->type == A_IMM64)
{
if (p->val < 0xA)
log("$%lu", p->val);
else
log("$0x%lX", p->val);
}
else
{
mfmt = p->type & AM_MFMT_MASK;
if (mfmt == AM_IMM64)
log("($0x%lX)", p->addr);
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)
log("%hd(%%%s,%%%s)", p->imm2, ctx->r[p->reg1].name,
ctx->r[p->reg2].name);
else log("%hd(%%%s)", p->imm2,
ctx->r[p->reg1 ? p->reg1 : p->reg2].name);
}
else if (mfmt == AM_RRII)
{
if (p->reg1)
log("%hd(%s,%s,$%u)", p->imm2,
ctx->r[p->reg1].name,
ctx->r[p->reg2].name,
p->imm1);
else
log("%hd(*,%s,$%u)", p->imm2,
ctx->r[p->reg2].name,
p->imm1);
}
}
}
#endif

View File

@ -68,8 +68,6 @@ int main(int argc, char **argv)
main_ctx.r = arch_r;
main_ctx.i = arch_i;
disable_stdin_echoing();
//
// srand
@ -87,7 +85,6 @@ int main(int argc, char **argv)
//
// Load program
//
if (argc < 2) {
log("Not enough arguments\n");
exit(-3);
@ -133,6 +130,8 @@ int main(int argc, char **argv)
exit(-10);
}
disable_stdin_echoing();
while (1) {
decode(&main_ctx);