Require assembler sections to specify where in virtual memory they begin
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -31,6 +31,7 @@ fn main() -> Result<()> {
|
||||
}
|
||||
};
|
||||
let obj = vm::obj::obj::Object::try_from(&ast)?;
|
||||
//dump(&obj)?;
|
||||
let mut vm = vm::vm::Vm::new();
|
||||
vm.load_object(obj, 1024 * 1024 * 64)?; // 64mb
|
||||
let status = vm.run()?;
|
||||
@@ -39,23 +40,21 @@ fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
fn dump(obj: &Object) {
|
||||
fn dump(obj: &vm::obj::obj::Object) -> Result<()> {
|
||||
use vm::obj::obj::Section;
|
||||
use vm::visit::VisitInst;
|
||||
let mut stdout = io::stdout();
|
||||
for section in &obj.sections {
|
||||
let mut disasm = match section {
|
||||
Section::Code { start, contents, .. }
|
||||
| Section::Data { start, contents, .. } => {
|
||||
Section::Code { start, contents, .. } => {
|
||||
vm::disassemble::Disassemble::new(&mut stdout, contents, *start)
|
||||
}
|
||||
Section::Meta { .. } => continue,
|
||||
Section::Meta { .. } | Section::Data { .. } => continue,
|
||||
};
|
||||
while !disasm.is_done() {
|
||||
disasm.visit_inst()?;
|
||||
}
|
||||
println!();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -38,7 +38,6 @@ impl<'a> Assemble<'a> {
|
||||
}
|
||||
|
||||
pub fn assemble(&mut self) -> Result<Object> {
|
||||
let mut pos = 0;
|
||||
let mut sections = Vec::new();
|
||||
|
||||
// gather global symbols
|
||||
@@ -78,11 +77,9 @@ impl<'a> Assemble<'a> {
|
||||
}
|
||||
}
|
||||
let (start, end) = match org {
|
||||
Some(SectionOrg::Start(start)) => (*start, start + bytes.len() as u64),
|
||||
Some(SectionOrg::Range(start, end)) => (*start, *end),
|
||||
None => (pos, pos + bytes.len() as u64),
|
||||
SectionOrg::Start(start) => (*start, start + bytes.len() as u64),
|
||||
SectionOrg::Range(start, end) => (*start, *end),
|
||||
};
|
||||
pos = end;
|
||||
|
||||
let section = match block {
|
||||
SectionBlock::Data { .. } => Section::Data {
|
||||
@@ -121,10 +118,12 @@ impl<'a> Assemble<'a> {
|
||||
|
||||
fn gather_symbols(block: &SectionBlock, export: bool) -> Result<HashMap<String, u64>> {
|
||||
match block {
|
||||
SectionBlock::Data { body, .. } | SectionBlock::Code { body, .. } => {
|
||||
SectionBlock::Data { org, body, .. } | SectionBlock::Code { org, body, .. } => {
|
||||
let mut exports = HashSet::new();
|
||||
let mut labels = HashMap::new();
|
||||
let mut pos = 0;
|
||||
let mut pos = match org {
|
||||
SectionOrg::Start(start) | SectionOrg::Range(start, _) => (*start) as usize,
|
||||
};
|
||||
for line in body.iter() {
|
||||
match line {
|
||||
Line::Inst(inst) => {
|
||||
|
||||
@@ -3,11 +3,11 @@ use crate::vm::{inst::*, reg::Reg};
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum SectionBlock {
|
||||
Data {
|
||||
org: Option<SectionOrg>,
|
||||
org: SectionOrg,
|
||||
body: Vec<Line>,
|
||||
},
|
||||
Code {
|
||||
org: Option<SectionOrg>,
|
||||
org: SectionOrg,
|
||||
body: Vec<Line>,
|
||||
},
|
||||
Meta {
|
||||
|
||||
@@ -82,11 +82,11 @@ SectionOrg: SectionOrg = {
|
||||
}
|
||||
|
||||
Section: SectionBlock = {
|
||||
"data" <org:SectionOrg?> "{" <body:Line*> "}" => {
|
||||
"data" <org:SectionOrg> "{" <body:Line*> "}" => {
|
||||
SectionBlock::Data { org, body }
|
||||
},
|
||||
|
||||
"code" <org:SectionOrg?> "{" <body:Line*> "}" => {
|
||||
"code" <org:SectionOrg> "{" <body:Line*> "}" => {
|
||||
SectionBlock::Code { org, body }
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user