This patch introduces basic aarch64 code generation by using `cranelift-codegen`'s backend. This commit *does not*: * Change the semantics of the code generation * Adds support for other Wasm instructions The most notable change in this patch is how addressing modes are handled at the MacroAssembler layer: instead of having a canonical address representation, this patch introduces the addressing mode as an associated type in the MacroAssembler trait. This approach has the advantage that gives each ISA enough flexiblity to describe the addressing modes and their constraints in isolation without having to worry on how a particular addressing mode is going to affect other ISAs. In the case of Aarch64 this becomes useful to describe indexed addressing modes (particularly from the stack pointer). This patch uses the concept of a shadow stack pointer (x28) as a workaround to Aarch64's stack pointer 16-byte alignment. This constraint is enforced by: * Introducing specialized addressing modes when using the real stack pointer; this enables auditing when the real stack pointer is used. As of this change, the real stack pointer is only used in the function's prologue and epilogue. * Asserting that the real stack pointer is not used as a base for addressing modes. * Ensuring that at any point during the code generation process where the stack pointer changes (e.g. when stack space is allocated / deallocated) the value of the real stack pointer is copied into the shadow stack pointer.
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use regalloc2::{PReg, RegClass};
|
|
|
|
/// A newtype abstraction on top of a physical register.
|
|
//
|
|
// NOTE
|
|
// This is temporary; the intention behind this newtype
|
|
// is to keep the usage of PReg contained to this module
|
|
// so that the rest of Winch should only need to operate
|
|
// on top of the concept of `Reg`.
|
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
pub(crate) struct Reg(PReg);
|
|
|
|
impl Reg {
|
|
/// Create a new register from a physical register.
|
|
pub const fn new(raw: PReg) -> Self {
|
|
Reg(raw)
|
|
}
|
|
|
|
/// Create a new general purpose register from encoding.
|
|
pub fn int(enc: usize) -> Self {
|
|
Self::new(PReg::new(enc, RegClass::Int))
|
|
}
|
|
|
|
/// Create a new floating point register from encoding.
|
|
#[allow(dead_code)]
|
|
pub fn float(enc: usize) -> Self {
|
|
Self::new(PReg::new(enc, RegClass::Float))
|
|
}
|
|
|
|
/// Get the encoding of the underlying register.
|
|
pub const fn hw_enc(self) -> u8 {
|
|
self.0.hw_enc() as u8
|
|
}
|
|
|
|
/// Get the physical register representation.
|
|
pub(super) fn inner(&self) -> PReg {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl From<Reg> for cranelift_codegen::Reg {
|
|
fn from(reg: Reg) -> Self {
|
|
reg.inner().into()
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for Reg {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(f, "{}", self.0)
|
|
}
|
|
}
|