-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[x64] implementing more of instruction compilation
- Loading branch information
Showing
10 changed files
with
306 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::Target::{x64Reg, Reg}; | ||
|
||
use super::instr::MemOp; | ||
|
||
#[doc(hidden)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct RexPrefix { | ||
pub w: bool, | ||
pub r: bool, | ||
pub x: bool, | ||
pub b: bool, | ||
} | ||
|
||
#[doc(hidden)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum MandatoryPrefix { | ||
t16BitOps, | ||
} | ||
|
||
pub(crate) fn buildOpcode(mandatory: Option<MandatoryPrefix>, rex: Option<RexPrefix>, op: Vec<u8>) -> Vec<u8> { | ||
let mut out = vec![]; | ||
|
||
if let Some(man) = mandatory { | ||
out.extend_from_slice(&match man { | ||
MandatoryPrefix::t16BitOps => vec![0x66], | ||
}) | ||
} | ||
|
||
if let Some(rex) = rex { | ||
out.push({ | ||
let mut enc = 1 << 6; | ||
if rex.w { enc |= 1 << 3} | ||
if rex.r { enc |= 1 << 2} | ||
if rex.x { enc |= 1 << 1} | ||
if rex.b { enc |= 1 << 0} | ||
enc | ||
}) | ||
} | ||
|
||
out.extend_from_slice(&op); | ||
|
||
out | ||
} | ||
|
||
#[doc(hidden)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct ModRm {} | ||
|
||
impl ModRm { | ||
pub fn reg2(reg1: x64Reg, reg2: x64Reg) -> Vec<u8> { | ||
vec![0b11 << 6 | reg2.enc() << 3 | reg1.enc()] | ||
} | ||
|
||
pub fn regM(reg: x64Reg, mem: MemOp) -> Vec<u8> { | ||
let mut out = vec![mem._mod() << 6 | reg.enc() << 3 | 0b100]; | ||
out.extend_from_slice(&mem.encode()); | ||
out | ||
} | ||
|
||
pub fn memR(mem: MemOp, reg: x64Reg) -> Vec<u8> { | ||
let mut out = vec![0 << 6 | reg.enc() << 3 | 0b100]; | ||
out.extend_from_slice(&mem.encode()); | ||
out | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod lexer; | ||
mod parser; | ||
mod instr; | ||
/// x64 instruction encoding (compilation) and verifycation | ||
pub mod instr; | ||
/// x64 instruction set architecture specific stuff like rex prefix | ||
pub mod isa; | ||
|
||
pub use lexer::*; | ||
pub use parser::*; | ||
pub use instr::*; | ||
pub use parser::*; |
Oops, something went wrong.