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