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

fix: clippy #319

Merged
merged 4 commits into from
Apr 4, 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
26 changes: 26 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ edition = "2021"
align-address = "0.1"
hermit-entry = { version = "0.9", features = ["loader"] }
log = "0.4"
one-shot-mutex = "0.1"
sptr = "0.3"
take-static = "0.1"
vm-fdt = { version = "0.3", default-features = false, features = ["alloc"] }

[features]
Expand Down
51 changes: 27 additions & 24 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn output_message_byte(byte: u8) {
}

pub unsafe fn get_memory(_memory_size: u64) -> u64 {
(ptr::addr_of!(kernel_end).addr() as u64).align_up(LargePageSize::SIZE as u64)
(unsafe { ptr::addr_of!(kernel_end) }.addr() as u64).align_up(LargePageSize::SIZE as u64)
}

pub fn find_kernel() -> &'static [u8] {
Expand Down Expand Up @@ -159,21 +159,21 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = ptr::addr_of!(l1_pgtable).addr() as u64 + PT_PT;
pgt_slice[511] = ptr::addr_of!(l0_pgtable).addr() as u64 + PT_PT + PT_SELF;
pgt_slice[0] = unsafe { ptr::addr_of!(l1_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[511] = unsafe { ptr::addr_of!(l0_pgtable) }.addr() as u64 + PT_PT + PT_SELF;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l1_pgtable), 512) };
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = ptr::addr_of!(l2_pgtable).addr() as u64 + PT_PT;
pgt_slice[1] = ptr::addr_of!(l2k_pgtable).addr() as u64 + PT_PT;
pgt_slice[0] = unsafe { ptr::addr_of!(l2_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[1] = unsafe { ptr::addr_of!(l2k_pgtable) }.addr() as u64 + PT_PT;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l2_pgtable), 512) };
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = ptr::addr_of!(l3_pgtable).addr() as u64 + PT_PT;
pgt_slice[0] = unsafe { ptr::addr_of!(l3_pgtable) }.addr() as u64 + PT_PT;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l3_pgtable), 512) };
for i in pgt_slice.iter_mut() {
Expand All @@ -187,8 +187,9 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
*i = 0;
}
for (i, pgt_slice) in pgt_slice.iter_mut().enumerate().take(10) {
*pgt_slice =
ptr::addr_of!(L0mib_pgtable).addr() as u64 + (i * BasePageSize::SIZE) as u64 + PT_PT;
*pgt_slice = unsafe { ptr::addr_of!(L0mib_pgtable) }.addr() as u64
+ (i * BasePageSize::SIZE) as u64
+ PT_PT;
}

let pgt_slice =
Expand Down Expand Up @@ -227,7 +228,12 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
}

let current_stack_address = load_info.kernel_image_addr_range.start - KERNEL_STACK_SIZE as u64;
pub static mut BOOT_INFO: Option<RawBootInfo> = None;

take_static::take_static! {
static RAW_BOOT_INFO: Option<RawBootInfo> = None;
}

let raw_boot_info = RAW_BOOT_INFO.take().unwrap();

let dtb = unsafe {
Dtb::from_raw(sptr::from_exposed_addr(DEVICE_TREE as usize))
Expand All @@ -246,22 +252,19 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
let ram_start = u64::from_be_bytes(start_slice.try_into().unwrap());
let ram_size = u64::from_be_bytes(size_slice.try_into().unwrap());

let boot_info = {
let boot_info = BootInfo {
hardware_info: HardwareInfo {
phys_addr_range: ram_start..ram_start + ram_size,
serial_port_base: SerialPortBase::new(0x1000),
device_tree: core::num::NonZeroU64::new(DEVICE_TREE),
},
load_info,
platform_info: PlatformInfo::LinuxBoot,
};
RawBootInfo::from(boot_info)
let boot_info = BootInfo {
hardware_info: HardwareInfo {
phys_addr_range: ram_start..ram_start + ram_size,
serial_port_base: SerialPortBase::new(0x1000),
device_tree: core::num::NonZeroU64::new(DEVICE_TREE),
},
load_info,
platform_info: PlatformInfo::LinuxBoot,
};

unsafe {
BOOT_INFO = Some(boot_info);
}
info!("boot_info = {boot_info:#?}");
let boot_info_ptr = raw_boot_info.insert(RawBootInfo::from(boot_info));
info!("boot_info at {boot_info_ptr:p}");

// Jump to the kernel entry point and provide the Multiboot information to it.
info!(
Expand Down Expand Up @@ -291,7 +294,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
"br {entry}",
stack_address = in(reg) current_stack_address,
entry = in(reg) entry_point,
in("x0") BOOT_INFO.as_ref().unwrap(),
in("x0") boot_info_ptr,
in("x1") 0,
options(noreturn)
)
Expand Down
78 changes: 38 additions & 40 deletions src/arch/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,47 +100,45 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {

info!("hart_id = {}", start::get_hart_id());

static mut BOOT_INFO: Option<RawBootInfo> = None;

let boot_info = {
let phys_addr_range = {
let memory = fdt.memory();
let mut regions = memory.regions();

let mem_region = regions.next().unwrap();
assert!(
regions.next().is_none(),
"hermit-loader can only handle one memory region yet"
);

let mem_base = u64::try_from(mem_region.starting_address.addr()).unwrap();
let mem_size = u64::try_from(mem_region.size.unwrap()).unwrap();
mem_base..mem_base + mem_size
};

let device_tree = {
let fdt_addr = start::get_fdt_ptr().expose_addr();
DeviceTreeAddress::new(fdt_addr.try_into().unwrap())
};

let boot_info = BootInfo {
hardware_info: HardwareInfo {
phys_addr_range,
serial_port_base: None,
device_tree,
},
load_info,
platform_info: PlatformInfo::LinuxBoot,
};

info!("boot_info = {boot_info:#?}");

RawBootInfo::from(boot_info)
take_static::take_static! {
static RAW_BOOT_INFO: Option<RawBootInfo> = None;
}

let raw_boot_info = RAW_BOOT_INFO.take().unwrap();

let phys_addr_range = {
let memory = fdt.memory();
let mut regions = memory.regions();

let mem_region = regions.next().unwrap();
assert!(
regions.next().is_none(),
"hermit-loader can only handle one memory region yet"
);

let mem_base = u64::try_from(mem_region.starting_address.addr()).unwrap();
let mem_size = u64::try_from(mem_region.size.unwrap()).unwrap();
mem_base..mem_base + mem_size
};

unsafe {
BOOT_INFO = Some(boot_info);
}
let device_tree = {
let fdt_addr = start::get_fdt_ptr().expose_addr();
DeviceTreeAddress::new(fdt_addr.try_into().unwrap())
};

let boot_info = BootInfo {
hardware_info: HardwareInfo {
phys_addr_range,
serial_port_base: None,
device_tree,
},
load_info,
platform_info: PlatformInfo::LinuxBoot,
};

info!("boot_info = {boot_info:#?}");
let boot_info_ptr = raw_boot_info.insert(RawBootInfo::from(boot_info));
info!("boot_info at {boot_info_ptr:p}");

// Check expected signature of entry function
let entry: Entry = {
Expand All @@ -158,7 +156,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
entry = in(reg) entry,
stack = in(reg) start::get_stack_ptr(),
in("a0") start::get_hart_id(),
in("a1") BOOT_INFO.as_ref().unwrap(),
in("a1") boot_info_ptr,
options(noreturn)
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/arch/x86_64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use alloc::format;
use multiboot::information::{MemoryType, Multiboot};
use vm_fdt::{Error as FdtError, FdtWriter};

use super::{mb_info, MEM};
use super::{mb_info, Mem};

pub struct DeviceTree;

impl DeviceTree {
#[cfg(all(target_os = "none", not(feature = "fc")))]
pub fn create() -> Result<&'static [u8], FdtError> {
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut MEM).unwrap() };
let mut mem = Mem;
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };

let all_regions = multiboot
.memory_regions()
Expand Down
Loading