gila/src/kernel/main.rs
2025-09-28 23:04:00 -04:00

138 lines
3.8 KiB
Rust

// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later
#![no_std]
#![no_main]
#![feature(allocator_api)]
#![feature(str_from_raw_parts)]
#![feature(abi_x86_interrupt)]
mod arch;
mod boot;
mod constants;
mod device;
mod interrupt;
#[macro_use]
mod log;
mod memory;
mod panic;
mod process;
#[macro_use]
mod util;
use boot::{BASE_REVISION, params, *};
use constants::*;
use limine::firmware_type::FirmwareType;
use log::*;
use memory::alloc::{format, string::*, vec};
use params::*;
#[allow(unused_imports)]
use lzma_rs::lzma_decompress;
use crate::arch::x86_64::interrupts::IDT;
#[unsafe(no_mangle)]
unsafe extern "C" fn main() -> ! {
// Assert supported bootloader version
assert!(BASE_REVISION.is_supported());
// Ensure IDT exists
IDT.load();
#[cfg(target_arch = "x86_64")]
let serial: x86_64::instructions::port::Port<u8> = x86_64::instructions::port::Port::new(0x3f8);
// Set up logging level from params
// Nothing we can do here if this fails since no log subscribers are initialized yet
if let Some(level) = PARAMS.get("-loglevel")
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
{
LOGGER.set_level(parsed_level);
}
// Add subscribers to logger
if let Some(device) = PARAMS.get("-logdev") {
let log_device_list: vec::Vec<&str> = device.split(',').collect();
if log_device_list.contains(&"display") {
// Append display console to log subs
}
if log_device_list.contains(&"serial") {
// TODO: Set up device discovery
#[cfg(target_arch = "x86_64")]
LOGGER.add_subscriber(serial);
}
log_trace!("Configured kernel logging devices");
}
log_info!(
"Kernel cmdline: {}",
String::from_utf8_lossy(
limine::file::File::string(EXECUTABLE_FILE_RESPONSE.file()).to_bytes()
)
);
log_info!(
"Kernel file path: {}",
String::from_utf8_lossy(EXECUTABLE_FILE_RESPONSE.file().path().to_bytes())
);
log_info!("Booting gila version {}", kernel_version_string());
log_info!("Enabled features: {}", FEATURE_FLAGS.to_string());
match boot::FIRMWARE_TYPE_REQUEST.get_response() {
Some(resp) => log_info!(
"Firmware type: {}",
match resp.firmware_type() {
FirmwareType::SBI => "SBI",
FirmwareType::UEFI_32 => "UEFI (32-bit)",
FirmwareType::UEFI_64 => "UEFI (64-bit)",
FirmwareType::X86_BIOS => "x86 BIOS",
_ => "Unknown",
}
),
None => log_warning!("Firmware type: No response"),
}
log_info!("Trans rights!");
device::init_statics();
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
let fb = framebuffer_response.framebuffers().next().unwrap();
log_info!("Framebuffer response received");
log_trace!(
"Framebuffer dimensions: {}x{}, {} bits per pixel",
fb.width(),
fb.height(),
fb.bpp()
);
} else {
log_info!("Framebuffer response absent, graphics disabled",);
}
let smp_response = MP_REQUEST.get_response();
match smp_response {
None => log_info!("Multiprocessing response not received"),
Some(resp) => {
log_info!("Multiprocessing response received");
log_trace!("{} CPUs found", resp.cpus().len());
}
}
boot::modules::log_modules();
memory::log_memory();
memory::log_address();
arch::x86_64::paging::get_mappings();
panic!("Bailing");
#[allow(unreachable_code)]
loop {
for _i in 0..50000000u64 {
crate::arch::asm::nop();
}
core::hint::black_box(());
log_trace!("Heartbeat");
}
}