Skip to content

Commit

Permalink
Add homomorphic host redirection abstraction for vm->host calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Sep 17, 2019
1 parent 574e4c4 commit 9ab3da3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/singlepass-backend/src/codegen_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
),
Location::GPR(GPR::RAX),
);
a.emit_jmp_location(Location::GPR(GPR::RAX));
a.emit_homomorphic_host_redirection(GPR::RAX);

self.func_import_count += 1;

Expand Down
6 changes: 6 additions & 0 deletions lib/singlepass-backend/src/emitter_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ pub trait Emitter {
fn emit_call_location(&mut self, loc: Location);

fn emit_bkpt(&mut self);

fn emit_homomorphic_host_redirection(&mut self, target: GPR);
}

fn _dummy(a: &mut Assembler) {
Expand Down Expand Up @@ -940,4 +942,8 @@ impl Emitter for Assembler {
fn emit_bkpt(&mut self) {
dynasm!(self ; int 0x3);
}

fn emit_homomorphic_host_redirection(&mut self, target: GPR) {
self.emit_jmp_location(Location::GPR(target));
}
}
52 changes: 52 additions & 0 deletions lib/singlepass-backend/src/translator_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,4 +977,56 @@ impl Emitter for Assembler {
fn emit_bkpt(&mut self) {
dynasm!(self ; brk 1)
}

fn emit_homomorphic_host_redirection(&mut self, target: GPR) {
let target = map_gpr(target);
dynasm!(
self
; sub sp, sp, 96
; str x19, [sp, 0]
; str x20, [sp, 8]
; str x21, [sp, 16]
; str x22, [sp, 24]
; str x23, [sp, 32]
; str x24, [sp, 40]
; str x25, [sp, 48]
; str x26, [sp, 56]
; str x27, [sp, 64]
; str x28, [sp, 72] // x_rsp
; str x30, [sp, 80] // LR
; adr x30, >after

// Put parameters in correct order
; sub sp, sp, 64
; str X(map_gpr(GPR::RDI).x()), [sp, 0]
; str X(map_gpr(GPR::RSI).x()), [sp, 8]
; str X(map_gpr(GPR::RDX).x()), [sp, 16]
; str X(map_gpr(GPR::RCX).x()), [sp, 24]
; str X(map_gpr(GPR::R8).x()), [sp, 32]
; str X(map_gpr(GPR::R9).x()), [sp, 40]
; ldr x0, [sp, 0]
; ldr x1, [sp, 8]
; ldr x2, [sp, 16]
; ldr x3, [sp, 24]
; ldr x4, [sp, 32]
; ldr x5, [sp, 40]
; add sp, sp, 64

; br X(target.x())
; after:
; ldr x19, [sp, 0]
; ldr x20, [sp, 8]
; ldr x21, [sp, 16]
; ldr x22, [sp, 24]
; ldr x23, [sp, 32]
; ldr x24, [sp, 40]
; ldr x25, [sp, 48]
; ldr x26, [sp, 56]
; ldr x27, [sp, 64]
; ldr x28, [sp, 72] // x_rsp
; ldr x30, [sp, 80] // LR
; add sp, sp, 96
; br x30
);
}
}

0 comments on commit 9ab3da3

Please sign in to comment.