pull/21/head
Ondřej Hruška 4 years ago
parent f493cc102a
commit 8f076e195a
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      asm/src/data/literal.rs
  2. 4
      asm/src/data/mask.rs
  3. 21
      asm/src/data/mod.rs
  4. 1
      asm/src/data/reg.rs
  5. 9
      asm/src/error.rs
  6. 9
      asm/src/instr/flatten.rs
  7. 13
      asm/src/instr/mod.rs
  8. 14
      asm/src/instr/op.rs
  9. 23
      asm/src/lib.rs
  10. 12
      asm/src/parse/mod.rs
  11. 5
      asm/src/parse/parse_cond.rs
  12. 16
      asm/src/parse/parse_data.rs
  13. 10
      asm/src/parse/parse_instr.rs
  14. 11
      asm/src/parse/parse_op.rs
  15. 7
      asm/src/parse/parse_routines.rs
  16. 3
      asm/src/parse/sexp_expect.rs
  17. 5
      asm/src/patches/mod.rs
  18. 5
      crsn/src/main.rs
  19. 13
      runtime/src/exec/mod.rs
  20. 3
      runtime/src/fault.rs
  21. 8
      runtime/src/frame.rs
  22. 3
      runtime/src/frame/status.rs
  23. 3
      runtime/src/lib.rs
  24. 5
      runtime/src/mlock.rs
  25. 8
      runtime/src/program.rs
  26. 9
      runtime/src/run_thread.rs
  27. 2
      runtime/src/span.rs

@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU32;
use std::borrow::Cow;
pub type DebugMsg = Cow<'static, str>; pub type DebugMsg = Cow<'static, str>;

@ -15,7 +15,7 @@ impl Default for Mask {
fn default() -> Self { fn default() -> Self {
Mask { Mask {
len: 64, len: 64,
offset: 0 offset: 0,
} }
} }
} }
@ -44,7 +44,7 @@ impl Mask {
// create the invalid mask to display it in the error // create the invalid mask to display it in the error
return Err(AsmError::BadMask(Mask { return Err(AsmError::BadMask(Mask {
len, len,
offset offset,
})); }));
} }

@ -1,20 +1,19 @@
use super::error::AsmError; use std::convert::TryFrom;
use std::fmt::{Debug, Display, Formatter};
use std::fmt;
use literal::Addr;
pub use mask::Mask;
pub use reg::Register;
use crate::data::literal::{as_signed, Value};
use super::error::AsmError;
pub mod literal; pub mod literal;
pub mod reg; pub mod reg;
pub mod mask; pub mod mask;
pub use reg::Register;
pub use mask::Mask;
use literal::Addr;
use std::convert::TryFrom;
use crate::data::literal::{Value, as_signed};
use std::fmt::{Debug, Formatter, Display};
use std::fmt;
/// Data source disposition /// Data source disposition
#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum DataDisp { pub enum DataDisp {

@ -1,4 +1,5 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use crate::error::Error; use crate::error::Error;
/// Register name /// Register name

@ -1,9 +1,10 @@
use crate::instr::{Cond};
use crate::data::{Mask, Register};
use thiserror::Error;
use std::borrow::Cow; use std::borrow::Cow;
use crate::data::literal::Label;
use thiserror::Error;
use crate::data::{Mask, Register};
use crate::data::literal::Label;
use crate::instr::Cond;
/// csn_asm unified error type /// csn_asm unified error type
#[derive(Error, Debug)] #[derive(Error, Debug)]

@ -1,9 +1,10 @@
use std::sync::atomic::AtomicU32;
use crate::instr::{HLOp, Instr, Cond, Routine, Op};
use crate::error::{Error, AsmError};
use std::collections::HashMap; use std::collections::HashMap;
use crate::data::literal::{Label, Value}; use std::sync::atomic::AtomicU32;
use crate::data::{Rd, SrcDisp}; use crate::data::{Rd, SrcDisp};
use crate::data::literal::{Label, Value};
use crate::error::{AsmError, Error};
use crate::instr::{Cond, HLOp, Instr, Op, Routine};
/// A trait for something that can turn into multiple instructions /// A trait for something that can turn into multiple instructions
pub trait Flatten { pub trait Flatten {

@ -1,17 +1,14 @@
mod op; pub use cond::Cond;
mod cond;
mod flatten;
pub use flatten::Flatten; pub use flatten::Flatten;
pub use flatten::lower; pub use flatten::lower;
pub use op::HLOp; pub use op::HLOp;
pub use op::Op; pub use op::Op;
pub use cond::Cond;
use crate::data::literal::{RoutineName};
use crate::data::literal::RoutineName;
mod op;
mod cond;
mod flatten;
/// A higher-level instruction /// A higher-level instruction
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]

@ -1,10 +1,10 @@
use crate::data::{ use crate::data::{
Wr, Rd, literal::DebugMsg, literal::Label,
literal::Label,
literal::RoutineName, literal::RoutineName,
literal::DebugMsg, Rd,
Wr,
}; };
use crate::instr::{Cond}; use crate::instr::Cond;
/// A higher level simple opration /// A higher level simple opration
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -64,9 +64,11 @@ pub enum Op {
Or { dst: Wr, a: Rd, b: Rd }, Or { dst: Wr, a: Rd, b: Rd },
Xor { dst: Wr, a: Rd, b: Rd }, Xor { dst: Wr, a: Rd, b: Rd },
Cpl { dst: Wr, a: Rd }, Cpl { dst: Wr, a: Rd },
Rol { dst: Wr, a: Rd, n: Rd }, // Rotate (with wrap-around) Rol { dst: Wr, a: Rd, n: Rd },
// Rotate (with wrap-around)
Ror { dst: Wr, a: Rd, n: Rd }, Ror { dst: Wr, a: Rd, n: Rd },
Lsl { dst: Wr, a: Rd, n: Rd }, // Shift Lsl { dst: Wr, a: Rd, n: Rd },
// Shift
Lsr { dst: Wr, a: Rd, n: Rd }, Lsr { dst: Wr, a: Rd, n: Rd },
Asr { dst: Wr, a: Rd, n: Rd }, Asr { dst: Wr, a: Rd, n: Rd },
} }

@ -1,11 +1,11 @@
use crate::instr::{lower, Op};
pub mod data; pub mod data;
pub mod error; pub mod error;
pub mod instr; pub mod instr;
pub mod parse; pub mod parse;
pub mod patches; pub mod patches;
use crate::instr::{Op, lower};
/// Parse a program from string and assemble a low level instruction sequence from it. /// Parse a program from string and assemble a low level instruction sequence from it.
pub fn assemble(source: &str) -> Result<Vec<Op>, error::Error> { pub fn assemble(source: &str) -> Result<Vec<Op>, error::Error> {
let parsed = parse::parse(source)?; let parsed = parse::parse(source)?;
@ -14,12 +14,13 @@ pub fn assemble(source : &str) -> Result<Vec<Op>, error::Error> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::parse::{parse, parse_instructions};
use crate::instr::{HLOp, Op, Flatten, Instr, lower};
use crate::data::{Wr, DstDisp, Register, SrcDisp, Rd};
use crate::data::literal::{Addr, Label};
use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU32;
use crate::data::{DstDisp, Rd, Register, SrcDisp, Wr};
use crate::data::literal::{Addr, Label};
use crate::instr::{Flatten, HLOp, Instr, lower, Op};
use crate::instr::Cond; use crate::instr::Cond;
use crate::parse::{parse, parse_instructions};
#[test] #[test]
fn test_parse_empty() { fn test_parse_empty() {
@ -187,14 +188,14 @@ mod tests {
Wr::new(DstDisp::Register(Register::Gen(0))), Wr::new(DstDisp::Register(Register::Gen(0))),
Rd::new(SrcDisp::Register(Register::Gen(0))), Rd::new(SrcDisp::Register(Register::Gen(0))),
)), )),
branches: None branches: None,
}, },
Instr { Instr {
op: HLOp::L(Op::Mov( op: HLOp::L(Op::Mov(
Wr::new(DstDisp::Register(Register::Gen(1))), Wr::new(DstDisp::Register(Register::Gen(1))),
Rd::new(SrcDisp::Register(Register::Gen(2))), Rd::new(SrcDisp::Register(Register::Gen(2))),
)), )),
branches: None branches: None,
} }
] ]
), ),
@ -206,18 +207,18 @@ mod tests {
Wr::new(DstDisp::Register(Register::Gen(0))), Wr::new(DstDisp::Register(Register::Gen(0))),
Rd::new(SrcDisp::Register(Register::Gen(0))), Rd::new(SrcDisp::Register(Register::Gen(0))),
)), )),
branches: None branches: None,
}, },
Instr { Instr {
op: HLOp::L(Op::Mov( op: HLOp::L(Op::Mov(
Wr::new(DstDisp::Register(Register::Gen(1))), Wr::new(DstDisp::Register(Register::Gen(1))),
Rd::new(SrcDisp::Register(Register::Gen(1))), Rd::new(SrcDisp::Register(Register::Gen(1))),
)), )),
branches: None branches: None,
} }
] ]
) )
]) ]),
} }
, parsed); , parsed);
} }

@ -1,9 +1,10 @@
use std::sync::atomic::AtomicU32;
use crate::instr::{Routine, HLOp, Flatten}; pub use parse_instr::parse_instructions;
use crate::error::Error; use parse_routines::parse_routines;
use std::sync::atomic::AtomicU32; use crate::error::Error;
use crate::instr::{Flatten, HLOp, Routine};
use crate::parse::sexp_expect::expect_list; use crate::parse::sexp_expect::expect_list;
mod parse_cond; mod parse_cond;
@ -13,9 +14,6 @@ mod parse_routines;
mod sexp_expect; mod sexp_expect;
mod parse_op; mod parse_op;
use parse_routines::parse_routines;
pub use parse_instr::parse_instructions;
pub fn parse(source: &str) -> Result<Vec<HLOp>, Error> { pub fn parse(source: &str) -> Result<Vec<HLOp>, Error> {
let root = sexp::parse(source)?; let root = sexp::parse(source)?;

@ -1,8 +1,9 @@
use crate::parse::sexp_expect::{expect_list, expect_string_atom};
use sexp::Sexp; use sexp::Sexp;
use crate::instr::{Cond, Instr};
use crate::error::Error; use crate::error::Error;
use crate::instr::{Cond, Instr};
use crate::parse::parse_instr::parse_instructions; use crate::parse::parse_instr::parse_instructions;
use crate::parse::sexp_expect::{expect_list, expect_string_atom};
use crate::patches::TryRemove; use crate::patches::TryRemove;
pub fn parse_cond_branch(tok: Sexp) -> Result<(Cond, Vec<Instr>), Error> { pub fn parse_cond_branch(tok: Sexp) -> Result<(Cond, Vec<Instr>), Error> {

@ -1,8 +1,10 @@
use sexp::{Sexp, Atom};
use crate::data::{DataDisp, Rd, Wr, DstDisp, SrcDisp, reg};
use crate::error::Error;
use crate::data::literal::{Addr, Label};
use std::convert::TryFrom; use std::convert::TryFrom;
use sexp::{Atom, Sexp};
use crate::data::{DataDisp, DstDisp, Rd, reg, SrcDisp, Wr};
use crate::data::literal::{Addr, Label};
use crate::error::Error;
use crate::parse::sexp_expect::expect_string_atom; use crate::parse::sexp_expect::expect_string_atom;
/// Parse a label /// Parse a label
@ -24,7 +26,7 @@ pub fn parse_data_disp(tok: Option<Sexp>) -> Result<DataDisp, Error> {
match &tok { match &tok {
Sexp::Atom(Atom::I(val)) => { Sexp::Atom(Atom::I(val)) => {
Ok(DataDisp::Immediate(unsafe { std::mem::transmute(*val) })) Ok(DataDisp::Immediate(unsafe { std::mem::transmute(*val) }))
}, }
Sexp::Atom(Atom::S(s)) => { Sexp::Atom(Atom::S(s)) => {
if s == "_" { if s == "_" {
return Ok(DataDisp::Discard); return Ok(DataDisp::Discard);
@ -42,10 +44,10 @@ pub fn parse_data_disp(tok: Option<Sexp>) -> Result<DataDisp, Error> {
} else { } else {
Ok(DataDisp::Register(reg::parse_reg(s)?)) Ok(DataDisp::Register(reg::parse_reg(s)?))
} }
}, }
_ => { _ => {
Err(Error::Parse(format!("bad data disp: {:?}", tok).into())) Err(Error::Parse(format!("bad data disp: {:?}", tok).into()))
}, }
} }
} }

@ -1,11 +1,11 @@
use sexp::Sexp; use sexp::Sexp;
use crate::instr::{Instr};
use crate::error::Error;
use crate::parse::parse_cond::{parse_cond_branch};
use crate::error::Error;
use crate::instr::Instr;
use crate::parse::parse_cond::parse_cond_branch;
use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use crate::parse::sexp_expect::{expect_list, expect_string_atom};
use crate::patches::SexpIsA; use crate::patches::SexpIsA;
use super::parse_op::parse_op; use super::parse_op::parse_op;
pub fn parse_instructions(instrs: Vec<Sexp>) -> Result<Vec<Instr>, Error> { pub fn parse_instructions(instrs: Vec<Sexp>) -> Result<Vec<Instr>, Error> {
@ -43,7 +43,7 @@ pub fn parse_instructions(instrs: Vec<Sexp>) -> Result<Vec<Instr>, Error> {
parsed.push(Instr { parsed.push(Instr {
op: parse_op(name.as_str(), far, arg_tokens.into_iter())?, op: parse_op(name.as_str(), far, arg_tokens.into_iter())?,
branches branches,
}); });
} }
Ok(parsed) Ok(parsed)

@ -1,11 +1,12 @@
use crate::instr::{HLOp, Op};
use sexp::Sexp; use sexp::Sexp;
use crate::data::{Rd, Wr};
use crate::data::literal::{Label, RoutineName};
use crate::error::Error; use crate::error::Error;
use crate::data::literal::{RoutineName, Label}; use crate::instr::{HLOp, Op};
use crate::parse::sexp_expect::expect_string_atom;
use crate::parse::parse_data::{parse_rd, parse_wr, parse_label};
use crate::parse::parse_cond::parse_cond; use crate::parse::parse_cond::parse_cond;
use crate::data::{Rd, Wr}; use crate::parse::parse_data::{parse_label, parse_rd, parse_wr};
use crate::parse::sexp_expect::expect_string_atom;
pub fn parse_op(keyword: &str, far: bool, mut arg_tokens: impl ExactSizeIterator<Item=Sexp> + Clone) -> Result<HLOp, Error> { pub fn parse_op(keyword: &str, far: bool, mut arg_tokens: impl ExactSizeIterator<Item=Sexp> + Clone) -> Result<HLOp, Error> {
Ok(match keyword { Ok(match keyword {

@ -1,8 +1,9 @@
use crate::parse::parse_instr::parse_instructions;
use crate::instr::Routine;
use crate::data::literal::RoutineName;
use sexp::Sexp; use sexp::Sexp;
use crate::data::literal::RoutineName;
use crate::error::Error; use crate::error::Error;
use crate::instr::Routine;
use crate::parse::parse_instr::parse_instructions;
use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use crate::parse::sexp_expect::{expect_list, expect_string_atom};
use crate::patches::TryRemove; use crate::patches::TryRemove;

@ -1,4 +1,5 @@
use sexp::{Sexp, Atom}; use sexp::{Atom, Sexp};
use crate::error::Error; use crate::error::Error;
pub fn expect_list(expr: Option<Sexp>, allow_empty: bool) -> Result<Vec<Sexp>, Error> { pub fn expect_list(expr: Option<Sexp>, allow_empty: bool) -> Result<Vec<Sexp>, Error> {

@ -1,5 +1,6 @@
pub use sexp_is_a::SexpIsA;
pub use try_remove::TryRemove;
mod try_remove; mod try_remove;
mod sexp_is_a; mod sexp_is_a;
pub use try_remove::TryRemove;
pub use sexp_is_a::SexpIsA;

@ -2,9 +2,10 @@
extern crate log; extern crate log;
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
use runtime::run_thread::{RunThread, ThreadToken};
use runtime::program::Program;
use asm::data::literal::Addr; use asm::data::literal::Addr;
use runtime::program::Program;
use runtime::run_thread::{RunThread, ThreadToken};
fn main() { fn main() {
SimpleLogger::new().init().unwrap(); SimpleLogger::new().init().unwrap();

@ -1,10 +1,13 @@
use crate::run_thread::{RunThread}; use std::ops::Rem;
use asm::instr::{Op};
use num_traits::PrimInt;
use asm::data::literal::Addr;
use asm::instr::Op;
use crate::fault::Fault; use crate::fault::Fault;
use crate::frame::StackFrame; use crate::frame::StackFrame;
use asm::data::literal::{Addr}; use crate::run_thread::RunThread;
use std::ops::{Rem};
use num_traits::PrimInt;
pub type CyclesSpent = usize; pub type CyclesSpent = usize;

@ -1,8 +1,9 @@
use thiserror::Error; use thiserror::Error;
// use super::span::MemorySpan; // use super::span::MemorySpan;
// use crate::run_thread::ThreadToken; // use crate::run_thread::ThreadToken;
// use crate::mlock::ClaimId; // use crate::mlock::ClaimId;
use asm::data::literal::{DebugMsg, RoutineName, Label}; use asm::data::literal::{DebugMsg, Label, RoutineName};
use asm::data::Register; use asm::data::Register;
#[derive(Error, Debug)] #[derive(Error, Debug)]

@ -1,12 +1,10 @@
use asm::data::{DstDisp, Rd, Register, SrcDisp, Wr};
use asm::data::literal::{Addr, Value}; use asm::data::literal::{Addr, Value};
use asm::data::{Rd, SrcDisp, Register, Wr, DstDisp}; use status::StatusFlags;
use crate::fault::Fault;
use crate::fault::Fault;
mod status; mod status;
use status::StatusFlags;
pub const REG_COUNT: usize = 8; pub const REG_COUNT: usize = 8;

@ -1,6 +1,7 @@
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::fmt; use std::fmt;
use asm::data::literal::{Value, is_positive, is_negative};
use asm::data::literal::{is_negative, is_positive, Value};
use asm::instr::Cond; use asm::instr::Cond;
#[derive(Default, Clone, Debug)] #[derive(Default, Clone, Debug)]

@ -1,4 +1,5 @@
#[macro_use] extern crate log; #[macro_use]
extern crate log;
pub mod run_thread; pub mod run_thread;
// pub mod mlock; // pub mod mlock;

@ -1,8 +1,9 @@
use std::sync::atomic::{AtomicU32, Ordering};
use std::fmt; use std::fmt;
use std::fmt::Formatter; use std::fmt::Formatter;
use crate::run_thread::ThreadToken; use std::sync::atomic::{AtomicU32, Ordering};
use crate::fault::Fault; use crate::fault::Fault;
use crate::run_thread::ThreadToken;
use crate::span::MemorySpan; use crate::span::MemorySpan;
/// Records memory claims and protects from illegal access /// Records memory claims and protects from illegal access

@ -1,8 +1,10 @@
use asm::instr::{Op};
use asm::data::literal::{Addr, RoutineName, Label};
use crate::fault::Fault;
use std::collections::HashMap; use std::collections::HashMap;
use asm::data::literal::{Addr, Label, RoutineName};
use asm::instr::Op;
use crate::fault::Fault;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Program { pub struct Program {
ops: Vec<Op>, ops: Vec<Op>,

@ -1,14 +1,11 @@
use std::time::Duration;
use std::thread::JoinHandle; use std::thread::JoinHandle;
use std::time::Duration;
use asm::data::literal::{Addr}; use asm::data::literal::Addr;
use crate::exec::EvalRes;
use crate::frame::StackFrame; use crate::frame::StackFrame;
use crate::program::Program; use crate::program::Program;
use crate::exec::EvalRes;
const CYCLE_TIME: Duration = Duration::from_millis(0); const CYCLE_TIME: Duration = Duration::from_millis(0);
//const CYCLE_TIME : Duration = Duration::from_millis(100); //const CYCLE_TIME : Duration = Duration::from_millis(100);

@ -1,5 +1,3 @@
use asm::data::literal::Addr; use asm::data::literal::Addr;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

Loading…
Cancel
Save