Reorganizing & clippy fixes

This commit is contained in:
River 2025-02-21 08:50:18 -05:00
parent 0e585b955e
commit 8ac55a4911
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
7 changed files with 73 additions and 69 deletions

View File

@ -1,7 +1,10 @@
# Default target is x86_64-unknown-none
TARGET ?= "x86_64-unknown-none" TARGET ?= "x86_64-unknown-none"
# QEMU system is set accordingly and automatically
qemu = "qemu-system-x86_64" qemu = "qemu-system-x86_64"
# Properly set QEMU command
ifeq ($(TARGET),x86_64-unknown-none) ifeq ($(TARGET),x86_64-unknown-none)
qemu = "qemu-system-x86_64" qemu = "qemu-system-x86_64"
else ifeq ($(TARGET),riscv64gc-unknown-none-elf) else ifeq ($(TARGET),riscv64gc-unknown-none-elf)
@ -28,19 +31,20 @@ run: build/gila.iso
# Build the bootable kernel image. # Build the bootable kernel image.
.PHONY: build/iso/gila .PHONY: build/iso/gila
gila: prepare $(wildcard src/*.rs) gila: prepare $(wildcard src/*.rs) $(wildcard linker-scripts/*.ld)
mkdir -p build/iso/ mkdir -p build/iso/
cargo build --release -Z unstable-options --target=$(TARGET) --artifact-dir build/iso/ cargo build --release -Z unstable-options --target=$(TARGET) --artifact-dir build/iso/
# Build a bootable ISO and install Limine. # Build a bootable ISO and install Limine.
.PHONY: build/gila.iso .PHONY: build/gila.iso
iso: build/iso/gila gila limine.conf iso: build/iso/gila limine.conf
mkdir -p build/iso/limine mkdir -p build/iso/limine
mkdir -p build/iso/EFI/BOOT mkdir -p build/iso/EFI/BOOT
cp ./limine.conf build/iso/ cp ./limine.conf build/iso/
cp /usr/share/limine/limine-bios.sys build/iso/limine/ cp /usr/share/limine/limine-bios.sys build/iso/limine/
cp /usr/share/limine/limine-bios-cd.bin build/iso/limine/ cp /usr/share/limine/limine-bios-cd.bin build/iso/limine/
cp /usr/share/limine/limine-uefi-cd.bin build/iso/limine/ cp /usr/share/limine/limine-uefi-cd.bin build/iso/limine/
tree build/iso/
xorriso -as mkisofs -b limine/limine-bios-cd.bin -no-emul-boot \ xorriso -as mkisofs -b limine/limine-bios-cd.bin -no-emul-boot \
-boot-load-size 4 -boot-info-table --efi-boot \ -boot-load-size 4 -boot-info-table --efi-boot \
limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image \ limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image \

View File

@ -3,9 +3,16 @@
Gila is a Rust microkernel OS, inspired by the Xinu embedded OS, as well as Linux. I aim to implement multitasking and different users for processes, and eventually a filesystem. I do not aim to make it POSIX-compatible, but it will likely end up sharing many features with POSIX operating systems. Gila is a Rust microkernel OS, inspired by the Xinu embedded OS, as well as Linux. I aim to implement multitasking and different users for processes, and eventually a filesystem. I do not aim to make it POSIX-compatible, but it will likely end up sharing many features with POSIX operating systems.
## Work In Progress ## Features
Gila does nothing at all right now. Check back later. Or contribute. - Kernel command line parameters
- Display console (work in progress)
- Serial console (unstarted)
- Multi-architecture support:
- `aarch64`: in progress
- `loongarch64`: in progress
- `riscv64`: in progress
- `x86_64`: mostly complete
## Licensing ## Licensing
@ -26,13 +33,15 @@ Licensed under the GNU Public License v3. See [LICENSE](LICENSE) for details.
## Building and running ## Building and running
Building a bootable kernel is easy. All you need to do is run `cargo build gila`, and a valid, bootable Limine executable will be generated. However, it cannot be booted without installing it in a bootable Limine filesystem.
To build an ISO image that you can boot, there are several prerequisites: To build an ISO image that you can boot, there are several prerequisites:
- `rustup` command installed - `rustup` command installed
- `limine` command installed - `limine` command installed
- `xorriso` command installed - `xorriso` command installed
- `make` command installed - `make` command installed
- `qemu-system-x86_64` command installed (for running) - `qemu-system-(your target architecture)` command installed (for running)
Then run `make` to invoke the [Makefile](Makefile). Then run `make` to invoke the [Makefile](Makefile).
@ -42,6 +51,8 @@ Then run `make` to invoke the [Makefile](Makefile).
- `make iso`: Builds the bootable ISO with Limine installed. - `make iso`: Builds the bootable ISO with Limine installed.
- `make run`: Builds the ISO and boots it in QEMU. - `make run`: Builds the ISO and boots it in QEMU.
By supplying `TARGET=(rustc target triple)` as an additional argument, you can change the architecture that gila will be compiled & run for. The default is `x86_64-unknown-none`.
You can install all these dependencies automatically by using `nix-shell` and You can install all these dependencies automatically by using `nix-shell` and
supplying [shell.nix](shell.nix) as an argument. supplying [shell.nix](shell.nix) as an argument.

View File

@ -1,20 +0,0 @@
#![no_std]
#![feature(allocator_api)]
/// Boot services, handled by the Limine boot protocol.
pub mod boot;
/// Logger structure, static, and trait.
pub mod log;
/// Memory regions, allocation, flags, and whatnot.
pub mod memory;
/// Panic handling function logic.
pub mod panic;
/// Kernel command line parameter structure and enums.
pub mod params;
/// Process representation.
pub mod process;
/// Resources accessible from many parts of the code.
pub mod resources;
/// Architecture dependent.
pub mod arch;

View File

@ -30,7 +30,7 @@ impl Default for Logger {
impl Logger { impl Logger {
pub const fn new() -> Self { pub const fn new() -> Self {
Logger { Logger {
level: LogLevel::WARNING, level: LogLevel::Warning,
subscriber: Vec::new(), subscriber: Vec::new(),
} }
} }
@ -38,6 +38,10 @@ impl Logger {
/// Calling log will sequentially acquire lock on all logging subscribers /// Calling log will sequentially acquire lock on all logging subscribers
/// to write to them with a formatted log message. /// to write to them with a formatted log message.
pub fn log(&self, level: LogLevel, msg: &str) { pub fn log(&self, level: LogLevel, msg: &str) {
// Nobody is EVER allowed to call log with the Disabled log level. It is a placeholder.
if level == LogLevel::Disabled {
return;
}
if level > self.level { if level > self.level {
for sub in &self.subscriber { for sub in &self.subscriber {
let mut message = String::new(); let mut message = String::new();
@ -50,24 +54,24 @@ impl Logger {
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] #[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum LogLevel { pub enum LogLevel {
DISABLED, Disabled,
CRITICAL, Critical,
ERROR, Error,
WARNING, Warning,
INFO, Info,
TRACE, Trace,
} }
impl TryFrom<u8> for LogLevel { impl TryFrom<u8> for LogLevel {
type Error = EnumParseError; type Error = EnumParseError;
fn try_from(from: u8) -> Result<Self, Self::Error> { fn try_from(from: u8) -> Result<Self, <crate::log::LogLevel as TryFrom<u8>>::Error> {
match from { match from {
0 => Ok(Self::DISABLED), 0 => Ok(Self::Disabled),
1 => Ok(Self::CRITICAL), 1 => Ok(Self::Critical),
2 => Ok(Self::ERROR), 2 => Ok(Self::Error),
3 => Ok(Self::WARNING), 3 => Ok(Self::Warning),
4 => Ok(Self::INFO), 4 => Ok(Self::Info),
5 => Ok(Self::TRACE), 5 => Ok(Self::Trace),
_ => Err(EnumParseError {}), _ => Err(EnumParseError {}),
} }
} }
@ -75,14 +79,14 @@ impl TryFrom<u8> for LogLevel {
impl TryFrom<&str> for LogLevel { impl TryFrom<&str> for LogLevel {
type Error = EnumParseError; type Error = EnumParseError;
fn try_from(from: &str) -> Result<Self, Self::Error> { fn try_from(from: &str) -> Result<Self, <crate::log::LogLevel as TryFrom<u8>>::Error> {
match from.to_ascii_lowercase().as_ref() { match from.to_ascii_lowercase().as_ref() {
"disabled" => Ok(Self::DISABLED), "disabled" => Ok(Self::Disabled),
"critical" => Ok(Self::CRITICAL), "critical" => Ok(Self::Critical),
"error" => Ok(Self::ERROR), "error" => Ok(Self::Error),
"warning" => Ok(Self::WARNING), "warning" => Ok(Self::Warning),
"info" => Ok(Self::INFO), "info" => Ok(Self::Info),
"trace" => Ok(Self::TRACE), "trace" => Ok(Self::Trace),
_ => Err(EnumParseError {}), _ => Err(EnumParseError {}),
} }
} }

View File

@ -3,16 +3,20 @@
#![feature(allocator_api)] #![feature(allocator_api)]
#![allow(unused_imports)] #![allow(unused_imports)]
use gila::arch::current::display; mod arch;
use gila::arch::current::*; mod boot;
use gila::boot::*; mod log;
use gila::log::*; mod memory;
use gila::memory; mod panic;
use gila::memory::alloc::*; mod params;
use gila::panic; mod process;
use gila::params; mod resources;
use gila::params::get_kernel_params;
use gila::process; use crate::arch::current::*;
use crate::boot::*;
use crate::log::*;
use crate::memory::alloc::*;
use crate::params::*;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
unsafe extern "C" fn main() -> ! { unsafe extern "C" fn main() -> ! {
@ -43,14 +47,14 @@ unsafe extern "C" fn main() -> ! {
if log_device_list.contains(&"serial") { if log_device_list.contains(&"serial") {
// Append serial console to log subs // Append serial console to log subs
} }
log(LogLevel::INFO, "Configured kernel logging devices.") log(LogLevel::Info, "Configured kernel logging devices.")
} }
{ {
let kernel_cmdline_string = let kernel_cmdline_string =
string::String::from_utf8_lossy(kernel_file_response.file().cmdline()); string::String::from_utf8_lossy(kernel_file_response.file().cmdline());
log( log(
LogLevel::INFO, LogLevel::Info,
&format!("Kernel cmdline: {}", kernel_cmdline_string), &format!("Kernel cmdline: {}", kernel_cmdline_string),
); );
drop(kernel_cmdline_string); drop(kernel_cmdline_string);
@ -59,30 +63,30 @@ unsafe extern "C" fn main() -> ! {
{ {
let kernel_path = string::String::from_utf8_lossy(kernel_file_response.file().path()); let kernel_path = string::String::from_utf8_lossy(kernel_file_response.file().path());
log( log(
LogLevel::INFO, LogLevel::Info,
&format!("Kernel file path: {}", kernel_path), &format!("Kernel file path: {}", kernel_path),
); );
drop(kernel_path); drop(kernel_path);
} }
} }
log(LogLevel::INFO, "Log devices configured. Booting `gila`."); log(LogLevel::Info, "Log devices configured. Booting `gila`.");
log(LogLevel::INFO, "Trans Rights!"); log(LogLevel::Info, "Trans Rights!");
let _smp_response = SMP_REQUEST.get_response(); let _smp_response = SMP_REQUEST.get_response();
match _smp_response { match _smp_response {
None => log( None => log(
LogLevel::ERROR, LogLevel::Error,
"SMP response not received. Multiprocessing is disabled.", "SMP response not received. Multiprocessing is disabled.",
), ),
Some(resp) => { Some(resp) => {
log( log(
LogLevel::INFO, LogLevel::Info,
"SMP response received. Multiprocessing enabled.", "SMP response received. Multiprocessing enabled.",
); );
log( log(
LogLevel::INFO, LogLevel::Info,
&format!("{} CPUs found.", resp.cpus().len()), &format!("{} CPUs found.", resp.cpus().len()),
); );
} }

View File

@ -3,7 +3,6 @@
use flagset::flags; use flagset::flags;
use core::alloc::{Allocator, Layout}; use core::alloc::{Allocator, Layout};
use spin;
use talc::*; use talc::*;
pub extern crate alloc; pub extern crate alloc;

View File

@ -6,6 +6,7 @@ use crate::memory::alloc;
use alloc::string::String; use alloc::string::String;
use alloc::vec::Vec; use alloc::vec::Vec;
#[allow(dead_code)]
pub struct ProcessTable {} pub struct ProcessTable {}
#[allow(dead_code)] #[allow(dead_code)]
@ -32,9 +33,10 @@ pub struct Process {
semaphor_wait: Option<u32>, semaphor_wait: Option<u32>,
} }
#[allow(dead_code)]
pub enum ProcessState { pub enum ProcessState {
RUNNING, Running,
WAITING, Waiting,
SLEEPING, Sleeping,
SUSPENDED, Suspended,
} }