Skip to content

Commit

Permalink
Restructure xtask, fix flag parsing
Browse files Browse the repository at this point in the history
Separate build into most distinct stages, each with their own argument parsing.  This suits clap better, and makes each step independent.

Combine qemu and qemukvm.

Fix parsing of profile flag arg (probably amongst others) - was always building in release mode.

Tidy memory map output in aarch64 by sorting.

Signed-off-by: Graham MacDonald <[email protected]>
  • Loading branch information
gmacd committed Dec 3, 2023
1 parent 5accf07 commit 58f59cd
Show file tree
Hide file tree
Showing 5 changed files with 636 additions and 523 deletions.
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
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

0 comments on commit 58f59cd

Please sign in to comment.