Add Intel call/return encodings.
This commit is contained in:
@@ -64,3 +64,10 @@ I32.enc(base.uload8.i32.i32, *r.ldDisp32(0x0f, 0xb6))
|
||||
I32.enc(base.sload8.i32.i32, *r.ld(0x0f, 0xbe))
|
||||
I32.enc(base.sload8.i32.i32, *r.ldDisp8(0x0f, 0xbe))
|
||||
I32.enc(base.sload8.i32.i32, *r.ldDisp32(0x0f, 0xbe))
|
||||
|
||||
#
|
||||
# Call/return
|
||||
#
|
||||
I32.enc(base.call, *r.call_id(0xe8))
|
||||
I32.enc(base.call_indirect.i32, *r.call_r(0xff, rrr=2))
|
||||
I32.enc(base.x_return, *r.ret(0xc3))
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import absolute_import
|
||||
from cdsl.isa import EncRecipe
|
||||
from cdsl.predicates import IsSignedInt, IsEqual
|
||||
from base.formats import UnaryImm, Binary, BinaryImm, Store, Load
|
||||
from base.formats import MultiAry, Call, IndirectCall
|
||||
from .registers import GPR, ABCD
|
||||
|
||||
try:
|
||||
@@ -206,3 +207,10 @@ ldDisp8 = TailRecipe(
|
||||
ldDisp32 = TailRecipe(
|
||||
'ldDisp32', Load, size=5, ins=(GPR), outs=(GPR),
|
||||
instp=IsSignedInt(Load.offset, 32))
|
||||
|
||||
#
|
||||
# Call/return
|
||||
#
|
||||
call_id = TailRecipe('call_id', Call, size=4, ins=(), outs=())
|
||||
call_r = TailRecipe('call_r', IndirectCall, size=1, ins=GPR, outs=())
|
||||
ret = TailRecipe('ret', MultiAry, size=0, ins=(), outs=())
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
//! Emitting binary Intel machine code.
|
||||
|
||||
use binemit::{CodeSink, bad_encoding};
|
||||
use binemit::{CodeSink, Reloc, bad_encoding};
|
||||
use ir::{Function, Inst, InstructionData};
|
||||
use isa::RegUnit;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/binemit-intel.rs"));
|
||||
|
||||
pub static RELOC_NAMES: [&'static str; 1] = ["Call"];
|
||||
/// Intel relocations.
|
||||
pub enum RelocKind {
|
||||
/// A 4-byte relative function reference. Based from relocation + 4 bytes.
|
||||
PCRel4,
|
||||
}
|
||||
|
||||
pub static RELOC_NAMES: [&'static str; 1] = ["PCRel4"];
|
||||
|
||||
impl Into<Reloc> for RelocKind {
|
||||
fn into(self) -> Reloc {
|
||||
Reloc(self as u16)
|
||||
}
|
||||
}
|
||||
|
||||
// Emit single-byte opcode.
|
||||
fn put_op1<CS: CodeSink + ?Sized>(bits: u16, sink: &mut CS) {
|
||||
@@ -310,3 +322,25 @@ fn recipe_op2lddisp32<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink:
|
||||
panic!("Expected Load format: {:?}", func.dfg[inst]);
|
||||
}
|
||||
}
|
||||
|
||||
fn recipe_op1call_id<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||
if let InstructionData::Call { func_ref, .. } = func.dfg[inst] {
|
||||
put_op1(func.encodings[inst].bits(), sink);
|
||||
sink.reloc_func(RelocKind::PCRel4.into(), func_ref);
|
||||
sink.put4(0);
|
||||
} else {
|
||||
panic!("Expected Call format: {:?}", func.dfg[inst]);
|
||||
}
|
||||
}
|
||||
|
||||
fn recipe_op1call_r<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||
let bits = func.encodings[inst].bits();
|
||||
put_op1(bits, sink);
|
||||
modrm_r_bits(func.locations[func.dfg.inst_args(inst)[0]].unwrap_reg(),
|
||||
bits,
|
||||
sink);
|
||||
}
|
||||
|
||||
fn recipe_op1ret<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||
put_op1(func.encodings[inst].bits(), sink);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user