Skip to content

Commit

Permalink
Format source with cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncouture committed Jan 3, 2023
1 parent 5a0ca99 commit a0fb1d4
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 44 deletions.
2 changes: 1 addition & 1 deletion api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
(97, 9),
(106, 9),
(115, 9),
(124, 1)
(124, 1),
];

let mut code = String::new();
Expand Down
1 change: 0 additions & 1 deletion api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ impl BootloaderConfig {
},
);


let buf = concat_115_9(
buf,
match minimum_framebuffer_width {
Expand Down
8 changes: 1 addition & 7 deletions bios/stage-2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
let kernel_len = load_file("kernel-x86_64", KERNEL_DST, &mut fs, &mut disk, disk_buffer);
writeln!(screen::Writer, "kernel loaded at {KERNEL_DST:#p}").unwrap();
writeln!(screen::Writer, "Loading ramdisk...").unwrap();
let ramdisk_len = match try_load_file(
"ramdisk",
RAMDISK_DST,
&mut fs,
&mut disk,
disk_buffer,
) {
let ramdisk_len = match try_load_file("ramdisk", RAMDISK_DST, &mut fs, &mut disk, disk_buffer) {
Some(s) => s,
None => 0u64,
};
Expand Down
12 changes: 8 additions & 4 deletions bios/stage-4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ pub extern "C" fn _start(info: &mut BiosInfo) -> ! {
PhysAddr::new(info.kernel.start)
};
let kernel_size = info.kernel.len;
let mut frame_allocator = if info.ramdisk.start == 0 {
let mut frame_allocator = if info.ramdisk.start == 0 {
let kernel_end = PhysFrame::containing_address(kernel_start + kernel_size - 1u64);
let next_free = kernel_end + 1;
LegacyFrameAllocator::new_starting_at(
next_free,
memory_map.iter().copied().map(MemoryRegion),
)
} else {
let ramdisk_end = PhysFrame::containing_address(PhysAddr::new( info.ramdisk.start + info.ramdisk.len));
let next_free = ramdisk_end+1;
LegacyFrameAllocator::new_starting_at(next_free, memory_map.iter().copied().map(MemoryRegion))
let ramdisk_end =
PhysFrame::containing_address(PhysAddr::new(info.ramdisk.start + info.ramdisk.len));
let next_free = ramdisk_end + 1;
LegacyFrameAllocator::new_starting_at(
next_free,
memory_map.iter().copied().map(MemoryRegion),
)
};

// We identity-mapped all memory, so the offset between physical and virtual addresses is 0
Expand Down
30 changes: 18 additions & 12 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ where
&mut page_tables,
system_info.framebuffer.as_ref(),
&config,
&system_info
&system_info,
);
let boot_info = create_boot_info(
&config,
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn set_up_mappings<I, D>(
page_tables: &mut PageTables,
framebuffer: Option<&RawFrameBufferInfo>,
config: &BootloaderConfig,
system_info: &SystemInfo
system_info: &SystemInfo,
) -> Mappings
where
I: ExactSizeIterator<Item = D> + Clone,
Expand Down Expand Up @@ -272,21 +272,24 @@ where
};
let ramdisk_slice_len = system_info.ramdisk_len;
let ramdisk_slice_start = if let Some(ramdisk_address) = system_info.ramdisk_addr {

let ramdisk_address_start = mapping_addr(
config.mappings.ramdisk_memory,
system_info.ramdisk_len,
8,
&mut used_entries
config.mappings.ramdisk_memory,
system_info.ramdisk_len,
8,
&mut used_entries,
);
let physical_address = PhysAddr::new(ramdisk_address);
let ramdisk_physical_start_page: PhysFrame<Size4KiB> = PhysFrame::containing_address(physical_address);
let ramdisk_physical_start_page: PhysFrame<Size4KiB> =
PhysFrame::containing_address(physical_address);
let ramdisk_page_count = (system_info.ramdisk_len - 1 / Size4KiB::SIZE) + 1;
let ramdisk_physical_end_page = ramdisk_physical_start_page + ramdisk_page_count;
let start_page = Page::containing_address(ramdisk_address_start);

let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
for (i, frame) in PhysFrame::range_inclusive(ramdisk_physical_start_page, ramdisk_physical_end_page).enumerate() {
for (i, frame) in
PhysFrame::range_inclusive(ramdisk_physical_start_page, ramdisk_physical_end_page)
.enumerate()
{
let page = start_page + i as u64;
match unsafe { kernel_page_table.map_to(page, frame, flags, frame_allocator) } {
Ok(tlb) => tlb.ignore(),
Expand Down Expand Up @@ -375,7 +378,7 @@ where
kernel_slice_start,
kernel_slice_len,
ramdisk_slice_start,
ramdisk_slice_len
ramdisk_slice_len,
}
}

Expand All @@ -402,7 +405,7 @@ pub struct Mappings {
/// Size of the kernel slice allocation in memory.
pub kernel_slice_len: u64,
pub ramdisk_slice_start: Option<VirtAddr>,
pub ramdisk_slice_len: u64
pub ramdisk_slice_len: u64,
}

/// Allocates and initializes the boot info struct and the memory map.
Expand Down Expand Up @@ -512,7 +515,10 @@ where
info.recursive_index = mappings.recursive_index.map(Into::into).into();
info.rsdp_addr = system_info.rsdp_addr.map(|addr| addr.as_u64()).into();
info.tls_template = mappings.tls_template.into();
info.ramdisk_addr = mappings.ramdisk_slice_start.map(|addr| addr.as_u64()).into();
info.ramdisk_addr = mappings
.ramdisk_slice_start
.map(|addr| addr.as_u64())
.into();
info.ramdisk_len = mappings.ramdisk_slice_len;
info
});
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ impl UefiBoot {
Some(rd) => Some(rd.as_path()),
None => None,
};
pxe::create_uefi_tftp_folder(bootloader_path, self.kernel.as_path(), ramdisk_path, out_path)
.context("failed to create UEFI PXE tftp folder")?;
pxe::create_uefi_tftp_folder(
bootloader_path,
self.kernel.as_path(),
ramdisk_path,
out_path,
)
.context("failed to create UEFI PXE tftp folder")?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/pxe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn create_uefi_tftp_folder(
to.display()
)
})?;
}
}

Ok(())
}
3 changes: 1 addition & 2 deletions tests/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ pub fn run_test_kernel(kernel_binary_path: &str, ramdisk_path: Option<&str>) {
let kernel_path = Path::new(kernel_binary_path);
let ramdisk_path = match ramdisk_path {
Some(rdp) => Some(Path::new(rdp)),
None => None
None => None,
};

// create an MBR disk image for legacy BIOS booting
let mbr_path = kernel_path.with_extension("mbr");
let mut bios_builder = bootloader::BiosBoot::new(kernel_path);


// create a GPT disk image for UEFI booting
let gpt_path = kernel_path.with_extension("gpt");
let mut uefi_builder = bootloader::UefiBoot::new(kernel_path);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_kernels/default_settings/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use bootloader_api::{entry_point, BootInfo};
use core::fmt::Write;
use test_kernel_default_settings::{exit_qemu, QemuExitCode, serial};
use test_kernel_default_settings::{exit_qemu, serial, QemuExitCode};

entry_point!(kernel_main);

Expand Down
15 changes: 9 additions & 6 deletions tests/test_kernels/ramdisk/src/bin/ramdisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
#![no_main] // disable all Rust-level entry points

use bootloader_api::{entry_point, BootInfo};
use test_kernel_ramdisk::{exit_qemu, QemuExitCode, RAMDISK_CONTENTS, serial};
use core::{fmt::Write, ptr::slice_from_raw_parts};


use test_kernel_ramdisk::{exit_qemu, serial, QemuExitCode, RAMDISK_CONTENTS};

entry_point!(kernel_main);

fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
writeln!(serial(), "Boot info: {:?}", boot_info).unwrap();
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
writeln!(serial(), "Boot info: {:?}", boot_info).unwrap();
assert!(boot_info.ramdisk_addr.into_option().is_some());
assert_eq!(boot_info.ramdisk_len as usize, RAMDISK_CONTENTS.len());
let actual_ramdisk = unsafe { &*slice_from_raw_parts(boot_info.ramdisk_addr.into_option().unwrap() as *const u8, boot_info.ramdisk_len as usize) };
let actual_ramdisk = unsafe {
&*slice_from_raw_parts(
boot_info.ramdisk_addr.into_option().unwrap() as *const u8,
boot_info.ramdisk_len as usize,
)
};
writeln!(serial(), "Actual contents: {:?}", actual_ramdisk).unwrap();
assert_eq!(RAMDISK_CONTENTS, actual_ramdisk);

Expand Down
20 changes: 13 additions & 7 deletions uefi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use uefi::{
ProtocolPointer,
},
table::boot::{
AllocateType, MemoryType, OpenProtocolAttributes, OpenProtocolParams,
ScopedProtocol,
AllocateType, MemoryType, OpenProtocolAttributes, OpenProtocolParams, ScopedProtocol,
},
CStr16, CStr8,
};
Expand Down Expand Up @@ -133,7 +132,9 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
// We may hit this code twice, if the map allocation ends up spanning more pages.
let next_target_size = memory_map_size.map_size + (8 * memory_map_size.entry_size);
target_size = next_target_size;
st.boot_services().free_pool(ptr).expect("Failed to free temporary memory for memory map!");
st.boot_services()
.free_pool(ptr)
.expect("Failed to free temporary memory for memory map!");
continue;
}
break;
Expand Down Expand Up @@ -358,8 +359,7 @@ fn load_file_from_tftp_boot_server(
let filename = CStr8::from_bytes_with_nul(name.as_bytes()).unwrap();

// Determine the kernel file size.
let file_size = base_code
.tftp_get_file_size(&server_ip, &filename).ok()?;
let file_size = base_code.tftp_get_file_size(&server_ip, &filename).ok()?;
let kernel_size = usize::try_from(file_size).expect("The file size should fit into usize");

// Allocate some memory for the kernel file.
Expand Down Expand Up @@ -453,9 +453,15 @@ fn init_logger(st: &SystemTable<Boot>, config: BootloaderConfig) -> Option<RawFr
.get_handle_for_protocol::<GraphicsOutput>()
.ok()?;
let mut gop = unsafe {

st.boot_services()
.open_protocol::<GraphicsOutput>(OpenProtocolParams { handle: gop_handle, agent: st.boot_services().image_handle(), controller: None }, OpenProtocolAttributes::Exclusive)
.open_protocol::<GraphicsOutput>(
OpenProtocolParams {
handle: gop_handle,
agent: st.boot_services().image_handle(),
controller: None,
},
OpenProtocolAttributes::Exclusive,
)
.ok()?
};

Expand Down

0 comments on commit a0fb1d4

Please sign in to comment.