-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Usage with QEMU is similar to the x86 version: The loader is passed via "-kernel" and the application via "-initrd". Co-authored-by: Martin Kröning <[email protected]> Signed-off-by: Martin Kröning <[email protected]>
- Loading branch information
1 parent
910c125
commit 076dd18
Showing
12 changed files
with
461 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
#[cfg(target_arch = "aarch64")] | ||
pub use crate::arch::aarch64::*; | ||
#[cfg(target_arch = "riscv64")] | ||
pub use crate::arch::riscv64::*; | ||
#[cfg(target_arch = "x86_64")] | ||
pub use crate::arch::x86_64::*; | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
pub mod aarch64; | ||
|
||
#[cfg(target_arch = "riscv64")] | ||
pub mod riscv64; | ||
|
||
#[cfg(target_arch = "x86_64")] | ||
pub mod x86_64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// TODO: Move this into its own crate. | ||
#![allow(dead_code)] | ||
|
||
use core::cmp::Ordering; | ||
use core::fmt; | ||
use core::ops::Range; | ||
|
||
use align_address::Align; | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
pub struct AddressRange { | ||
start: usize, | ||
end: usize, | ||
} | ||
|
||
impl AddressRange { | ||
pub fn new(start: usize, end: usize) -> Option<Self> { | ||
(start <= end).then_some(Self { start, end }) | ||
} | ||
|
||
pub fn from_start_len(start: usize, len: usize) -> Self { | ||
Self { | ||
start, | ||
end: start + len, | ||
} | ||
} | ||
|
||
pub fn overlaps(self, other: Self) -> bool { | ||
self.partial_cmp(&other).is_none() | ||
} | ||
|
||
pub fn next(self, len: usize) -> Self { | ||
Self::from_start_len(self.end, len) | ||
} | ||
|
||
pub fn align_to(self, align: usize) -> Self { | ||
Self { | ||
start: self.start.align_down(align), | ||
end: self.end.align_up(align), | ||
} | ||
} | ||
|
||
pub fn start(self) -> usize { | ||
self.start | ||
} | ||
|
||
pub fn end(self) -> usize { | ||
self.end | ||
} | ||
|
||
pub fn len(self) -> usize { | ||
self.end - self.start | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct TryFromRangeError(()); | ||
|
||
impl<T> TryFrom<Range<*const T>> for AddressRange { | ||
type Error = TryFromRangeError; | ||
|
||
fn try_from(value: Range<*const T>) -> Result<Self, Self::Error> { | ||
Self::new(value.start as usize, value.end as usize).ok_or(TryFromRangeError(())) | ||
} | ||
} | ||
|
||
impl fmt::Display for AddressRange { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let Self { start, end } = self; | ||
let len = self.len(); | ||
write!(f, "{start:#x}..{end:#x} (len = {len:#10x})") | ||
} | ||
} | ||
|
||
impl PartialOrd for AddressRange { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
if self.end <= other.start { | ||
Some(Ordering::Less) | ||
} else if self.start >= other.end { | ||
Some(Ordering::Greater) | ||
} else if self == other { | ||
Some(Ordering::Equal) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ENTRY(_start) | ||
phys = 0x0000000080200000; | ||
|
||
SECTIONS | ||
{ | ||
kernel_start = phys; | ||
.text phys : AT(ADDR(.text)) { | ||
*(.text._start) | ||
*(.text.*) | ||
} | ||
.rodata ALIGN(4096) : AT(ADDR(.rodata)) { | ||
*(.rodata) | ||
*(.rodata.*) | ||
} | ||
.data ALIGN(4096) : AT(ADDR(.data)) { | ||
*(.data) | ||
*(.data.*) | ||
} | ||
.bss ALIGN(4096) : AT(ADDR(.bss)) { | ||
*(.bss) | ||
*(.bss.*) | ||
} | ||
.sbss ALIGN(4096) : AT(ADDR(.sbss)) { | ||
*(.sbss) | ||
*(.sbss.*) | ||
} | ||
kernel_end = .; | ||
} |
Oops, something went wrong.