aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm.peg12
-rw-r--r--main.c8
-rw-r--r--minias.h2
-rw-r--r--parse.c6
4 files changed, 15 insertions, 13 deletions
diff --git a/asm.peg b/asm.peg
index a284c1b..e922a83 100644
--- a/asm.peg
+++ b/asm.peg
@@ -140,7 +140,7 @@ call = "call" 'q'? ws (
)
jmp = 'j' v:jmp-variant ws t:ident
- { $$.jmp = (Jmp) {.kind = ASM_JMP, .variant=v.i64, .target=t.charptr}; }
+ { $$.jmp = (Jmp) {.kind = ASM_JMP, .cc=v.i64, .target=t.charptr}; }
jmp-variant =
"mp" { $$.i64 = 0; }
@@ -550,7 +550,15 @@ xchg = "xchg" (
| 'l'? ws s:mem ws? ',' ws? d:r32 { $$ = MEMREG(-1, (Rex){0}, 0x87, s, d); }
| 'q'? ws s:mem ws? ',' ws? d:r64 { $$ = MEMREG(-1, (Rex){.w=1}, 0x87, s, d); }
)
-
+
+%{
+ static uint8_t cc2setop[30] = {
+ 0x94, 0x98, 0x9b, 0x9a, 0x9a, 0x90, 0x95, 0x99, 0x9b, 0x91,
+ 0x9f, 0x9d, 0x9c, 0x9e, 0x95, 0x93, 0x97, 0x93, 0x92, 0x96,
+ 0x9e, 0x9c, 0x9d, 0x9f, 0x94, 0x92, 0x96, 0x92, 0x93, 0x97,
+ };
+%}
+
set = "set" cc:condition-code (
'b'? ws a:r8 { $$ = OPREG(-1, (Rex){0}, 0x01000f00 | cc2setop[cc.i64], 0x00, a) }
| 'b'? ws a:mem { $$ = OPMEM(-1, (Rex){0}, 0x01000f00 | cc2setop[cc.i64], 0x00, a) }
diff --git a/main.c b/main.c
index 3dbf693..3bd0e47 100644
--- a/main.c
+++ b/main.c
@@ -459,7 +459,7 @@ static void assemblejmp(const Jmp *j) {
int64_t distance;
Symbol *target;
- static uint8_t variant2op[31] = {
+ static uint8_t cc2op[31] = {
0xe9, 0x84, 0x88, 0x8b, 0x8a, 0x8a, 0x80, 0x85, 0x89, 0x8b, 0x81,
0x8f, 0x8d, 0x8c, 0x8e, 0x85, 0x83, 0x87, 0x83, 0x82, 0x86, 0x8e,
0x8c, 0x8d, 0x8f, 0x84, 0x82, 0x86, 0x82, 0x83, 0x87,
@@ -481,12 +481,12 @@ static void assemblejmp(const Jmp *j) {
}
if (jmpsize == 4) {
- if (j->variant)
+ if (j->cc)
sb(0x0f);
- sb(variant2op[j->variant]);
+ sb(cc2op[j->cc]);
assemblereloc(j->target, -4, 4, R_X86_64_PC32);
} else {
- sb(variant2op[j->variant] + (j->variant ? -16 : 2));
+ sb(cc2op[j->cc] + (j->cc ? -16 : 2));
assemblereloc(j->target, -1, 1, R_X86_64_PC8);
}
}
diff --git a/minias.h b/minias.h
index de9542b..b1f0d86 100644
--- a/minias.h
+++ b/minias.h
@@ -248,7 +248,7 @@ typedef struct Call {
typedef struct Jmp {
AsmKind kind;
- uint32_t variant;
+ uint32_t cc; /* 0 means unconditional. */
const char *target;
} Jmp;
diff --git a/parse.c b/parse.c
index 8699384..3be60a2 100644
--- a/parse.c
+++ b/parse.c
@@ -222,12 +222,6 @@ static int needsmovabs(Imm *imm) {
#define REG(K) \
(Parsev) { .kind = ASM_##K }
-static uint8_t cc2setop[30] = {
- 0x94, 0x98, 0x9b, 0x9a, 0x9a, 0x90, 0x95, 0x99, 0x9b, 0x91,
- 0x9f, 0x9d, 0x9c, 0x9e, 0x95, 0x93, 0x97, 0x93, 0x92, 0x96,
- 0x9e, 0x9c, 0x9d, 0x9f, 0x94, 0x92, 0x96, 0x92, 0x93, 0x97,
-};
-
#define YYSTYPE Parsev
#define YY_CTX_LOCAL
#define YY_CTX_MEMBERS Parsev v;