Skip to content

Commit 2ca6ebd

Browse files
committed
Resolve all remaining warnings and fix build with --all-targets
Makes the `panic` implementations conditional to fix errors when building with `cargo check --all-targets --all`. This also fixes the remaining rust-analyzer errors.
1 parent bb9e7af commit 2ca6ebd

File tree

25 files changed

+86
-48
lines changed

25 files changed

+86
-48
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ license = "MIT/Apache-2.0"
88
description = "An experimental x86_64 bootloader that works on both BIOS and UEFI systems."
99
repository = "https://github.com/rust-osdev/bootloader"
1010
edition = "2021"
11-
resolver = "2"
1211

1312
[workspace]
1413
members = [

api/src/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ impl Default for BootloaderConfig {
282282
}
283283
}
284284

285+
/// A semver-compatible version.
285286
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
286287
#[repr(C)]
287288
pub struct ApiVersion {
@@ -318,18 +319,22 @@ impl ApiVersion {
318319
}
319320
}
320321

322+
/// Returns the major version number.
321323
pub fn version_major(&self) -> u16 {
322324
self.version_major
323325
}
324326

327+
/// Returns the minor version number.
325328
pub fn version_minor(&self) -> u16 {
326329
self.version_minor
327330
}
328331

332+
/// Returns the patch version number.
329333
pub fn version_patch(&self) -> u16 {
330334
self.version_patch
331335
}
332336

337+
/// Returns whether this version is a pre-release, e.g., an alpha version.
333338
pub fn pre_release(&self) -> bool {
334339
self.pre_release
335340
}

api/src/info.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::config::ApiVersion;
2020
#[repr(C)]
2121
#[non_exhaustive]
2222
pub struct BootInfo {
23+
/// The version of the `bootloader_api` crate. Must match the `bootloader` version.
2324
pub api_version: ApiVersion,
2425
/// A map of the physical memory regions of the underlying machine.
2526
///
@@ -54,6 +55,9 @@ pub struct BootInfo {
5455
}
5556

5657
impl BootInfo {
58+
/// Create a new boot info structure with the given memory map.
59+
///
60+
/// The other fields are initialized with default values.
5761
pub fn new(memory_regions: MemoryRegions) -> Self {
5862
Self {
5963
api_version: ApiVersion::new_default(),
@@ -162,7 +166,13 @@ pub struct FrameBuffer {
162166
}
163167

164168
impl FrameBuffer {
165-
pub fn new(buffer_start: u64, info: FrameBufferInfo) -> Self {
169+
/// Creates a new framebuffer instance.
170+
///
171+
/// ## Safety
172+
///
173+
/// The given start address and info must describe a valid, accessible, and unaliased
174+
/// framebuffer.
175+
pub unsafe fn new(buffer_start: u64, info: FrameBufferInfo) -> Self {
166176
Self { buffer_start, info }
167177
}
168178

@@ -232,9 +242,13 @@ pub enum PixelFormat {
232242
/// Length might be larger than 1, check [`bytes_per_pixel`][FrameBufferInfo::bytes_per_pixel]
233243
/// for this.
234244
U8,
245+
/// Unknown pixel format.
235246
Unknown {
247+
/// Bit offset of the red value.
236248
red_position: u8,
249+
/// Bit offset of the green value.
237250
green_position: u8,
251+
/// Bit offset of the blue value.
238252
blue_position: u8,
239253
},
240254
}

bios/stage-2/src/screen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl Write for Writer {
2929
}
3030
}
3131

32+
#[cfg(all(not(test), target_os = "none"))]
3233
#[panic_handler]
33-
#[cfg(not(test))]
3434
pub fn panic(info: &core::panic::PanicInfo) -> ! {
3535
let _ = write!(Writer, "\nPANIC: ");
3636
if let Some(location) = info.location() {

bios/stage-4/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ fn detect_rsdp() -> Option<PhysAddr> {
227227
}
228228
}
229229

230+
#[cfg(all(not(test), target_os = "none"))]
230231
#[panic_handler]
231-
#[cfg(not(test))]
232232
fn panic(info: &core::panic::PanicInfo) -> ! {
233233
unsafe {
234234
bootloader_x86_64_common::logger::LOGGER

common/src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,18 @@ where
447447
let mut info = BootInfo::new(memory_regions.into());
448448
info.framebuffer = mappings
449449
.framebuffer
450-
.map(|addr| FrameBuffer::new(addr.as_u64(), system_info.framebuffer.expect("there shouldn't be a mapping for the framebuffer if there is not framebuffer").info))
450+
.map(|addr| unsafe {
451+
FrameBuffer::new(
452+
addr.as_u64(),
453+
system_info
454+
.framebuffer
455+
.expect(
456+
"there shouldn't be a mapping for the framebuffer if there is \
457+
no framebuffer",
458+
)
459+
.info,
460+
)
461+
})
451462
.into();
452463
info.physical_memory_offset = mappings.physical_memory_offset.map(VirtAddr::as_u64).into();
453464
info.recursive_index = mappings.recursive_index.map(Into::into).into();

tests/runner/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "bootloader_test_runner"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

tests/test_kernels/default_settings/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
name = "test_kernel_default_settings"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[dependencies]
88
bootloader_api = { path = "../../../api" }
9-
x86_64 = { version = "0.14.7", default-features = false, features = ["instructions", "inline_asm"] }
9+
x86_64 = { version = "0.14.7", default-features = false, features = [
10+
"instructions",
11+
"inline_asm",
12+
] }
1013
uart_16550 = "0.2.10"

tests/test_kernels/default_settings/src/bin/basic_boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_default_settings::{exit_qemu, QemuExitCode};
76

87
entry_point!(kernel_main);
@@ -13,7 +12,8 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1312

1413
/// This function is called on panic.
1514
#[panic_handler]
16-
fn panic(info: &PanicInfo) -> ! {
15+
#[cfg(not(test))]
16+
fn panic(info: &core::panic::PanicInfo) -> ! {
1717
use core::fmt::Write;
1818

1919
let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {}", info);

tests/test_kernels/default_settings/src/bin/check_boot_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, info::PixelFormat, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_default_settings::{exit_qemu, QemuExitCode};
76

87
entry_point!(kernel_main);
@@ -41,8 +40,9 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
4140
}
4241

4342
/// This function is called on panic.
43+
#[cfg(not(test))]
4444
#[panic_handler]
45-
fn panic(info: &PanicInfo) -> ! {
45+
fn panic(info: &core::panic::PanicInfo) -> ! {
4646
use core::fmt::Write;
4747

4848
let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {}", info);

tests/test_kernels/default_settings/src/bin/should_panic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
6-
use test_kernel_default_settings::{exit_qemu, QemuExitCode};
75

86
entry_point!(kernel_main);
97

@@ -12,7 +10,9 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1210
}
1311

1412
/// This function is called on panic.
13+
#[cfg(not(test))]
1514
#[panic_handler]
16-
fn panic(_info: &PanicInfo) -> ! {
15+
fn panic(_info: &core::panic::PanicInfo) -> ! {
16+
use test_kernel_default_settings::{exit_qemu, QemuExitCode};
1717
exit_qemu(QemuExitCode::Success);
1818
}

tests/test_kernels/higher_half/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cargo-features = ["profile-rustflags"]
44
name = "test_kernel_higher_half"
55
version = "0.1.0"
66
authors = ["Philipp Oppermann <[email protected]>"]
7-
edition = "2018"
7+
edition = "2021"
88

99
[dependencies]
1010
bootloader_api = { path = "../../../api" }

tests/test_kernels/higher_half/src/bin/basic_boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_higher_half::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
@@ -12,7 +11,8 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1211
}
1312

1413
/// This function is called on panic.
14+
#[cfg(not(test))]
1515
#[panic_handler]
16-
fn panic(_info: &PanicInfo) -> ! {
16+
fn panic(_info: &core::panic::PanicInfo) -> ! {
1717
exit_qemu(QemuExitCode::Failed);
1818
}

tests/test_kernels/higher_half/src/bin/check_boot_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, info::PixelFormat, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_higher_half::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
@@ -41,8 +40,9 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
4140
}
4241

4342
/// This function is called on panic.
43+
#[cfg(not(test))]
4444
#[panic_handler]
45-
fn panic(info: &PanicInfo) -> ! {
45+
fn panic(info: &core::panic::PanicInfo) -> ! {
4646
use core::fmt::Write;
4747

4848
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);

tests/test_kernels/higher_half/src/bin/should_panic.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
6-
use test_kernel_higher_half::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
5+
use test_kernel_higher_half::BOOTLOADER_CONFIG;
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
98

@@ -12,7 +11,10 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1211
}
1312

1413
/// This function is called on panic.
14+
#[cfg(not(test))]
1515
#[panic_handler]
16-
fn panic(_info: &PanicInfo) -> ! {
16+
fn panic(_info: &core::panic::PanicInfo) -> ! {
17+
use test_kernel_higher_half::{exit_qemu, QemuExitCode};
18+
1719
exit_qemu(QemuExitCode::Success);
1820
}

tests/test_kernels/higher_half/src/bin/verify_higher_half.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_higher_half::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
@@ -30,8 +29,9 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
3029
}
3130

3231
/// This function is called on panic.
32+
#[cfg(not(test))]
3333
#[panic_handler]
34-
fn panic(info: &PanicInfo) -> ! {
34+
fn panic(info: &core::panic::PanicInfo) -> ! {
3535
use core::fmt::Write;
3636

3737
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);

tests/test_kernels/lto/src/bin/basic_boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_lto::{exit_qemu, QemuExitCode};
76

87
entry_point!(kernel_main);
@@ -12,8 +11,9 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1211
}
1312

1413
/// This function is called on panic.
14+
#[cfg(not(test))]
1515
#[panic_handler]
16-
fn panic(info: &PanicInfo) -> ! {
16+
fn panic(info: &core::panic::PanicInfo) -> ! {
1717
use core::fmt::Write;
1818

1919
let _ = writeln!(test_kernel_lto::serial(), "PANIC: {}", info);

tests/test_kernels/map_phys_mem/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "test_kernel_map_phys_mem"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[target.'cfg(target_arch = "x86_64")'.dependencies]
88
bootloader_api = { path = "../../../api" }

tests/test_kernels/map_phys_mem/src/bin/access_phys_mem.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
6-
use test_kernel_map_phys_mem::{exit_qemu, serial, QemuExitCode, BOOTLOADER_CONFIG};
5+
use test_kernel_map_phys_mem::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
98

@@ -17,9 +16,11 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
1716
}
1817

1918
/// This function is called on panic.
19+
#[cfg(not(test))]
2020
#[panic_handler]
21-
fn panic(info: &PanicInfo) -> ! {
21+
fn panic(info: &core::panic::PanicInfo) -> ! {
2222
use core::fmt::Write;
23+
use test_kernel_map_phys_mem::serial;
2324

2425
let _ = writeln!(serial(), "PANIC: {}", info);
2526
exit_qemu(QemuExitCode::Failed);

tests/test_kernels/map_phys_mem/src/bin/check_boot_info.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, info::PixelFormat, BootInfo};
5-
use core::panic::PanicInfo;
6-
use test_kernel_map_phys_mem::{exit_qemu, serial, QemuExitCode, BOOTLOADER_CONFIG};
5+
use test_kernel_map_phys_mem::{exit_qemu, QemuExitCode, BOOTLOADER_CONFIG};
76

87
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
98

@@ -44,9 +43,11 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
4443
}
4544

4645
/// This function is called on panic.
46+
#[cfg(not(test))]
4747
#[panic_handler]
48-
fn panic(info: &PanicInfo) -> ! {
48+
fn panic(info: &core::panic::PanicInfo) -> ! {
4949
use core::fmt::Write;
50+
use test_kernel_map_phys_mem::serial;
5051

5152
let _ = writeln!(serial(), "PANIC: {}", info);
5253
exit_qemu(QemuExitCode::Failed);

tests/test_kernels/pie/src/bin/basic_boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main] // disable all Rust-level entry points
33

44
use bootloader_api::{entry_point, BootInfo};
5-
use core::panic::PanicInfo;
65
use test_kernel_pie::{exit_qemu, QemuExitCode};
76

87
entry_point!(kernel_main);
@@ -12,8 +11,9 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
1211
}
1312

1413
/// This function is called on panic.
14+
#[cfg(not(test))]
1515
#[panic_handler]
16-
fn panic(info: &PanicInfo) -> ! {
16+
fn panic(info: &core::panic::PanicInfo) -> ! {
1717
use core::fmt::Write;
1818

1919
let _ = writeln!(test_kernel_pie::serial(), "PANIC: {}", info);

0 commit comments

Comments
 (0)