Reorganizing & clippy fixes
This commit is contained in:
parent
0e585b955e
commit
8ac55a4911
8
Makefile
8
Makefile
@ -1,7 +1,10 @@
|
||||
|
||||
# Default target is x86_64-unknown-none
|
||||
TARGET ?= "x86_64-unknown-none"
|
||||
# QEMU system is set accordingly and automatically
|
||||
qemu = "qemu-system-x86_64"
|
||||
|
||||
# Properly set QEMU command
|
||||
ifeq ($(TARGET),x86_64-unknown-none)
|
||||
qemu = "qemu-system-x86_64"
|
||||
else ifeq ($(TARGET),riscv64gc-unknown-none-elf)
|
||||
@ -28,19 +31,20 @@ run: build/gila.iso
|
||||
|
||||
# Build the bootable kernel image.
|
||||
.PHONY: build/iso/gila
|
||||
gila: prepare $(wildcard src/*.rs)
|
||||
gila: prepare $(wildcard src/*.rs) $(wildcard linker-scripts/*.ld)
|
||||
mkdir -p build/iso/
|
||||
cargo build --release -Z unstable-options --target=$(TARGET) --artifact-dir build/iso/
|
||||
|
||||
# Build a bootable ISO and install Limine.
|
||||
.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/EFI/BOOT
|
||||
cp ./limine.conf build/iso/
|
||||
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-uefi-cd.bin build/iso/limine/
|
||||
tree build/iso/
|
||||
xorriso -as mkisofs -b limine/limine-bios-cd.bin -no-emul-boot \
|
||||
-boot-load-size 4 -boot-info-table --efi-boot \
|
||||
limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image \
|
||||
|
17
README.md
17
README.md
@ -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.
|
||||
|
||||
## 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
|
||||
|
||||
@ -26,13 +33,15 @@ Licensed under the GNU Public License v3. See [LICENSE](LICENSE) for details.
|
||||
|
||||
## 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:
|
||||
|
||||
- `rustup` command installed
|
||||
- `limine` command installed
|
||||
- `xorriso` 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).
|
||||
|
||||
@ -42,6 +51,8 @@ Then run `make` to invoke the [Makefile](Makefile).
|
||||
- `make iso`: Builds the bootable ISO with Limine installed.
|
||||
- `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
|
||||
supplying [shell.nix](shell.nix) as an argument.
|
||||
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -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;
|
46
src/log.rs
46
src/log.rs
@ -30,7 +30,7 @@ impl Default for Logger {
|
||||
impl Logger {
|
||||
pub const fn new() -> Self {
|
||||
Logger {
|
||||
level: LogLevel::WARNING,
|
||||
level: LogLevel::Warning,
|
||||
subscriber: Vec::new(),
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,10 @@ impl Logger {
|
||||
/// Calling log will sequentially acquire lock on all logging subscribers
|
||||
/// to write to them with a formatted log message.
|
||||
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 {
|
||||
for sub in &self.subscriber {
|
||||
let mut message = String::new();
|
||||
@ -50,24 +54,24 @@ impl Logger {
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub enum LogLevel {
|
||||
DISABLED,
|
||||
CRITICAL,
|
||||
ERROR,
|
||||
WARNING,
|
||||
INFO,
|
||||
TRACE,
|
||||
Disabled,
|
||||
Critical,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Trace,
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for LogLevel {
|
||||
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 {
|
||||
0 => Ok(Self::DISABLED),
|
||||
1 => Ok(Self::CRITICAL),
|
||||
2 => Ok(Self::ERROR),
|
||||
3 => Ok(Self::WARNING),
|
||||
4 => Ok(Self::INFO),
|
||||
5 => Ok(Self::TRACE),
|
||||
0 => Ok(Self::Disabled),
|
||||
1 => Ok(Self::Critical),
|
||||
2 => Ok(Self::Error),
|
||||
3 => Ok(Self::Warning),
|
||||
4 => Ok(Self::Info),
|
||||
5 => Ok(Self::Trace),
|
||||
_ => Err(EnumParseError {}),
|
||||
}
|
||||
}
|
||||
@ -75,14 +79,14 @@ impl TryFrom<u8> for LogLevel {
|
||||
|
||||
impl TryFrom<&str> for LogLevel {
|
||||
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() {
|
||||
"disabled" => Ok(Self::DISABLED),
|
||||
"critical" => Ok(Self::CRITICAL),
|
||||
"error" => Ok(Self::ERROR),
|
||||
"warning" => Ok(Self::WARNING),
|
||||
"info" => Ok(Self::INFO),
|
||||
"trace" => Ok(Self::TRACE),
|
||||
"disabled" => Ok(Self::Disabled),
|
||||
"critical" => Ok(Self::Critical),
|
||||
"error" => Ok(Self::Error),
|
||||
"warning" => Ok(Self::Warning),
|
||||
"info" => Ok(Self::Info),
|
||||
"trace" => Ok(Self::Trace),
|
||||
_ => Err(EnumParseError {}),
|
||||
}
|
||||
}
|
||||
|
40
src/main.rs
40
src/main.rs
@ -3,16 +3,20 @@
|
||||
#![feature(allocator_api)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use gila::arch::current::display;
|
||||
use gila::arch::current::*;
|
||||
use gila::boot::*;
|
||||
use gila::log::*;
|
||||
use gila::memory;
|
||||
use gila::memory::alloc::*;
|
||||
use gila::panic;
|
||||
use gila::params;
|
||||
use gila::params::get_kernel_params;
|
||||
use gila::process;
|
||||
mod arch;
|
||||
mod boot;
|
||||
mod log;
|
||||
mod memory;
|
||||
mod panic;
|
||||
mod params;
|
||||
mod process;
|
||||
mod resources;
|
||||
|
||||
use crate::arch::current::*;
|
||||
use crate::boot::*;
|
||||
use crate::log::*;
|
||||
use crate::memory::alloc::*;
|
||||
use crate::params::*;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn main() -> ! {
|
||||
@ -43,14 +47,14 @@ unsafe extern "C" fn main() -> ! {
|
||||
if log_device_list.contains(&"serial") {
|
||||
// Append serial console to log subs
|
||||
}
|
||||
log(LogLevel::INFO, "Configured kernel logging devices.")
|
||||
log(LogLevel::Info, "Configured kernel logging devices.")
|
||||
}
|
||||
|
||||
{
|
||||
let kernel_cmdline_string =
|
||||
string::String::from_utf8_lossy(kernel_file_response.file().cmdline());
|
||||
log(
|
||||
LogLevel::INFO,
|
||||
LogLevel::Info,
|
||||
&format!("Kernel cmdline: {}", 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());
|
||||
log(
|
||||
LogLevel::INFO,
|
||||
LogLevel::Info,
|
||||
&format!("Kernel file path: {}", kernel_path),
|
||||
);
|
||||
drop(kernel_path);
|
||||
}
|
||||
}
|
||||
|
||||
log(LogLevel::INFO, "Log devices configured. Booting `gila`.");
|
||||
log(LogLevel::INFO, "Trans Rights!");
|
||||
log(LogLevel::Info, "Log devices configured. Booting `gila`.");
|
||||
log(LogLevel::Info, "Trans Rights!");
|
||||
|
||||
let _smp_response = SMP_REQUEST.get_response();
|
||||
|
||||
match _smp_response {
|
||||
None => log(
|
||||
LogLevel::ERROR,
|
||||
LogLevel::Error,
|
||||
"SMP response not received. Multiprocessing is disabled.",
|
||||
),
|
||||
Some(resp) => {
|
||||
log(
|
||||
LogLevel::INFO,
|
||||
LogLevel::Info,
|
||||
"SMP response received. Multiprocessing enabled.",
|
||||
);
|
||||
log(
|
||||
LogLevel::INFO,
|
||||
LogLevel::Info,
|
||||
&format!("{} CPUs found.", resp.cpus().len()),
|
||||
);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
use flagset::flags;
|
||||
|
||||
use core::alloc::{Allocator, Layout};
|
||||
use spin;
|
||||
use talc::*;
|
||||
|
||||
pub extern crate alloc;
|
||||
|
@ -6,6 +6,7 @@ use crate::memory::alloc;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct ProcessTable {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@ -32,9 +33,10 @@ pub struct Process {
|
||||
semaphor_wait: Option<u32>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum ProcessState {
|
||||
RUNNING,
|
||||
WAITING,
|
||||
SLEEPING,
|
||||
SUSPENDED,
|
||||
Running,
|
||||
Waiting,
|
||||
Sleeping,
|
||||
Suspended,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user