Skip to content

Commit 2d61f27

Browse files
committed
edition 2021 -> 2024 fixes
1 parent 87f7b81 commit 2d61f27

File tree

11 files changed

+55
-48
lines changed

11 files changed

+55
-48
lines changed

api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ macro_rules! entry_point {
114114
};
115115
($path:path, config = $config:expr) => {
116116
const _: () = {
117-
#[link_section = ".bootloader-config"]
117+
#[unsafe(link_section = ".bootloader-config")]
118118
pub static __BOOTLOADER_CONFIG: [u8; $crate::BootloaderConfig::SERIALIZED_LEN] = {
119119
// validate the type
120120
let config: &$crate::BootloaderConfig = $config;
@@ -125,7 +125,7 @@ macro_rules! entry_point {
125125
static __BOOTLOADER_CONFIG_REF: &[u8; $crate::BootloaderConfig::SERIALIZED_LEN] =
126126
&__BOOTLOADER_CONFIG;
127127

128-
#[export_name = "_start"]
128+
#[unsafe(export_name = "_start")]
129129
pub extern "C" fn __impl_start(boot_info: &'static mut $crate::BootInfo) -> ! {
130130
// validate the signature of the program entry point
131131
let f: fn(&'static mut $crate::BootInfo) -> ! = $path;

bios/boot_sector/src/fail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<T, E> UnwrapOrFail for Result<T, E> {
2828
}
2929
}
3030

31-
#[no_mangle]
31+
#[unsafe(no_mangle)]
3232
pub extern "C" fn print_char(c: u8) {
3333
let ax = u16::from(c) | 0x0e00;
3434
unsafe {
@@ -38,7 +38,7 @@ pub extern "C" fn print_char(c: u8) {
3838

3939
#[cold]
4040
#[inline(never)]
41-
#[no_mangle]
41+
#[unsafe(no_mangle)]
4242
pub extern "C" fn fail(code: u8) -> ! {
4343
print_char(b'!');
4444
print_char(code);

bios/boot_sector/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod dap;
1111
mod fail;
1212
mod mbr;
1313

14-
extern "C" {
14+
unsafe extern "C" {
1515
static _partition_table: u8;
1616
static _second_stage_start: u8;
1717
}
@@ -25,7 +25,7 @@ fn second_stage_start() -> *const () {
2525
ptr as *const ()
2626
}
2727

28-
#[no_mangle]
28+
#[unsafe(no_mangle)]
2929
pub extern "C" fn first_stage(disk_number: u16) {
3030
// read partition table and look for second stage partition
3131
let partition_table = unsafe { slice::from_raw_parts(partition_table_raw(), 16 * 4) };

bios/stage-2/src/dap.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,22 @@ impl DiskAddressPacket {
3737

3838
pub unsafe fn perform_load(&self, disk_number: u16) {
3939
let self_addr = self as *const Self as u16;
40-
asm!(
41-
"push 'z'", // error code `z`, passed to `fail` on error
42-
"mov {1:x}, si",
43-
"mov si, {0:x}",
44-
"int 0x13",
45-
"jnc 2f", // carry is set on fail
46-
"call fail",
47-
"2:",
48-
"pop si", // remove error code again
49-
"mov si, {1:x}",
50-
in(reg) self_addr,
51-
out(reg) _,
52-
in("ax") 0x4200u16,
53-
in("dx") disk_number,
54-
);
40+
unsafe {
41+
asm!(
42+
"push 'z'", // error code `z`, passed to `fail` on error
43+
"mov {1:x}, si",
44+
"mov si, {0:x}",
45+
"int 0x13",
46+
"jnc 2f", // carry is set on fail
47+
"call fail",
48+
"2:",
49+
"pop si", // remove error code again
50+
"mov si, {1:x}",
51+
in(reg) self_addr,
52+
out(reg) _,
53+
in("ax") 0x4200u16,
54+
in("dx") disk_number,
55+
);
56+
}
5557
}
5658
}

bios/stage-2/src/disk.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl Read for DiskAccess {
1515
static mut TMP_BUF: AlignedArrayBuffer<1024> = AlignedArrayBuffer {
1616
buffer: [0; 512 * 2],
1717
};
18+
#[allow(static_mut_refs)]
1819
let buf = unsafe { &mut TMP_BUF };
1920
assert!(current_sector_offset + len <= buf.buffer.len());
2021

bios/stage-2/src/fat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<D: Read + Seek> FileSystem<D> {
205205
fn read_root_dir<'a>(
206206
&'a mut self,
207207
buffer: &'a mut (dyn AlignedBuffer + 'a),
208-
) -> impl Iterator<Item = Result<RawDirectoryEntry, ()>> + 'a {
208+
) -> impl Iterator<Item = Result<RawDirectoryEntry<'a>, ()>> + 'a {
209209
match self.bpb.fat_type() {
210210
FatType::Fat32 => {
211211
// self.bpb.root_cluster;
@@ -242,6 +242,7 @@ impl<D: Read + Seek> FileSystem<D> {
242242

243243
#[derive(Debug)]
244244
pub struct Cluster {
245+
#[allow(unused)]
245246
pub index: u32,
246247
pub start_offset: u64,
247248
pub len_bytes: u32,

bios/stage-2/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
copy_to_protected_mode, enter_protected_mode_and_jump_to_stage_3, enter_unreal_mode,
88
},
99
};
10-
use bootloader_x86_64_bios_common::{hlt, BiosFramebufferInfo, BiosInfo, Region};
10+
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, Region, hlt};
1111
use byteorder::{ByteOrder, LittleEndian};
1212
use core::{fmt::Write as _, slice};
1313
use disk::AlignedArrayBuffer;
@@ -35,8 +35,8 @@ static mut DISK_BUFFER: AlignedArrayBuffer<0x4000> = AlignedArrayBuffer {
3535
buffer: [0; 0x4000],
3636
};
3737

38-
#[no_mangle]
39-
#[link_section = ".start"]
38+
#[unsafe(no_mangle)]
39+
#[unsafe(link_section = ".start")]
4040
pub extern "C" fn _start(disk_number: u16, partition_table_start: *const u8) -> ! {
4141
start(disk_number, partition_table_start)
4242
}
@@ -87,6 +87,7 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
8787

8888
let mut fs = fat::FileSystem::parse(disk.clone());
8989

90+
#[allow(static_mut_refs)]
9091
let disk_buffer = unsafe { &mut DISK_BUFFER };
9192

9293
let stage_3_len = load_file("boot-stage-3", STAGE_3_DST, &mut fs, &mut disk, disk_buffer);
@@ -255,7 +256,7 @@ fn split_array_ref<const N: usize, T>(slice: &[T]) -> (&[T; N], &[T]) {
255256

256257
#[cold]
257258
#[inline(never)]
258-
#[no_mangle]
259+
#[unsafe(no_mangle)]
259260
pub extern "C" fn fail(code: u8) -> ! {
260261
panic!("fail: {}", code as char);
261262
}

bios/stage-2/src/protected_mode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,20 @@ pub fn enter_unreal_mode() {
8585
}
8686
}
8787

88-
#[no_mangle]
88+
#[unsafe(no_mangle)]
8989
pub unsafe fn copy_to_protected_mode(target: *mut u8, bytes: &[u8]) {
9090
for (offset, byte) in bytes.iter().enumerate() {
9191
let dst = target.wrapping_add(offset);
9292
// we need to do the write in inline assembly because the compiler
9393
// seems to truncate the address
9494
unsafe {
95-
asm!("mov [{}], {}", in(reg) dst, in(reg_byte) *byte, options(nostack, preserves_flags))
96-
};
97-
assert_eq!(read_from_protected_mode(dst), *byte);
95+
asm!("mov [{}], {}", in(reg) dst, in(reg_byte) *byte, options(nostack, preserves_flags));
96+
assert_eq!(read_from_protected_mode(dst), *byte);
97+
}
9898
}
9999
}
100100

101-
#[no_mangle]
101+
#[unsafe(no_mangle)]
102102
pub unsafe fn read_from_protected_mode(ptr: *mut u8) -> u8 {
103103
let res;
104104
// we need to do the read in inline assembly because the compiler

bios/stage-3/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#![deny(unsafe_op_in_unsafe_fn)]
44

55
use crate::screen::Writer;
6-
use bootloader_x86_64_bios_common::{hlt, BiosInfo};
6+
use bootloader_x86_64_bios_common::{BiosInfo, hlt};
77
use core::{arch::asm, fmt::Write as _};
88

99
mod gdt;
1010
mod paging;
1111
mod screen;
1212

13-
#[no_mangle]
14-
#[link_section = ".start"]
13+
#[unsafe(no_mangle)]
14+
#[unsafe(link_section = ".start")]
1515
pub extern "C" fn _start(info: &mut BiosInfo) {
1616
screen::init(info.framebuffer);
1717
// Writer.clear_screen();
@@ -29,7 +29,7 @@ pub extern "C" fn _start(info: &mut BiosInfo) {
2929
}
3030
}
3131

32-
#[no_mangle]
32+
#[unsafe(no_mangle)]
3333
pub fn enter_long_mode_and_jump_to_stage_4(info: &mut BiosInfo) {
3434
let _ = writeln!(Writer, "Paging init done, jumping to stage 4");
3535
unsafe {

bios/stage-4/src/main.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use bootloader_boot_config::{BootConfig, LevelFilter};
77
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, E820MemoryRegion};
88
use bootloader_x86_64_common::RawFrameBufferInfo;
99
use bootloader_x86_64_common::{
10-
legacy_memory_region::LegacyFrameAllocator, load_and_switch_to_kernel, Kernel, PageTables,
11-
SystemInfo,
10+
Kernel, PageTables, SystemInfo, legacy_memory_region::LegacyFrameAllocator,
11+
load_and_switch_to_kernel,
1212
};
1313
use core::{cmp, slice};
1414
use usize_conversions::usize_from;
@@ -22,8 +22,8 @@ const GIGABYTE: u64 = 4096 * 512 * 512;
2222

2323
mod memory_descriptor;
2424

25-
#[no_mangle]
26-
#[link_section = ".start"]
25+
#[unsafe(no_mangle)]
26+
#[unsafe(link_section = ".start")]
2727
pub extern "C" fn _start(info: &mut BiosInfo) -> ! {
2828
let memory_map: &mut [E820MemoryRegion] = unsafe {
2929
core::slice::from_raw_parts_mut(
@@ -255,8 +255,8 @@ fn create_page_tables(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Pa
255255
fn detect_rsdp() -> Option<PhysAddr> {
256256
use core::ptr::NonNull;
257257
use rsdp::{
258-
handler::{AcpiHandler, PhysicalMapping},
259258
Rsdp,
259+
handler::{AcpiHandler, PhysicalMapping},
260260
};
261261

262262
#[derive(Clone)]
@@ -271,13 +271,15 @@ fn detect_rsdp() -> Option<PhysAddr> {
271271
physical_address: usize,
272272
size: usize,
273273
) -> PhysicalMapping<Self, T> {
274-
PhysicalMapping::new(
275-
physical_address,
276-
NonNull::new(physical_address as *mut _).unwrap(),
277-
size,
278-
size,
279-
Self,
280-
)
274+
unsafe {
275+
PhysicalMapping::new(
276+
physical_address,
277+
NonNull::new(physical_address as *mut _).unwrap(),
278+
size,
279+
size,
280+
Self,
281+
)
282+
}
281283
}
282284

283285
fn unmap_physical_region<T>(_region: &PhysicalMapping<Self, T>) {}

0 commit comments

Comments
 (0)