diff options
| author | Andrew Chambers <[email protected]> | 2021-10-09 18:22:43 +1300 |
|---|---|---|
| committer | Andrew Chambers <[email protected]> | 2021-10-09 18:22:43 +1300 |
| commit | a439d4004379cc73dd6b2bf330130733396f9d61 (patch) | |
| tree | b62315e59ea9f7dfaab7156ffa1ffab8ab0855e3 /main.c | |
| parent | f72806dec51ef5ffcf2883566b070c8508ebf30a (diff) | |
More tests.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -307,20 +307,7 @@ static void assembleplusr(uint8_t opcode, uint8_t rexw, AsmKind reg) { sb(opcode | (bits & 7)); } -/* Assemble a symbolic value. */ -static void assemblereloc(const char *l, int64_t c, int nbytes, int type) { - Relocation *reloc; - Symbol *sym; - - if (l != NULL) { - reloc = newreloc(); - sym = getsym(l); - reloc->type = type; - reloc->section = cursection; - reloc->sym = sym; - reloc->offset = cursection->hdr.sh_size; - } - +void assembleconstant(int64_t c, int nbytes) { switch (nbytes) { case 1: sb((uint8_t)c); @@ -332,24 +319,46 @@ static void assemblereloc(const char *l, int64_t c, int nbytes, int type) { su32((uint32_t)c); break; case 8: - fatal("TODO 8 byte symbolic"); + fatal("TODO 8 byte"); break; default: unreachable(); } } +/* Assemble a symbolic value. */ +static void assemblereloc(const char *l, int64_t c, int nbytes, int type) { + Relocation *reloc; + Symbol *sym; + + if (l != NULL) { + reloc = newreloc(); + sym = getsym(l); + reloc->type = type; + reloc->section = cursection; + reloc->sym = sym; + reloc->offset = cursection->hdr.sh_size; + } + assembleconstant(c, nbytes); +} + /* Assemble a r <-> (%rip) operation. */ static void assembleriprel(Memarg *memarg, uint8_t rexw, uint8_t opcode, uint8_t reg, uint8_t opsz) { uint8_t rex; + if (opsz == 2) sb(0x66); rex = rexbyte(rexw, 0, 0, 0); if (rex != rexbyte(0, 0, 0, 0)) sb(rex); sb2(opcode, modregrm(0x00, reg, 0x05)); - assemblereloc(memarg->l, memarg->c - 4, 4, R_X86_64_PC32); + + if (memarg->l) { + assemblereloc(memarg->l, memarg->c - 4, 4, R_X86_64_PC32); + } else { + assembleconstant(memarg->c, 4); + } } /* Assemble a r <-> mem operation. */ |
