pass-lang/src/asm.c

31 lines
779 B
C
Raw Normal View History

/// This file handles the contextual generation of machine code.
/// It abstracts over quirks like the limitations of addressing modes,
/// provides higher-level functionality, and can perform peephole optimization.
///
/// Reserved registers:
///
/// * rsp: the stack pointer
/// * rbp: the base of the stack frame
/// * rax: the top of the stack
/// * r13: a scratch register for compound instructions
2022-09-05 23:48:56 -07:00
#include "asm.h"
#include "io.h"
#include <stdlib.h>
#include <string.h>
void inst_jump(ip there) {
x86_inst_jmp_disp((int32_t) (there - here));
// TODO: support 64-bit jumps?
2022-09-05 23:48:56 -07:00
}
ip inst_jump_unresolved(void) {
x86_inst_jmp_disp32(0);
2022-09-05 23:48:56 -07:00
return here;
}
void inst_jump_resolve(ip disp, ip there) {
patch_i32(disp - 4, (int32_t) (there - here));
2022-09-05 23:48:56 -07:00
}