Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update limine protocol #34

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/firmware_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Auxiliary types for the [firmware type request
//! ](crate::request::FirmwareTypeRequest).

/// A firmware type.
#[repr(transparent)]
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct FirmwareType(u64);
impl FirmwareType {
/// The firmware type is x86 BIOS.
pub const X86_BIOS: Self = Self(0);
/// The firmware type is 32-bit UEFI.
pub const UEFI_32: Self = Self(1);
/// The firmware type is 64-bit UEFI.
pub const UEFI_64: Self = Self(2);
}
impl From<u64> for FirmwareType {
fn from(value: u64) -> Self {
Self(value)
}
}
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! ```rust
//! use limine::BaseRevision;
//!
//! // Require version 1 or higher
//! // Require version 2 or higher
//! pub static BASE_REVISION: BaseRevision = BaseRevision::new();
//! ```
//!
Expand All @@ -59,6 +59,7 @@
use core::cell::UnsafeCell;

pub mod file;
pub mod firmware_type;
pub mod framebuffer;
pub mod memory_map;
pub mod modules;
Expand All @@ -71,7 +72,7 @@ pub mod smp;
/// kernel in order to require a higher revision. Without this tag, the
/// bootloader will assume revision 0.
///
/// The latest revision is 1.
/// The latest revision is 2.
#[repr(C)]
pub struct BaseRevision {
_id: [u64; 2],
Expand All @@ -80,7 +81,7 @@ pub struct BaseRevision {
impl BaseRevision {
/// Create a new base revision tag with the latest revision.
pub const fn new() -> Self {
Self::with_revision(1)
Self::with_revision(2)
}

/// Create a new base revision tag with the given revision.
Expand Down
35 changes: 27 additions & 8 deletions src/paging.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
//! Auxiliary types for the [paging mode
//! request](crate::request::PagingModeRequest).

use bitflags::bitflags;

bitflags! {
/// Paging mode flags. None are currently specified.
#[derive(Default, Clone, Copy)]
pub struct Flags: u64 {}
}

/// A paging mode.
#[repr(transparent)]
#[derive(PartialEq, Eq, Clone, Copy)]
Expand All @@ -25,6 +17,13 @@ impl Mode {
pub const FOUR_LEVEL: Self = Self(0);
/// (x86_64 and aarch64) Five-level paging (i.e. 52-bit virtual addresses on x86_64).
pub const FIVE_LEVEL: Self = Self(1);

/// The default paging mode.
pub const DEFAULT: Self = Self::FOUR_LEVEL;
/// The maximum supported paging mode.
pub const MAX: Self = Self::FIVE_LEVEL;
/// The minimum supported paging mode.
pub const MIN: Self = Self::FOUR_LEVEL;
}

#[cfg(target_arch = "riscv64")]
Expand All @@ -35,4 +34,24 @@ impl Mode {
pub const SV48: Self = Self(1);
/// (riscv64 only) SV57, i.e. 57-bit virtual addresses.
pub const SV57: Self = Self(2);

/// The default paging mode.
pub const DEFAULT: Self = Self::SV48;
/// The maximum supported paging mode.
pub const MAX: Self = Self::SV57;
/// The minimum supported paging mode.
pub const MIN: Self = Self::SV39;
}

#[cfg(target_arch = "loongarch64")]
impl Mode {
/// (loongarch64 only) Four-level paging.
pub const FOUR_LEVEL: Self = Self(0);

/// The default paging mode.
pub const DEFAULT: Self = Self::FOUR_LEVEL;
/// The maximum supported paging mode.
pub const MAX: Self = Self::FOUR_LEVEL;
/// The minimum supported paging mode.
pub const MIN: Self = Self::FOUR_LEVEL;
}
111 changes: 60 additions & 51 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ impl BootloaderInfoRequest {
);
}

/// Request the type of the firmware.
///
/// # Usage
/// ```rust
/// # use limine::{request::FirmwareTypeRequest, response::FirmwareTypeResponse, BaseRevision};
/// static BASE_REVISION: BaseRevision = BaseRevision::new();
///
/// // Request the firmware type
/// static FIRMWARE_TYPE_REQUEST: FirmwareTypeRequest = FirmwareTypeRequest::new();
///
/// # fn dummy<'a>() -> Option<&'a FirmwareTypeResponse> {
/// // ...later, in our code
/// FIRMWARE_TYPE_REQUEST.get_response() // ...
/// # }
/// ```
#[repr(C)]
pub struct FirmwareTypeRequest {
id: [u64; 4],
revision: u64,
response: Response<FirmwareTypeResponse>,
}
impl FirmwareTypeRequest {
impl_base_fns!(
0,
FirmwareTypeResponse,
magic!(0x8c2f75d90bef28a8, 0x7045a4688eac00c3),
{}
);
}

/// Request a differently-sized stack.
///
/// # Usage
Expand Down Expand Up @@ -255,19 +285,20 @@ pub struct PagingModeRequest {
revision: u64,
response: Response<PagingModeResponse>,
mode: paging::Mode,
flags: paging::Flags,

// Revision 1+
max_mode: paging::Mode,
min_mode: paging::Mode,
}
impl PagingModeRequest {
impl_base_fns!(
0,
1,
PagingModeResponse,
magic!(0x95c1a0edab0944cb, 0xa4e5cb3842f7488a),
{
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
mode: paging::Mode::FOUR_LEVEL,
#[cfg(target_arch = "riscv64")]
mode: paging::Mode::SV48,
flags: paging::Flags::empty(),
mode: paging::Mode::DEFAULT,
max_mode: paging::Mode::DEFAULT,
min_mode: paging::Mode::MIN,
}
);

Expand All @@ -280,59 +311,37 @@ impl PagingModeRequest {
mode
);
setter!(
/// Set the requested paging flags. See [`Flags`](paging::Flags) for
/// more information.
paging::Flags,
set_flags,
with_flags,
flags
/// Set the requested maximum paging mode. See [`Mode`](paging::Mode) for more
/// information.
paging::Mode,
set_max_mode,
with_max_mode,
max_mode
);
setter!(
/// Set the requested minimum paging mode. See [`Mode`](paging::Mode) for more
/// information.
paging::Mode,
set_min_mode,
with_min_mode,
min_mode
);

/// Get the requested paging mode. See [`Mode`](paging::Mode) for more
/// information.
pub fn mode(&self) -> paging::Mode {
self.mode
}
/// Get the requested paging flags. See [`Flags`](paging::Flags) for more
/// Get the requested maximum paging mode. See [`Mode`](paging::Mode) for more
/// information.
pub fn flags(&self) -> paging::Flags {
self.flags
pub fn max_mode(&self) -> paging::Mode {
self.max_mode
}
/// Get the requested minimum paging mode. See [`Mode`](paging::Mode) for more
/// information.
pub fn min_mode(&self) -> paging::Mode {
self.min_mode
}
}

/// **This request is deprecated and was removed from the reference
/// implementation. Use [`PagingModeRequest`] instead.**
///
/// Request a five-level paging mode.
///
/// # Usage
/// ```rust
/// # use limine::{request::FiveLevelPagingRequest, response::FiveLevelPagingResponse, BaseRevision};
/// static BASE_REVISION: BaseRevision = BaseRevision::new();
///
/// // Request a five-level paging mode
/// static FIVE_LEVEL_PAGING_REQUEST: FiveLevelPagingRequest = FiveLevelPagingRequest::new();
///
/// # fn dummy<'a>() -> Option<&'a FiveLevelPagingResponse> {
/// // ...later, in our code
/// FIVE_LEVEL_PAGING_REQUEST.get_response() // ...
/// # }
/// ```
#[repr(C)]
#[deprecated(note = "use `PagingModeRequest` instead")]
pub struct FiveLevelPagingRequest {
id: [u64; 4],
revision: u64,
response: Response<FiveLevelPagingResponse>,
}
#[allow(deprecated)]
impl FiveLevelPagingRequest {
impl_base_fns!(
0,
FiveLevelPagingResponse,
magic!(0x94469551da9b3192, 0xebe5e86db7382888),
{}
);
}

/// Request the start of all other cores on the system, if they exist. Without
Expand Down
40 changes: 18 additions & 22 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use core::{

use crate::{
file,
firmware_type::FirmwareType,
framebuffer::{Framebuffer, RawFramebuffer},
memory_map,
paging::{Flags, Mode},
paging::Mode,
smp,
};

Expand Down Expand Up @@ -47,6 +48,22 @@ impl BootloaderInfoResponse {
}
}

/// A response to a [firmware type request
/// ](crate::request::FirmwareTypeRequest).
#[repr(C)]
pub struct FirmwareTypeResponse {
revision: u64,
firmware_type: FirmwareType,
}
impl FirmwareTypeResponse {
impl_base_fns!();

/// Returns the firmware type.
pub fn firmware_type(&self) -> FirmwareType {
self.firmware_type
}
}

/// A response to a [stack size request](crate::request::StackSizeRequest). This
/// response has no fields. If it is provided, the bootloader complied with the
/// request.
Expand Down Expand Up @@ -122,7 +139,6 @@ impl FramebufferResponse {
pub struct PagingModeResponse {
revision: u64,
mode: Mode,
flags: Flags,
}
impl PagingModeResponse {
impl_base_fns!();
Expand All @@ -132,26 +148,6 @@ impl PagingModeResponse {
pub fn mode(&self) -> Mode {
self.mode
}
/// Returns the flags that were enabled by the bootloader. See [`Flags`] for
/// more information.
pub fn flags(&self) -> Flags {
self.flags
}
}

/// **This request is deprecated and was removed from the reference
/// implementation. Use [`PagingModeRequest`](crate::request::PagingModeRequest)
/// instead.**
///
/// A response to a [five-level paging
/// request](crate::request::FiveLevelPagingRequest). This response has no
/// fields. If it is provided, five-level paging is supported and enabled.
#[repr(C)]
pub struct FiveLevelPagingResponse {
revision: u64,
}
impl FiveLevelPagingResponse {
impl_base_fns!();
}

/// A response to a [smp request](crate::request::SmpRequest). This response
Expand Down
42 changes: 11 additions & 31 deletions src/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,29 @@ impl GotoAddress {
}

/// A CPU entry in the SMP request.
#[cfg(target_arch = "x86_64")]
#[repr(C)]
pub struct Cpu {
/// The ACPI processor ID, according to the ACPI MADT.
adavis628 marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub id: u32,
/// The ACPI processor ID, according to the ACPI MADT.
#[cfg(target_arch = "riscv64")]
pub id: u64,

#[cfg(target_arch = "x86_64")]
/// The APIC ID, according to the ACPI MADT.
pub lapic_id: u32,
_reserved: core::mem::MaybeUninit<u64>,
/// The address to jump to. Writing to this field will cause the core to
/// jump to the given function. The function will receive a pointer to this
/// structure, and it will have its own 64KiB (or requested-size) stack.
pub goto_address: GotoAddress,
/// Free for use by the kernel.
pub extra: u64,
}

/// A CPU entry in the SMP request.
#[cfg(target_arch = "aarch64")]
#[repr(C)]
pub struct Cpu {
/// The ACPI processor ID, according to the ACPI MADT.
pub id: u32,
/// The GIC interface number, according to the ACPI MADT.
pub gic_iface_no: u32,
#[cfg(target_arch = "aarch64")]
_reserved1: core::mem::MaybeUninit<u32>,
#[cfg(target_arch = "aarch64")]
/// The MPIDR of the CPU, according to the ACPI MADT or the device tree.
pub mpidr: u64,
_reserved: core::mem::MaybeUninit<u64>,
/// The address to jump to. Writing to this field will cause the core to
/// jump to the given function. The function will receive a pointer to this
/// structure, and it will have its own 64KiB (or requested-size) stack.
pub goto_address: GotoAddress,
/// Free for use by the kernel.
pub extra: u64,
}

/// A CPU entry in the SMP request.
#[cfg(target_arch = "riscv64")]
#[repr(C)]
pub struct Cpu {
/// The ACPI processor ID, according to the ACPI MADT.
pub id: u64,
#[cfg(target_arch = "riscv64")]
/// The hart ID, according to the ACPI MADT or the device tree.
pub hartid: u64,

_reserved: core::mem::MaybeUninit<u64>,
/// The address to jump to. Writing to this field will cause the core to
/// jump to the given function. The function will receive a pointer to this
Expand Down
Loading