Move statics out of main
This commit is contained in:
parent
24524c104f
commit
477781c3f5
@ -4,8 +4,8 @@ use lazy_static::lazy_static;
|
|||||||
|
|
||||||
use super::asm::*;
|
use super::asm::*;
|
||||||
|
|
||||||
use crate::{log_trace, format};
|
use crate::log::{LOGGER, LogLevel};
|
||||||
use crate::log::{LogLevel, LOGGER};
|
use crate::{format, log_trace};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref GDT: GlobalDescriptorTable = {
|
pub static ref GDT: GlobalDescriptorTable = {
|
||||||
|
@ -4,11 +4,23 @@ use limine::response::{DeviceTreeBlobResponse, RsdpResponse};
|
|||||||
|
|
||||||
use crate::boot::{DTB_REQUEST, RSDP_REQUEST};
|
use crate::boot::{DTB_REQUEST, RSDP_REQUEST};
|
||||||
use crate::log::{LOGGER, LogLevel};
|
use crate::log::{LOGGER, LogLevel};
|
||||||
use crate::{format, log_trace};
|
use crate::{format, log_info, log_trace, log_warning};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = DTB_REQUEST.get_response();
|
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() {
|
||||||
pub static ref RDSP: Option<&'static RsdpResponse> = RSDP_REQUEST.get_response();
|
Some(resp) => { log_info!("Device: Got DTB pointer"); Some(resp) },
|
||||||
|
None => { log_warning!("Device: Did not get DTB pointer"); None },
|
||||||
|
};
|
||||||
|
pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() {
|
||||||
|
Some(resp) => { log_info!("Device: Got RSDP pointer"); Some(resp) },
|
||||||
|
None => { log_warning!("Device: Did not get RSDP pointer, ACPI unavailable"); None },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just to check
|
||||||
|
pub fn init_statics() {
|
||||||
|
let _ = DTB.is_some();
|
||||||
|
let _ = RSDP.is_some();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -39,21 +39,15 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
// Assert supported bootloader version
|
// Assert supported bootloader version
|
||||||
assert!(BASE_REVISION.is_supported());
|
assert!(BASE_REVISION.is_supported());
|
||||||
|
|
||||||
let executable_file_response = FILE_REQUEST
|
|
||||||
.get_response()
|
|
||||||
.expect("Bootloader did not return executable data");
|
|
||||||
let params =
|
|
||||||
get_kernel_params(limine::file::File::string(executable_file_response.file()).to_bytes());
|
|
||||||
|
|
||||||
// Set up logging level from params
|
// Set up logging level from params
|
||||||
// Nothing we can do here if this fails since no log subscribers are initialized yet
|
// Nothing we can do here if this fails since no log subscribers are initialized yet
|
||||||
if let Some(level) = params.get("-loglevel")
|
if let Some(level) = PARAMS.get("-loglevel")
|
||||||
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
|
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
|
||||||
{
|
{
|
||||||
LOGGER.set_level(parsed_level);
|
LOGGER.set_level(parsed_level);
|
||||||
}
|
}
|
||||||
// Add subscribers to logger
|
// Add subscribers to logger
|
||||||
if let Some(device) = params.get("-logdev") {
|
if let Some(device) = PARAMS.get("-logdev") {
|
||||||
let log_device_list: vec::Vec<&str> = device.split(',').collect();
|
let log_device_list: vec::Vec<&str> = device.split(',').collect();
|
||||||
if log_device_list.contains(&"display") {
|
if log_device_list.contains(&"display") {
|
||||||
// Append display console to log subs
|
// Append display console to log subs
|
||||||
@ -68,17 +62,19 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
log_info!(
|
log_info!(
|
||||||
"Boot: Kernel cmdline: {}",
|
"Boot: Kernel cmdline: {}",
|
||||||
String::from_utf8_lossy(
|
String::from_utf8_lossy(
|
||||||
limine::file::File::string(executable_file_response.file()).to_bytes()
|
limine::file::File::string(EXECUTABLE_FILE_RESPONSE.file()).to_bytes()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
log_info!(
|
log_info!(
|
||||||
"Boot: Kernel file path: {}",
|
"Boot: Kernel file path: {}",
|
||||||
String::from_utf8_lossy(executable_file_response.file().path().to_bytes())
|
String::from_utf8_lossy(EXECUTABLE_FILE_RESPONSE.file().path().to_bytes())
|
||||||
);
|
);
|
||||||
log_info!("Boot: Booting gila version {}", kernel_version_string());
|
log_info!("Boot: Booting gila version {}", kernel_version_string());
|
||||||
|
|
||||||
log_info!("Boot: Trans rights!");
|
log_info!("Boot: Trans rights!");
|
||||||
|
|
||||||
|
device::init_statics();
|
||||||
|
|
||||||
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
|
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
|
||||||
let fb = framebuffer_response.framebuffers().next().unwrap();
|
let fb = framebuffer_response.framebuffers().next().unwrap();
|
||||||
log_info!("Boot: Framebuffer response received");
|
log_info!("Boot: Framebuffer response received");
|
||||||
@ -101,18 +97,6 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to obtain ACPI information first. If not available, fall back to
|
|
||||||
// flattened device tree.
|
|
||||||
let rsdp_response = RSDP_REQUEST.get_response();
|
|
||||||
let dtb_response = DTB_REQUEST.get_response();
|
|
||||||
if let Some(rdsp) = rsdp_response {
|
|
||||||
log_info!("Boot: RDSP response received");
|
|
||||||
log_trace!("Boot: RDSP located at 0x{:x}", rdsp.address());
|
|
||||||
} else if let Some(dtb) = dtb_response {
|
|
||||||
log_info!("Boot: DTB response received");
|
|
||||||
log_trace!("Boot: DTB located at 0x{:x}", dtb.dtb_ptr() as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
let module_response = MODULE_REQUEST
|
let module_response = MODULE_REQUEST
|
||||||
.get_response()
|
.get_response()
|
||||||
.expect("Bootloader did not return kernel modules");
|
.expect("Bootloader did not return kernel modules");
|
||||||
@ -132,7 +116,7 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let irfs_path = {
|
let irfs_path = {
|
||||||
if let Some(key) = params.get("-initramfs") {
|
if let Some(key) = PARAMS.get("-initramfs") {
|
||||||
key
|
key
|
||||||
} else {
|
} else {
|
||||||
INITRAMFS_DEFAULT_PATH
|
INITRAMFS_DEFAULT_PATH
|
||||||
|
@ -4,6 +4,17 @@
|
|||||||
use crate::memory::alloc;
|
use crate::memory::alloc;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use limine::response::ExecutableFileResponse;
|
||||||
|
use crate::boot::FILE_REQUEST;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref EXECUTABLE_FILE_RESPONSE: &'static ExecutableFileResponse = FILE_REQUEST
|
||||||
|
.get_response()
|
||||||
|
.expect("Bootloader did not return executable data");
|
||||||
|
pub static ref PARAMS: KernelParameters =
|
||||||
|
get_kernel_params(limine::file::File::string(EXECUTABLE_FILE_RESPONSE.file()).to_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
pub type KernelParameters = alloc::collections::BTreeMap<String, String>;
|
pub type KernelParameters = alloc::collections::BTreeMap<String, String>;
|
||||||
|
|
||||||
@ -11,17 +22,17 @@ pub type KernelParameters = alloc::collections::BTreeMap<String, String>;
|
|||||||
pub fn get_kernel_params(cmdline: &[u8]) -> KernelParameters {
|
pub fn get_kernel_params(cmdline: &[u8]) -> KernelParameters {
|
||||||
let cmd_str = String::from_utf8_lossy(cmdline).into_owned();
|
let cmd_str = String::from_utf8_lossy(cmdline).into_owned();
|
||||||
let args: Vec<&str> = cmd_str.split_ascii_whitespace().collect();
|
let args: Vec<&str> = cmd_str.split_ascii_whitespace().collect();
|
||||||
let mut params: alloc::collections::BTreeMap<String, String> =
|
let mut local_params: alloc::collections::BTreeMap<String, String> =
|
||||||
alloc::collections::BTreeMap::new();
|
alloc::collections::BTreeMap::new();
|
||||||
for arg in args {
|
for arg in args {
|
||||||
let split: Vec<&str> = arg.split('=').collect();
|
let split: Vec<&str> = arg.split('=').collect();
|
||||||
if let Some(first) = split.first() {
|
if let Some(first) = split.first() {
|
||||||
if split.len() > 1 {
|
if split.len() > 1 {
|
||||||
params.insert(String::from(*first), split[1..].join("="));
|
local_params.insert(String::from(*first), split[1..].join("="));
|
||||||
} else {
|
} else {
|
||||||
params.insert(String::from(*first), String::new());
|
local_params.insert(String::from(*first), String::new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params
|
local_params
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user