Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/heavy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ jobs:

- name: Run Rustfmt
run: cargo fmt --verbose --all -- --check

11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
// These settings are mandatory when working in `no_std` environments.
// Otherwise, rust-analyzer will panic trying to find the standard library
// Prevent rust-analyzer from searching for `stdlib` in `no_std` environments
"rust-analyzer.check.allTargets": false,
"rust-analyzer.check.targets": [
"x86_64-unknown-none",
"x86_64-unknown-uefi"
],
"rust-analyzer.check.features": [],
// Do not trigger bindeps
"rust-analyzer.check.extraArgs": ["--exclude", "beskar-os"],
// Do not run build scripts
"rust-analyzer.cargo.buildScripts.enable": false,

// Optimization for large `no_std` projects
"rust-analyzer.lens.enable": false,
}
83 changes: 61 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/mathisbot/beskar-os/"
members = [
"bootloader",
"kernel",
"userspace/bashkar"
"userspace/*"
]

[workspace.dependencies]
Expand All @@ -27,10 +27,12 @@ xmas-elf = "0.10.0"
bootloader = { path = "bootloader", artifact = "bin", target = "x86_64-unknown-uefi" }
kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" }
bashkar = { path = "userspace/bashkar", artifact = "bin", target = "x86_64-unknown-none" }
# doom = { path = "userspace/doom", artifact = "bin", target = "x86_64-unknown-none" }

[profile.release]
panic = "abort"
lto = true
lto = "fat"
strip = "symbols"

[profile.dev]
panic = "abort"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Throughout the development process, I always follow four objectives:

I have many milestones ideas for the OS:

1. Being completely self-hosted
2. Successfully ping `1.1.1.1`
3. Run Doom?
- [X] Run Doom (see [Doom](userspace/doom/README.md))
- [ ] Successfully ping `1.1.1.1`
- [ ] Being completely self-hosted

## Design and architecture

Expand Down
2 changes: 1 addition & 1 deletion beskar-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2024"

[dependencies]
noto-sans-mono-bitmap = { version = "0.3.1", default-features = false, features = ["font_weights_default", "size_20", "unicode_ranges_all"] }
num_enum = { version = "0.7.3", default-features = false }
num_enum = { version = "0.7.4", default-features = false }
thiserror = { workspace = true }
44 changes: 41 additions & 3 deletions beskar-core/src/arch/addrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ pub struct VirtAddr(u64);
pub struct PhysAddr(u64);

impl VirtAddr {
pub const MAX: Self = Self(u64::MAX);
pub const ZERO: Self = Self(0);

#[must_use]
#[track_caller]
#[inline]
pub const fn new(addr: u64) -> Self {
Self::try_new(addr).expect("Invalid virtual address")
Expand Down Expand Up @@ -50,6 +54,26 @@ impl VirtAddr {
unsafe { Self::new_unchecked(ptr.cast::<()>() as u64) }
}

#[must_use]
#[inline]
/// Create a new virtual address from page table indices.
///
/// Indices will be truncated to 9 bits each, as per the x86-64 paging scheme.
pub fn from_pt_indices(
p4_index: u16,
p3_index: u16,
p2_index: u16,
p1_index: u16,
offset: u16,
) -> Self {
let addr = (u64::from(p4_index & 0x1FF) << 39)
| (u64::from(p3_index & 0x1FF) << 30)
| (u64::from(p2_index & 0x1FF) << 21)
| (u64::from(p1_index & 0x1FF) << 12)
| u64::from(offset & 0xFFF);
Self::new_extend(addr)
}

#[must_use]
#[inline]
/// # Safety
Expand Down Expand Up @@ -132,9 +156,11 @@ impl VirtAddr {
}

impl PhysAddr {
pub const MAX_VALID: u64 = 0x000F_FFFF_FFFF_FFFF;
pub const MAX: Self = Self(0x000F_FFFF_FFFF_FFFF);
pub const ZERO: Self = Self(0);

#[must_use]
#[track_caller]
#[inline]
pub const fn new(addr: u64) -> Self {
Self::try_new(addr).expect("Invalid physical address")
Expand All @@ -153,7 +179,7 @@ impl PhysAddr {
#[must_use]
#[inline]
pub const fn new_truncate(addr: u64) -> Self {
let truncated = addr & Self::MAX_VALID;
let truncated = addr & Self::MAX.0;
// Safety: We just truncated the address to fit in the valid range
unsafe { Self::new_unchecked(truncated) }
}
Expand Down Expand Up @@ -306,10 +332,22 @@ mod tests {

#[test]
fn test_v() {
let addr = PhysAddr::new(0x18000031060);
let addr = VirtAddr::new(0x18000031060);
assert_eq!(addr.as_u64(), 0x18000031060);
}

#[test]
fn test_v_from_idx() {
let addr = VirtAddr::new(0x18000031060);
let p4_index = addr.p4_index();
let p3_index = addr.p3_index();
let p2_index = addr.p2_index();
let p1_index = addr.p1_index();
let offset = u16::try_from(addr.as_u64() & 0xFFF).unwrap();
let same_addr = VirtAddr::from_pt_indices(p4_index, p3_index, p2_index, p1_index, offset);
assert_eq!(addr, same_addr);
}

#[test]
fn test_v_extends() {
let addr = VirtAddr::new_extend(0xFFFF_FFFF_FFFF);
Expand Down
Loading