From 9748b0f2dc0feae6b9f4c866a15730e5cc2b361b Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 19 Oct 2022 16:39:38 +0200 Subject: [PATCH] decode & struct Instruction --- Cargo.lock | 7 +++++++ src/decode.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 3 files changed, 67 insertions(+) create mode 100644 Cargo.lock create mode 100644 src/decode.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..1e08526 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "burritos" +version = "0.1.0" diff --git a/src/decode.rs b/src/decode.rs new file mode 100644 index 0000000..ed21275 --- /dev/null +++ b/src/decode.rs @@ -0,0 +1,57 @@ +pub struct Instruction { + value : u64, + + opcode : u8, + rs1 : u8, + rs2 : u8, + rs3 : u8, + rd : u8, + funct7 : u8, + funct7_smaller : u8, + funct3 : u8, + shamt : u8, + + imm12_I : u16, + imm12_S : u16, + + imm12_I_signed : i16, + imm12_S_signed : i16, + imm13 : i16, + imm13_signed : i16, + + imm31_12 : u32, + imm21_1 : u32, + + imm31_12_signed : i32, + imm21_1_signed : i32, +} + +pub fn decode(val : u64) -> Instruction { + Instruction { + value : val, + + opcode : 0, + rs1 : 0, + rs2 : 0, + rs3 : 0, + rd : 0, + funct7 : 0, + funct7_smaller : 0, + funct3 : 0, + shamt : 0, + + imm12_I : 0, + imm12_S : 0, + + imm12_I_signed : 0, + imm12_S_signed : 0, + imm13 : 0, + imm13_signed : 0, + + imm31_12 : 0, + imm21_1 : 0, + + imm31_12_signed : 0, + imm21_1_signed : 0, + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..9c521f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +mod decode; + fn main() { + let instr = decode::decode(98); println!("Hello, world!"); }