arbitrary addr
This commit is contained in:
+1
-1
@@ -74,7 +74,7 @@ pub enum EType {
|
||||
}
|
||||
|
||||
// this is currently specialized for riscv64; obviously add params later
|
||||
pub fn create(program: &[u8], start_offset: Addr) -> Vec<u8> {
|
||||
pub fn create(program: &[u8], start_offset: u64) -> Vec<u8> {
|
||||
let pie = true;
|
||||
let addr_start = if pie { 0 } else { 0x400000 };
|
||||
let page_size = 0x1000;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
pub trait Addr: Clone + Copy {
|
||||
fn from_len(len: usize) -> Self;
|
||||
}
|
||||
|
||||
impl Addr for u64 {
|
||||
fn from_len(len: usize) -> Self {
|
||||
len as Self
|
||||
}
|
||||
}
|
||||
|
||||
impl Addr for u32 {
|
||||
fn from_len(len: usize) -> Self {
|
||||
len as Self
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
mod addr;
|
||||
mod symbol;
|
||||
pub use addr::*;
|
||||
pub use symbol::*;
|
||||
|
||||
use crate::{arch::Arch, backend::LinkedProgram, io::CompilerMsg};
|
||||
@@ -30,9 +32,9 @@ pub type VarId = usize;
|
||||
pub type FnId = usize;
|
||||
|
||||
impl<A: Arch> Program<A> {
|
||||
pub fn encode_data(&self, data: &mut Vec<u8>, sym_tab: &mut SymTable) {
|
||||
pub fn encode_data(&self, data: &mut Vec<u8>, sym_tab: &mut SymTable<A::Addr>) {
|
||||
for d in &self.ro_data {
|
||||
let addr = data.len() as u64;
|
||||
let addr = A::Addr::from_len(data.len());
|
||||
data.extend(&d.bytes);
|
||||
sym_tab.insert(d.sym, addr);
|
||||
}
|
||||
@@ -58,7 +60,7 @@ impl<A: Arch> Program<A> {
|
||||
res
|
||||
}
|
||||
|
||||
pub fn compile(&self) -> Result<LinkedProgram, CompilerMsg> {
|
||||
pub fn compile(&self) -> Result<LinkedProgram<A::Addr>, CompilerMsg> {
|
||||
A::compile(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub struct Symbol(pub(super) usize);
|
||||
|
||||
pub type Addr = u64;
|
||||
|
||||
pub struct SymTable(Vec<Option<Addr>>);
|
||||
impl SymTable {
|
||||
pub struct SymTable<Addr>(Vec<Option<Addr>>);
|
||||
impl<Addr: Clone + Copy> SymTable<Addr> {
|
||||
pub fn new(len: usize) -> Self {
|
||||
Self(vec![None; len])
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
use crate::backend::{Addr, elf};
|
||||
use crate::backend::elf;
|
||||
|
||||
pub struct LinkedProgram {
|
||||
pub struct LinkedProgram<Addr> {
|
||||
pub code: Vec<u8>,
|
||||
pub entry: Option<Addr>,
|
||||
}
|
||||
|
||||
impl LinkedProgram {
|
||||
impl LinkedProgram<u64> {
|
||||
pub fn to_elf(&self) -> Vec<u8> {
|
||||
elf::create(&self.code, self.entry.expect("no start"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user