Skip to content

Commit

Permalink
build: Use Replace log macros
Browse files Browse the repository at this point in the history
Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Jul 5, 2024
1 parent 93acb48 commit 1562c1f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/arch/x86_64/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2020 Google LLC

use core::cell::SyncUnsafeCell;
use log::info;
use x86_64::{
registers::control::Cr3,
structures::paging::{PageSize, PageTable, PageTableFlags, PhysFrame, Size2MiB},
Expand All @@ -25,7 +26,7 @@ pub fn setup() {
// SAFETY: This function is idempontent and only writes to static memory and
// CR3. Thus, it is safe to run multiple times or on multiple threads.
let (l4, l3, l2s) = unsafe { (L4_TABLE.get_mut(), L3_TABLE.get_mut(), L2_TABLES.get_mut()) };
log!("Setting up {} GiB identity mapping", ADDRESS_SPACE_GIB);
info!("Setting up {} GiB identity mapping", ADDRESS_SPACE_GIB);
let pt_flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;

// Setup Identity map using L2 huge pages
Expand All @@ -51,7 +52,7 @@ pub fn setup() {
if cr3_frame != l4_frame {
unsafe { Cr3::write(l4_frame, cr3_flags) };
}
log!("Page tables setup");
info!("Page tables setup");
}

// Map a virtual address to a PhysAddr (assumes identity mapping)
Expand Down
3 changes: 2 additions & 1 deletion src/efi/device_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::{
ptr::null_mut,
};

use log::error;
use r_efi::{
efi::{self, MemoryType, Status},
protocols::device_path::Protocol as DevicePathProtocol,
Expand Down Expand Up @@ -49,7 +50,7 @@ impl DevicePath {
}

if dpp.r#type == r_efi::protocols::device_path::TYPE_END && dpp.sub_type == 0xff {
log!("Unexpected end of device path");
error!("Unexpected end of device path");
return DevicePath::Unsupported;
}
let len = unsafe { core::mem::transmute::<[u8; 2], u16>(dpp.length) };
Expand Down
3 changes: 2 additions & 1 deletion src/efi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use core::ffi::c_void;

use log::error;
use r_efi::{
efi::{self, Char16, Guid, Status},
protocols::{
Expand Down Expand Up @@ -51,7 +52,7 @@ pub extern "efiapi" fn open(
match &wrapper.node {
crate::fat::Node::Directory(d) => d,
_ => {
log!("Attempt to open from non-directory is unsupported");
error!("Attempt to open from non-directory is unsupported");
return Status::UNSUPPORTED;
}
}
Expand Down
35 changes: 18 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#[cfg(all(not(test), not(feature = "integration_tests")))]
use core::panic::PanicInfo;

use log::{error, info, warn};
#[cfg(all(
not(test),
not(feature = "integration_tests"),
Expand Down Expand Up @@ -112,70 +113,70 @@ fn boot_from_device(
info: &dyn bootinfo::Info,
) -> Result<(), Error> {
if let Err(err) = device.init() {
log!("Error configuring block device: {:?}", err);
error!("Error configuring block device: {:?}", err);
return Err(Error::Virtio(err));
}
log!(
info!(
"Virtio block device configured. Capacity: {} sectors",
device.get_capacity()
);

let (start, end) = match part::find_efi_partition(device) {
Ok(p) => p,
Err(err) => {
log!("Failed to find EFI partition: {:?}", err);
error!("Failed to find EFI partition: {:?}", err);
return Err(Error::Partition(err));
}
};
log!("Found EFI partition");
info!("Found EFI partition");

let mut f = fat::Filesystem::new(device, start, end);
if let Err(err) = f.init() {
log!("Failed to create filesystem: {:?}", err);
error!("Failed to create filesystem: {:?}", err);
return Err(Error::Fat(err));
}
log!("Filesystem ready");
info!("Filesystem ready");

match loader::load_default_entry(&f, info) {
Ok(mut kernel) => {
log!("Jumping to kernel");
info!("Jumping to kernel");
kernel.boot();
return Ok(());
}
Err(err) => {
log!("Error loading default entry: {:?}", err);
warn!("Error loading default entry: {:?}", err);
// Fall through to EFI boot
}
}

log!("Using EFI boot.");
info!("Using EFI boot.");

let mut file = match f.open(efi::EFI_BOOT_PATH) {
Ok(file) => file,
Err(err) => {
log!("Failed to load default EFI binary: {:?}", err);
error!("Failed to load default EFI binary: {:?}", err);
return Err(Error::Fat(err));
}
};
log!("Found bootloader: {}", efi::EFI_BOOT_PATH);
info!("Found bootloader: {}", efi::EFI_BOOT_PATH);

let mut l = pe::Loader::new(&mut file);

let (entry_addr, load_addr, size) = match l.load(info.kernel_load_addr()) {
Ok(load_info) => load_info,
Err(err) => {
log!("Error loading executable: {:?}", err);
error!("Error loading executable: {:?}", err);
return Err(Error::Pe(err));
}
};

#[cfg(target_arch = "aarch64")]
if code_range().start < (info.kernel_load_addr() + size) as usize {
log!("Error Boot Image is too large");
error!("Error Boot Image is too large");
return Err(Error::ImageTooLarge);
}

log!("Executable loaded");
info!("Executable loaded");
efi::efi_exec(entry_addr, load_addr, size, info, &f, device);
Ok(())
}
Expand Down Expand Up @@ -231,7 +232,7 @@ pub extern "C" fn rust64_start(a0: u64, a1: *const u8) -> ! {
serial::PORT.borrow_mut().init();
logger::init();

log!("Starting on RV64 0x{:x} 0x{:x}", a0, a1 as u64,);
info!("Starting on RV64 0x{:x} 0x{:x}", a0, a1 as u64,);

let info = fdt::StartInfo::new(
a1,
Expand All @@ -247,7 +248,7 @@ pub extern "C" fn rust64_start(a0: u64, a1: *const u8) -> ! {

for i in 0..info.num_entries() {
let region = info.entry(i);
log!(
info!(
"Memory region {}MiB@0x{:x}",
region.size / 1024 / 1024,
region.addr
Expand All @@ -262,7 +263,7 @@ pub extern "C" fn rust64_start(a0: u64, a1: *const u8) -> ! {
}

fn main(info: &dyn bootinfo::Info) -> ! {
log!("\nBooting with {}", info.name());
info!("Booting with {}", info.name());

pci::print_bus();

Expand Down
29 changes: 10 additions & 19 deletions src/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use atomic_refcell::AtomicRefCell;

use log::{info, warn};
#[cfg(target_arch = "x86_64")]
use x86_64::instructions::port::{Port, PortWriteOnly};

Expand Down Expand Up @@ -152,11 +153,9 @@ pub fn print_bus() {
if vendor_id == INVALID_VENDOR_ID {
continue;
}
log!(
info!(
"Found PCI device vendor={:x} device={:x} in slot={}",
vendor_id,
device_id,
device
vendor_id, device_id, device
);
}
}
Expand Down Expand Up @@ -251,13 +250,9 @@ impl PciDevice {
self.vendor_id = vendor_id;
self.device_id = device_id;

log!(
info!(
"PCI Device: {}:{}.{} {:x}:{:x}",
self.bus,
self.device,
self.func,
self.vendor_id,
self.device_id
self.bus, self.device, self.func, self.vendor_id, self.device_id
);

// Enable responses in memory space
Expand Down Expand Up @@ -328,11 +323,9 @@ impl PciDevice {

#[allow(clippy::disallowed_names)]
for bar in &self.bars {
log!(
info!(
"Bar: type={:?} address=0x{:x} size=0x{:x}",
bar.bar_type,
bar.address,
bar.size
bar.bar_type, bar.address, bar.size
);
}
}
Expand Down Expand Up @@ -379,11 +372,9 @@ impl PciDevice {

#[allow(clippy::disallowed_names)]
for bar in &self.bars {
log!(
info!(
"Updated BARs: type={:?} address={:x} size={:x}",
bar.bar_type,
bar.address,
bar.size
bar.bar_type, bar.address, bar.size
);
}

Expand Down Expand Up @@ -445,7 +436,7 @@ impl VirtioTransport for VirtioPciTransport {

// bit 4 of status is capability bit
if status & 1 << 4 == 0 {
log!("No capabilities detected");
warn!("No capabilities detected");
return Err(VirtioError::UnsupportedDevice);
}

Expand Down

0 comments on commit 1562c1f

Please sign in to comment.