Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license.workspace = true
version.workspace = true
repository.workspace = true
authors = ["Philipp Oppermann <[email protected]>"]
edition = "2021"
edition = "2024"

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "bootloader_api"
license.workspace = true
version.workspace = true
repository.workspace = true
edition = "2021"
edition = "2024"
description = "Makes a kernel compatible with the bootloader crate"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ macro_rules! entry_point {
};
($path:path, config = $config:expr) => {
const _: () = {
#[link_section = ".bootloader-config"]
#[unsafe(link_section = ".bootloader-config")]
pub static __BOOTLOADER_CONFIG: [u8; $crate::BootloaderConfig::SERIALIZED_LEN] = {
// validate the type
let config: &$crate::BootloaderConfig = $config;
Expand All @@ -125,7 +125,7 @@ macro_rules! entry_point {
static __BOOTLOADER_CONFIG_REF: &[u8; $crate::BootloaderConfig::SERIALIZED_LEN] =
&__BOOTLOADER_CONFIG;

#[export_name = "_start"]
#[unsafe(export_name = "_start")]
pub extern "C" fn __impl_start(boot_info: &'static mut $crate::BootInfo) -> ! {
// validate the signature of the program entry point
let f: fn(&'static mut $crate::BootInfo) -> ! = $path;
Expand Down
2 changes: 1 addition & 1 deletion bios/boot_sector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "bootloader-x86_64-bios-boot-sector"
version.workspace = true
authors = ["Philipp Oppermann <[email protected]>"]
edition = "2021"
edition = "2024"
license.workspace = true
repository.workspace = true
description = "BIOS boot sector for the `bootloader` crate"
Expand Down
4 changes: 2 additions & 2 deletions bios/boot_sector/src/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T, E> UnwrapOrFail for Result<T, E> {
}
}

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

#[cold]
#[inline(never)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn fail(code: u8) -> ! {
print_char(b'!');
print_char(code);
Expand Down
4 changes: 2 additions & 2 deletions bios/boot_sector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod dap;
mod fail;
mod mbr;

extern "C" {
unsafe extern "C" {
static _partition_table: u8;
static _second_stage_start: u8;
}
Expand All @@ -25,7 +25,7 @@ fn second_stage_start() -> *const () {
ptr as *const ()
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn first_stage(disk_number: u16) {
// read partition table and look for second stage partition
let partition_table = unsafe { slice::from_raw_parts(partition_table_raw(), 16 * 4) };
Expand Down
2 changes: 1 addition & 1 deletion bios/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bootloader-x86_64-bios-common"
version.workspace = true
edition = "2021"
edition = "2024"
license.workspace = true
repository.workspace = true
description = "Common code for BIOS stages of the `bootloader` crate"
Expand Down
2 changes: 1 addition & 1 deletion bios/stage-2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "bootloader-x86_64-bios-stage-2"
version.workspace = true
authors = ["Philipp Oppermann <[email protected]>"]
edition = "2021"
edition = "2024"
license.workspace = true
repository.workspace = true
description = "Second BIOS stage of the `bootloader` crate"
Expand Down
32 changes: 17 additions & 15 deletions bios/stage-2/src/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ impl DiskAddressPacket {

pub unsafe fn perform_load(&self, disk_number: u16) {
let self_addr = self as *const Self as u16;
asm!(
"push 'z'", // error code `z`, passed to `fail` on error
"mov {1:x}, si",
"mov si, {0:x}",
"int 0x13",
"jnc 2f", // carry is set on fail
"call fail",
"2:",
"pop si", // remove error code again
"mov si, {1:x}",
in(reg) self_addr,
out(reg) _,
in("ax") 0x4200u16,
in("dx") disk_number,
);
unsafe {
asm!(
"push 'z'", // error code `z`, passed to `fail` on error
"mov {1:x}, si",
"mov si, {0:x}",
"int 0x13",
"jnc 2f", // carry is set on fail
"call fail",
"2:",
"pop si", // remove error code again
"mov si, {1:x}",
in(reg) self_addr,
out(reg) _,
in("ax") 0x4200u16,
in("dx") disk_number,
);
}
}
}
1 change: 1 addition & 0 deletions bios/stage-2/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl Read for DiskAccess {
static mut TMP_BUF: AlignedArrayBuffer<1024> = AlignedArrayBuffer {
buffer: [0; 512 * 2],
};
#[allow(static_mut_refs)]
let buf = unsafe { &mut TMP_BUF };
assert!(current_sector_offset + len <= buf.buffer.len());

Expand Down
3 changes: 2 additions & 1 deletion bios/stage-2/src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<D: Read + Seek> FileSystem<D> {
fn read_root_dir<'a>(
&'a mut self,
buffer: &'a mut (dyn AlignedBuffer + 'a),
) -> impl Iterator<Item = Result<RawDirectoryEntry, ()>> + 'a {
) -> impl Iterator<Item = Result<RawDirectoryEntry<'a>, ()>> + 'a {
match self.bpb.fat_type() {
FatType::Fat32 => {
// self.bpb.root_cluster;
Expand Down Expand Up @@ -242,6 +242,7 @@ impl<D: Read + Seek> FileSystem<D> {

#[derive(Debug)]
pub struct Cluster {
#[allow(unused)]
pub index: u32,
pub start_offset: u64,
pub len_bytes: u32,
Expand Down
9 changes: 5 additions & 4 deletions bios/stage-2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
copy_to_protected_mode, enter_protected_mode_and_jump_to_stage_3, enter_unreal_mode,
},
};
use bootloader_x86_64_bios_common::{hlt, BiosFramebufferInfo, BiosInfo, Region};
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, Region, hlt};
use byteorder::{ByteOrder, LittleEndian};
use core::{fmt::Write as _, slice};
use disk::AlignedArrayBuffer;
Expand Down Expand Up @@ -35,8 +35,8 @@ static mut DISK_BUFFER: AlignedArrayBuffer<0x4000> = AlignedArrayBuffer {
buffer: [0; 0x4000],
};

#[no_mangle]
#[link_section = ".start"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".start")]
pub extern "C" fn _start(disk_number: u16, partition_table_start: *const u8) -> ! {
start(disk_number, partition_table_start)
}
Expand Down Expand Up @@ -87,6 +87,7 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {

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

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

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

#[cold]
#[inline(never)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn fail(code: u8) -> ! {
panic!("fail: {}", code as char);
}
2 changes: 1 addition & 1 deletion bios/stage-2/src/memory_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// From http://wiki.osdev.org/Detecting_Memory_(x86)#Getting_an_E820_Memory_Map

use crate::split_array_ref;
use bootloader_x86_64_bios_common::{racy_cell::RacyCell, E820MemoryRegion};
use bootloader_x86_64_bios_common::{E820MemoryRegion, racy_cell::RacyCell};
use core::arch::asm;

static MEMORY_MAP: RacyCell<[E820MemoryRegion; 100]> = RacyCell::new(
Expand Down
10 changes: 5 additions & 5 deletions bios/stage-2/src/protected_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ pub fn enter_unreal_mode() {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe fn copy_to_protected_mode(target: *mut u8, bytes: &[u8]) {
for (offset, byte) in bytes.iter().enumerate() {
let dst = target.wrapping_add(offset);
// we need to do the write in inline assembly because the compiler
// seems to truncate the address
unsafe {
asm!("mov [{}], {}", in(reg) dst, in(reg_byte) *byte, options(nostack, preserves_flags))
};
assert_eq!(read_from_protected_mode(dst), *byte);
asm!("mov [{}], {}", in(reg) dst, in(reg_byte) *byte, options(nostack, preserves_flags));
assert_eq!(read_from_protected_mode(dst), *byte);
}
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe fn read_from_protected_mode(ptr: *mut u8) -> u8 {
let res;
// we need to do the read in inline assembly because the compiler
Expand Down
8 changes: 2 additions & 6 deletions bios/stage-2/src/vesa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use bootloader_x86_64_bios_common::PixelFormat;

use crate::{disk::AlignedBuffer, AlignedArrayBuffer};
use crate::{AlignedArrayBuffer, disk::AlignedBuffer};
use core::arch::asm;

#[repr(C, packed)]
Expand Down Expand Up @@ -109,11 +109,7 @@ impl<'a> VesaInfo<'a> {
let base_ptr = video_mode_ptr as *const u16;
let ptr = unsafe { base_ptr.add(index) };
let mode = unsafe { *ptr };
if mode == 0xffff {
None
} else {
Some(mode)
}
if mode == 0xffff { None } else { Some(mode) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion bios/stage-3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "bootloader-x86_64-bios-stage-3"
version.workspace = true
authors = ["Philipp Oppermann <[email protected]>"]
edition = "2021"
edition = "2024"
license.workspace = true
repository.workspace = true
description = "Third BIOS stage of the `bootloader` crate"
Expand Down
8 changes: 4 additions & 4 deletions bios/stage-3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#![deny(unsafe_op_in_unsafe_fn)]

use crate::screen::Writer;
use bootloader_x86_64_bios_common::{hlt, BiosInfo};
use bootloader_x86_64_bios_common::{BiosInfo, hlt};
use core::{arch::asm, fmt::Write as _};

mod gdt;
mod paging;
mod screen;

#[no_mangle]
#[link_section = ".start"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".start")]
pub extern "C" fn _start(info: &mut BiosInfo) {
screen::init(info.framebuffer);
// Writer.clear_screen();
Expand All @@ -29,7 +29,7 @@ pub extern "C" fn _start(info: &mut BiosInfo) {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn enter_long_mode_and_jump_to_stage_4(info: &mut BiosInfo) {
let _ = writeln!(Writer, "Paging init done, jumping to stage 4");
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions bios/stage-3/src/screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bootloader_x86_64_bios_common::{racy_cell::RacyCell, BiosFramebufferInfo, PixelFormat};
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, PixelFormat, racy_cell::RacyCell};
use core::{fmt, ptr};
use noto_sans_mono_bitmap::{get_bitmap, BitmapChar, BitmapHeight, FontWeight};
use noto_sans_mono_bitmap::{BitmapChar, BitmapHeight, FontWeight, get_bitmap};

static WRITER: RacyCell<Option<ScreenWriter>> = RacyCell::new(None);
pub struct Writer;
Expand Down
2 changes: 1 addition & 1 deletion bios/stage-4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bootloader-x86_64-bios-stage-4"
version.workspace = true
edition = "2021"
edition = "2024"
license.workspace = true
repository.workspace = true
description = "Fourth BIOS stage of the `bootloader` crate"
Expand Down
26 changes: 14 additions & 12 deletions bios/stage-4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bootloader_boot_config::{BootConfig, LevelFilter};
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, E820MemoryRegion};
use bootloader_x86_64_common::RawFrameBufferInfo;
use bootloader_x86_64_common::{
legacy_memory_region::LegacyFrameAllocator, load_and_switch_to_kernel, Kernel, PageTables,
SystemInfo,
Kernel, PageTables, SystemInfo, legacy_memory_region::LegacyFrameAllocator,
load_and_switch_to_kernel,
};
use core::{cmp, slice};
use usize_conversions::usize_from;
Expand All @@ -22,8 +22,8 @@ const GIGABYTE: u64 = 4096 * 512 * 512;

mod memory_descriptor;

#[no_mangle]
#[link_section = ".start"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".start")]
pub extern "C" fn _start(info: &mut BiosInfo) -> ! {
let memory_map: &mut [E820MemoryRegion] = unsafe {
core::slice::from_raw_parts_mut(
Expand Down Expand Up @@ -255,8 +255,8 @@ fn create_page_tables(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Pa
fn detect_rsdp() -> Option<PhysAddr> {
use core::ptr::NonNull;
use rsdp::{
handler::{AcpiHandler, PhysicalMapping},
Rsdp,
handler::{AcpiHandler, PhysicalMapping},
};

#[derive(Clone)]
Expand All @@ -271,13 +271,15 @@ fn detect_rsdp() -> Option<PhysAddr> {
physical_address: usize,
size: usize,
) -> PhysicalMapping<Self, T> {
PhysicalMapping::new(
physical_address,
NonNull::new(physical_address as *mut _).unwrap(),
size,
size,
Self,
)
unsafe {
PhysicalMapping::new(
physical_address,
NonNull::new(physical_address as *mut _).unwrap(),
size,
size,
Self,
)
}
}

fn unmap_physical_region<T>(_region: &PhysicalMapping<Self, T>) {}
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bootloader-x86_64-common"
version.workspace = true
edition = "2021"
edition = "2024"
description = "Common code for the x86_64 bootloader implementations"
license.workspace = true
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion common/config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bootloader-boot-config"
version.workspace = true
edition = "2021"
edition = "2024"
description = "The runtime configurations that are saved in a JSON file for the bootloader crate"
license.workspace = true
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion common/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bootloader_api::info::{FrameBufferInfo, PixelFormat};
use core::{fmt, ptr};
use font_constants::BACKUP_CHAR;
use noto_sans_mono_bitmap::{
get_raster, get_raster_width, FontWeight, RasterHeight, RasterizedChar,
FontWeight, RasterHeight, RasterizedChar, get_raster, get_raster_width,
};

/// Additional vertical space between lines
Expand Down
Loading
Loading