Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure xtask, fix flag parsing #30

Merged
merged 2 commits into from
Jan 7, 2024
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
65 changes: 1 addition & 64 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Right now, r9 is not self-hosting.

## Runtime Dependencies

`cargo xtask dist`, which `cargo xtask qemu` and
`cargo xtask qemukvm` depend on, requires `llvm-objcopy`.
`cargo xtask dist`, which `cargo xtask qemu` depends on, requires `llvm-objcopy`.
This is expected to live in the rust toolchain path. You can install by running:
```
rustup component add llvm-tools
Expand All @@ -47,6 +46,7 @@ R9 can be run using qemu for the various supported architectures:
|----|-----------|
|aarch64|cargo xtask qemu --arch aarch64 --verbose|
|x86-64|cargo xtask qemu --arch x86-64 --verbose|
|x86-64 (with kvm)|cargo xtask qemu --arch x86-64 --kvm --verbose|
|riscv|cargo xtask qemu --arch riscv64 --verbose|

## Running on Real Hardware™️
Expand Down
2 changes: 1 addition & 1 deletion aarch64/src/kmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn eearly_pagetables_addr() -> usize {
unsafe { eearly_pagetables.as_ptr().addr() }
}

#[derive(Clone, Copy, PartialEq, PartialOrd)]
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
#[repr(transparent)]
pub struct PhysAddr(u64);

Expand Down
51 changes: 28 additions & 23 deletions aarch64/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,35 +470,40 @@ pub unsafe fn init(kpage_table: &mut PageTable, dtb_phys: PhysAddr, edtb_phys: P
write_volatile(&mut kpage_table.entries[511], entry);
}

let text_phys = PhysAddr::from_virt(text_addr());
let etext_phys = PhysAddr::from_virt(etext_addr());
let erodata_phys = PhysAddr::from_virt(erodata_addr());
let ebss_phys = PhysAddr::from_virt(ebss_addr());
let heap_phys = PhysAddr::from_virt(heap_addr());
let eheap_phys = PhysAddr::from_virt(eheap_addr());

let mmio = rpi_mmio().expect("mmio base detect failed");
let mmio_end = PhysAddr::from(mmio + (2 * PAGE_SIZE_2M as u64));

let custom_map = [
// TODO We don't actualy unmap the first page... We should to achieve:
// Note that the first page is left unmapped to try and
// catch null pointer dereferences in unsafe code: defense
// in depth!
("DTB", dtb_phys, edtb_phys, Entry::ro_kernel_data(), PageSize::Page4K),
("Kernel Text", text_phys, etext_phys, Entry::ro_kernel_text(), PageSize::Page2M),
("Kernel Data", etext_phys, erodata_phys, Entry::ro_kernel_data(), PageSize::Page2M),
("Kernel BSS", erodata_phys, ebss_phys, Entry::rw_kernel_data(), PageSize::Page2M),
("Kernel Heap", heap_phys, eheap_phys, Entry::rw_kernel_data(), PageSize::Page2M),
("MMIO", mmio, mmio_end, Entry::ro_kernel_device(), PageSize::Page2M),
];
// TODO We don't actualy unmap the first page... We should to achieve:
// Note that the first page is left unmapped to try and
// catch null pointer dereferences in unsafe code: defense
// in depth!
let custom_map = {
let text_phys = PhysAddr::from_virt(text_addr());
let etext_phys = PhysAddr::from_virt(etext_addr());
let erodata_phys = PhysAddr::from_virt(erodata_addr());
let ebss_phys = PhysAddr::from_virt(ebss_addr());
let heap_phys = PhysAddr::from_virt(heap_addr());
let eheap_phys = PhysAddr::from_virt(eheap_addr());

let mmio = rpi_mmio().expect("mmio base detect failed");
let mmio_end = PhysAddr::from(mmio + (2 * PAGE_SIZE_2M as u64));

let mut map = [
("DTB", dtb_phys, edtb_phys, Entry::ro_kernel_data(), PageSize::Page4K),
("Kernel Text", text_phys, etext_phys, Entry::ro_kernel_text(), PageSize::Page2M),
("Kernel Data", etext_phys, erodata_phys, Entry::ro_kernel_data(), PageSize::Page2M),
("Kernel BSS", erodata_phys, ebss_phys, Entry::rw_kernel_data(), PageSize::Page2M),
("Kernel Heap", heap_phys, eheap_phys, Entry::rw_kernel_data(), PageSize::Page2M),
("MMIO", mmio, mmio_end, Entry::ro_kernel_device(), PageSize::Page2M),
];
map.sort_by_key(|a| a.1);
map
};

println!("Memory map:");
for (name, start, end, flags, page_size) in custom_map.iter() {
let mapped_range = kpage_table
.map_phys_range(*start, *end, *flags, *page_size)
.expect("init mapping failed");
println!(
"Mapped {:16} {:#018x}-{:#018x} to {:#018x}-{:#018x} flags: {:?} page_size: {:?}",
" {:14}{:#018x}-{:#018x} to {:#018x}-{:#018x} flags: {:?} page_size: {:?}",
name,
start.addr(),
end.addr(),
Expand Down
2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
clap = { version = "4.2.4", features = ["derive"] }
rustup-configurator = "0.1.1"
serde = { version = "1.0.160", features = ["derive"] }
target-lexicon = { version = "0.12" }
toml = "0.8.0"
36 changes: 19 additions & 17 deletions xtask/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,25 @@ pub struct Configuration {
pub link: Option<HashMap<String, String>>,
}

pub fn read_config(filename: String) -> Configuration {
let contents = match fs::read_to_string(filename.clone()) {
Ok(c) => c,
Err(_) => {
eprintln!("Could not read file `{filename}`");
exit(1);
}
};
let config: Configuration = match toml::from_str(&contents) {
Ok(d) => d,
Err(e) => {
eprintln!("TOML: Unable to load data from `{}`", filename);
eprintln!("{e}");
exit(1);
}
};
config
impl Configuration {
pub fn load(filename: String) -> Self {
let contents = match fs::read_to_string(filename.clone()) {
Ok(c) => c,
Err(_) => {
eprintln!("Could not read file `{filename}`");
exit(1);
}
};
let config: Configuration = match toml::from_str(&contents) {
Ok(d) => d,
Err(e) => {
eprintln!("TOML: Unable to load data from `{}`", filename);
eprintln!("{e}");
exit(1);
}
};
config
}
}

/// task could be 'build', 'clippy'
Expand Down
Loading