forked from AbleOS/holey-bytes
Merge pull request 'merge' (#1) from AbleOS/holey-bytes:master into master
Reviewed-on: https://git.ablecorp.us/bee/holey-bytes/pulls/1
This commit is contained in:
commit
abdce1a873
|
@ -21,11 +21,11 @@ macros::impl_both!(
|
||||||
=> [LD, ST],
|
=> [LD, ST],
|
||||||
bbd(p0: R, p1: R, p2: I)
|
bbd(p0: R, p1: R, p2: I)
|
||||||
=> [ADDI, MULI, ANDI, ORI, XORI, SLI, SRI, SRSI, CMPI, CMPUI,
|
=> [ADDI, MULI, ANDI, ORI, XORI, SLI, SRI, SRSI, CMPI, CMPUI,
|
||||||
BMC, JEQ, JNE, JLT, JGT, JLTU, JGTU, ADDFI, MULFI],
|
BMC, JAL, JEQ, JNE, JLT, JGT, JLTU, JGTU, ADDFI, MULFI],
|
||||||
bb(p0: R, p1: R)
|
bb(p0: R, p1: R)
|
||||||
=> [NEG, NOT, CP, SWA, NEGF, ITF, FTI],
|
=> [NEG, NOT, CP, SWA, NEGF, ITF, FTI],
|
||||||
bd(p0: R, p1: I)
|
bd(p0: R, p1: I)
|
||||||
=> [LI, JMP],
|
=> [LI],
|
||||||
n()
|
n()
|
||||||
=> [NOP, ECALL],
|
=> [NOP, ECALL],
|
||||||
);
|
);
|
||||||
|
|
|
@ -54,7 +54,7 @@ constmod!(pub opcode(u8) {
|
||||||
BMC = 30, "BBD; [#0] ← [#1], imm #2 bytes";
|
BMC = 30, "BBD; [#0] ← [#1], imm #2 bytes";
|
||||||
BRC = 31, "BBB; #0 ← #1, imm #2 registers";
|
BRC = 31, "BBB; #0 ← #1, imm #2 registers";
|
||||||
|
|
||||||
JMP = 32, "BD; Unconditional jump [#0 + imm #1]";
|
JAL = 32, "BD; Copy PC to #0 and unconditional jump [#1 + imm #2]";
|
||||||
JEQ = 33, "BBD; if #0 = #1 → jump imm #2";
|
JEQ = 33, "BBD; if #0 = #1 → jump imm #2";
|
||||||
JNE = 34, "BBD; if #0 ≠ #1 → jump imm #2";
|
JNE = 34, "BBD; if #0 ≠ #1 → jump imm #2";
|
||||||
JLT = 35, "BBD; if #0 < #1 → jump imm #2";
|
JLT = 35, "BBD; if #0 < #1 → jump imm #2";
|
||||||
|
|
|
@ -50,8 +50,8 @@ pub fn validate(mut program: &[u8]) -> Result<(), Error> {
|
||||||
| [DIR | DIRF, _, _, _, _, rest @ ..]
|
| [DIR | DIRF, _, _, _, _, rest @ ..]
|
||||||
| [ADD..=CMPU | BRC | ADDF..=MULF, _, _, _, rest @ ..]
|
| [ADD..=CMPU | BRC | ADDF..=MULF, _, _, _, rest @ ..]
|
||||||
| [NEG..=NOT | CP..=SWA | NEGF..=FTI, _, _, rest @ ..]
|
| [NEG..=NOT | CP..=SWA | NEGF..=FTI, _, _, rest @ ..]
|
||||||
| [LI | JMP, _, _, _, _, _, _, _, _, _, rest @ ..]
|
| [LI, _, _, _, _, _, _, _, _, _, rest @ ..]
|
||||||
| [ADDI..=CMPUI | BMC | JEQ..=JGTU | ADDFI..=MULFI, _, _, _, _, _, _, _, _, _, _, rest @ ..]
|
| [ADDI..=CMPUI | BMC | JAL..=JGTU | ADDFI..=MULFI, _, _, _, _, _, _, _, _, _, _, rest @ ..]
|
||||||
| [LD..=ST, _, _, _, _, _, _, _, _, _, _, _, _, rest @ ..] => rest,
|
| [LD..=ST, _, _, _, _, _, _, _, _, _, _, _, _, rest @ ..] => rest,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
|
|
|
@ -64,6 +64,25 @@ impl Memory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Maps host's memory into VM's memory
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// Who knows.
|
||||||
|
pub unsafe fn map(
|
||||||
|
&mut self,
|
||||||
|
mut host: *mut u8,
|
||||||
|
target: usize,
|
||||||
|
pagesize: PageSize,
|
||||||
|
count: usize,
|
||||||
|
) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unmaps pages from VM's memory
|
||||||
|
pub fn unmap(&mut self, addr: usize, count: usize) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
/// Load value from an address
|
/// Load value from an address
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
@ -215,11 +234,11 @@ impl Memory {
|
||||||
action: fn(*mut u8, *mut u8, usize),
|
action: fn(*mut u8, *mut u8, usize),
|
||||||
traph: &mut impl HandlePageFault,
|
traph: &mut impl HandlePageFault,
|
||||||
) -> Result<(), u64> {
|
) -> Result<(), u64> {
|
||||||
let mut pspl = AddrSplitter::new(src, len, self.root_pt);
|
let mut pspl = AddrPageLookuper::new(src, len, self.root_pt);
|
||||||
loop {
|
loop {
|
||||||
match pspl.next() {
|
match pspl.next() {
|
||||||
// Page found
|
// Page found
|
||||||
Some(Ok(AddrSplitOk {
|
Some(Ok(AddrPageLookupOk {
|
||||||
vaddr,
|
vaddr,
|
||||||
ptr,
|
ptr,
|
||||||
size,
|
size,
|
||||||
|
@ -233,7 +252,7 @@ impl Memory {
|
||||||
action(ptr, dst, size);
|
action(ptr, dst, size);
|
||||||
dst = unsafe { dst.add(size) };
|
dst = unsafe { dst.add(size) };
|
||||||
}
|
}
|
||||||
Some(Err(AddrSplitError { addr, size })) => {
|
Some(Err(AddrPageLookupError { addr, size })) => {
|
||||||
// Execute page fault handler
|
// Execute page fault handler
|
||||||
if traph.page_fault(reason, self, addr, size, dst) {
|
if traph.page_fault(reason, self, addr, size, dst) {
|
||||||
// Shift the splitter address
|
// Shift the splitter address
|
||||||
|
@ -252,7 +271,7 @@ impl Memory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result from address split
|
/// Result from address split
|
||||||
struct AddrSplitOk {
|
struct AddrPageLookupOk {
|
||||||
/// Virtual address
|
/// Virtual address
|
||||||
vaddr: u64,
|
vaddr: u64,
|
||||||
|
|
||||||
|
@ -266,7 +285,7 @@ struct AddrSplitOk {
|
||||||
perm: Permission,
|
perm: Permission,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AddrSplitError {
|
struct AddrPageLookupError {
|
||||||
/// Address of failure
|
/// Address of failure
|
||||||
addr: u64,
|
addr: u64,
|
||||||
|
|
||||||
|
@ -275,7 +294,7 @@ struct AddrSplitError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Address splitter into pages
|
/// Address splitter into pages
|
||||||
struct AddrSplitter {
|
struct AddrPageLookuper {
|
||||||
/// Current address
|
/// Current address
|
||||||
addr: u64,
|
addr: u64,
|
||||||
|
|
||||||
|
@ -286,7 +305,7 @@ struct AddrSplitter {
|
||||||
pagetable: *const PageTable,
|
pagetable: *const PageTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddrSplitter {
|
impl AddrPageLookuper {
|
||||||
/// Create a new page splitter
|
/// Create a new page splitter
|
||||||
pub const fn new(addr: u64, size: usize, pagetable: *const PageTable) -> Self {
|
pub const fn new(addr: u64, size: usize, pagetable: *const PageTable) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -303,8 +322,8 @@ impl AddrSplitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for AddrSplitter {
|
impl Iterator for AddrPageLookuper {
|
||||||
type Item = Result<AddrSplitOk, AddrSplitError>;
|
type Item = Result<AddrPageLookupOk, AddrPageLookupError>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
// The end, everything is fine
|
// The end, everything is fine
|
||||||
|
@ -328,7 +347,7 @@ impl Iterator for AddrSplitter {
|
||||||
match entry.permission() {
|
match entry.permission() {
|
||||||
// No page → page fault
|
// No page → page fault
|
||||||
Permission::Empty => {
|
Permission::Empty => {
|
||||||
return Some(Err(AddrSplitError {
|
return Some(Err(AddrPageLookupError {
|
||||||
addr: self.addr,
|
addr: self.addr,
|
||||||
size: PageSize::from_lvl(lvl)?,
|
size: PageSize::from_lvl(lvl)?,
|
||||||
}))
|
}))
|
||||||
|
@ -358,7 +377,7 @@ impl Iterator for AddrSplitter {
|
||||||
let avail = (size as usize - offset).clamp(0, self.size);
|
let avail = (size as usize - offset).clamp(0, self.size);
|
||||||
self.bump(size);
|
self.bump(size);
|
||||||
|
|
||||||
Some(Ok(AddrSplitOk {
|
Some(Ok(AddrPageLookupOk {
|
||||||
vaddr: self.addr,
|
vaddr: self.addr,
|
||||||
ptr: unsafe { base.add(offset) }, // Return pointer to the start of region
|
ptr: unsafe { base.add(offset) }, // Return pointer to the start of region
|
||||||
size: avail,
|
size: avail,
|
||||||
|
|
|
@ -259,8 +259,9 @@ impl<'a, PfHandler: HandlePageFault, const TIMER_QUOTIENT: usize>
|
||||||
usize::from(count),
|
usize::from(count),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
JMP => {
|
JAL => {
|
||||||
let ParamBD(reg, offset) = param!(self, ParamBD);
|
let ParamBBD(save, reg, offset) = param!(self, ParamBBD);
|
||||||
|
self.write_reg(save, self.pc as u64);
|
||||||
self.pc = (self.read_reg(reg).as_u64() + offset) as usize;
|
self.pc = (self.read_reg(reg).as_u64() + offset) as usize;
|
||||||
}
|
}
|
||||||
JEQ => cond_jump!(self, int, Equal),
|
JEQ => cond_jump!(self, int, Equal),
|
||||||
|
|
8
spec.md
8
spec.md
|
@ -166,11 +166,11 @@
|
||||||
## Control flow
|
## Control flow
|
||||||
|
|
||||||
### Unconditional jump
|
### Unconditional jump
|
||||||
- Type BD
|
- Type BBD
|
||||||
|
|
||||||
| Opcode | Name | Action |
|
| Opcode | Name | Action |
|
||||||
|:------:|:----:|:---------------------:|
|
|:------:|:----:|:-------------------------------------------------:|
|
||||||
| 32 | JMP | Jump at `#0 + imm #1` |
|
| 32 | JAL | Save current PC to `#0` and jump at `#1 + imm #2` |
|
||||||
|
|
||||||
### Conditional jumps
|
### Conditional jumps
|
||||||
- Type BBD
|
- Type BBD
|
||||||
|
|
Loading…
Reference in a new issue