aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--main.c17
2 files changed, 9 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0369c31..ce41752 100644
--- a/README.md
+++ b/README.md
@@ -68,5 +68,6 @@ Bonus features:
- [intel reference](https://software.intel.com/content/dam/develop/external/us/en/documents-tps/325383-sdm-vol-2abcd.pdf) - Specifically chapter 2.1 and chapter 3.1.
- [elf spec](https://refspecs.linuxfoundation.org/elf/elf.pdf)
+- [osdev wiki](https://wiki.osdev.org/X86-64_Instruction_Encoding)
- [goas](https://github.com/DQNEO/goas)
- [neatas](https://repo.or.cz/neatas.git)
diff --git a/main.c b/main.c
index 9ad714b..212e320 100644
--- a/main.c
+++ b/main.c
@@ -207,15 +207,7 @@ static uint8_t regbits(AsmKind k) { return (k - (ASM_REG_BEGIN + 1)) % 16; }
static uint8_t isreg64(AsmKind k) { return k >= ASM_RAX && k <= ASM_R15; }
-/* Register that requires the use of a rex prefix. */
-static uint8_t isrexreg(AsmKind k) {
- return k > ASM_REG_BEGIN && k < ASM_REG_END &&
- (regbits(k) & (1 << 3) || k == ASM_SPL || k == ASM_BPL ||
- k == ASM_SIL || k == ASM_DIL);
-}
-
-/* Compose a rex prefix - See intel manual. */
-
+/* Rex opcode prefix. */
typedef struct Rex {
uint8_t required : 1;
uint8_t w : 1;
@@ -224,6 +216,13 @@ typedef struct Rex {
uint8_t b : 1;
} Rex;
+/* Register that requires the use of a rex prefix. */
+static uint8_t isrexreg(AsmKind k) {
+ return k > ASM_REG_BEGIN && k < ASM_REG_END &&
+ (regbits(k) & (1 << 3) || k == ASM_SPL || k == ASM_BPL ||
+ k == ASM_SIL || k == ASM_DIL);
+}
+
static uint8_t rexbyte(Rex rex) {
return ((1 << 6) | (rex.w << 3) | (rex.r << 2) | (rex.x << 1) | rex.b);
}