Work for kernel params
This commit is contained in:
parent
e8d856d013
commit
32779a05bc
28
Makefile
28
Makefile
@ -1,8 +1,20 @@
|
|||||||
|
|
||||||
TARGET ?= "x86_64-unknown-none"
|
TARGET ?= "x86_64-unknown-none"
|
||||||
QEMU ?= "qemu-system-x86_64"
|
qemu = "qemu-system-x86_64"
|
||||||
|
|
||||||
all: clean prepare gila iso run
|
ifeq ($(TARGET),x86_64-unknown-none)
|
||||||
|
qemu = "qemu-system-x86_64"
|
||||||
|
else ifeq ($(TARGET),riscv64gc-unknown-none-elf)
|
||||||
|
qemu = "qemu-system-riscv64"
|
||||||
|
else ifeq ($(TARGET),aarch64-unknown-none)
|
||||||
|
qemu = "qemu-system-aarch64"
|
||||||
|
qemu += "-machine"
|
||||||
|
qemu += "orangepi-pc"
|
||||||
|
else ifeq ($(TARGET),loongarch64-unknown-none)
|
||||||
|
qemu = "qemu-system-loongarch64"
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: gila iso run
|
||||||
|
|
||||||
# Prepare toolchain
|
# Prepare toolchain
|
||||||
prepare:
|
prepare:
|
||||||
@ -12,17 +24,9 @@ prepare:
|
|||||||
# Run the ISO in an emulator.
|
# Run the ISO in an emulator.
|
||||||
run: build/gila.iso
|
run: build/gila.iso
|
||||||
|
|
||||||
ifeq ($(TARGET),x86_64-unknown-none)
|
echo $(qemu)
|
||||||
QEMU = "qemu-system-x86_64"
|
|
||||||
else ifeq ($(TARGET),riscv64gc-unknown-none-elf)
|
|
||||||
QEMU = "qemu-system-riscv64"
|
|
||||||
else ifeq ($(TARGET),aarch64-unknown-none)
|
|
||||||
QEMU = "qemu-system-aarch64"
|
|
||||||
else ifeq ($(TARGET),loongarch64-unknown-none)
|
|
||||||
QEMU = "qemu-system-loongarch64"
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(QEMU) -drive file=build/gila.iso,format=raw,index=0,media=disk
|
$(qemu) -drive file=build/gila.iso,format=raw,index=0,media=disk
|
||||||
|
|
||||||
# Build the bootable kernel image.
|
# Build the bootable kernel image.
|
||||||
.PHONY: build/iso/gila
|
.PHONY: build/iso/gila
|
||||||
|
1
build.rs
1
build.rs
@ -1,5 +1,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
||||||
// Tell cargo to pass the linker script to the linker..
|
// Tell cargo to pass the linker script to the linker..
|
||||||
println!("cargo:rustc-link-arg=-Tlinker-scripts/linker-{arch}.ld");
|
println!("cargo:rustc-link-arg=-Tlinker-scripts/linker-{arch}.ld");
|
||||||
|
7
src/arch/aarch64/asm.rs
Normal file
7
src/arch/aarch64/asm.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
pub unsafe fn halt() {
|
||||||
|
unsafe {
|
||||||
|
asm!("wfi");
|
||||||
|
}
|
||||||
|
}
|
1
src/arch/aarch64/display.rs
Normal file
1
src/arch/aarch64/display.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
2
src/arch/aarch64/mod.rs
Normal file
2
src/arch/aarch64/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod asm;
|
||||||
|
pub mod display;
|
7
src/arch/loongarch64/asm.rs
Normal file
7
src/arch/loongarch64/asm.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
pub unsafe fn halt() {
|
||||||
|
unsafe {
|
||||||
|
asm!("idle 0");
|
||||||
|
}
|
||||||
|
}
|
1
src/arch/loongarch64/display.rs
Normal file
1
src/arch/loongarch64/display.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
2
src/arch/loongarch64/mod.rs
Normal file
2
src/arch/loongarch64/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod asm;
|
||||||
|
pub mod display;
|
@ -2,3 +2,18 @@
|
|||||||
pub mod x86_64;
|
pub mod x86_64;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub use x86_64 as current;
|
pub use x86_64 as current;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
pub mod aarch64;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
pub use aarch64 as current;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "riscv64")]
|
||||||
|
pub mod riscv64;
|
||||||
|
#[cfg(target_arch = "riscv64")]
|
||||||
|
pub use riscv64 as current;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "loongarch64")]
|
||||||
|
pub mod loongarch64;
|
||||||
|
#[cfg(target_arch = "loongarch64")]
|
||||||
|
pub use loongarch64 as current;
|
||||||
|
7
src/arch/riscv64/asm.rs
Normal file
7
src/arch/riscv64/asm.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
pub unsafe fn halt() {
|
||||||
|
unsafe {
|
||||||
|
asm!("wfi");
|
||||||
|
}
|
||||||
|
}
|
1
src/arch/riscv64/display.rs
Normal file
1
src/arch/riscv64/display.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
2
src/arch/riscv64/mod.rs
Normal file
2
src/arch/riscv64/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod asm;
|
||||||
|
pub mod display;
|
7
src/arch/x86_64/asm.rs
Normal file
7
src/arch/x86_64/asm.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
pub unsafe fn halt() {
|
||||||
|
unsafe {
|
||||||
|
asm!("hlt");
|
||||||
|
}
|
||||||
|
}
|
@ -18,13 +18,9 @@ impl TextDisplay {
|
|||||||
row: 0,
|
row: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn writeline(text: &str, colors: vga::colors::TextModeColor) {
|
pub fn writeline(text: &str, colors: vga::colors::TextModeColor) {}
|
||||||
|
|
||||||
}
|
pub fn write(text: &str, colors: vga::colors::TextModeColor) {}
|
||||||
|
|
||||||
pub fn write(text: &str, colors: vga::colors::TextModeColor) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static TEXT_DISPLAY: TextDisplay = TextDisplay::new();
|
pub static TEXT_DISPLAY: TextDisplay = TextDisplay::new();
|
@ -1 +1,2 @@
|
|||||||
|
pub mod asm;
|
||||||
pub mod display;
|
pub mod display;
|
@ -1,6 +1,6 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use limine::{request::*, BaseRevision};
|
use limine::{BaseRevision, request::*};
|
||||||
|
|
||||||
#[used]
|
#[used]
|
||||||
#[unsafe(link_section = ".requests_start_marker")]
|
#[unsafe(link_section = ".requests_start_marker")]
|
||||||
@ -15,3 +15,6 @@ pub static BASE_REVISION: BaseRevision = limine::BaseRevision::new();
|
|||||||
#[used]
|
#[used]
|
||||||
#[unsafe(link_section = ".requests")]
|
#[unsafe(link_section = ".requests")]
|
||||||
pub static SMP_REQUEST: SmpRequest = limine::request::SmpRequest::new();
|
pub static SMP_REQUEST: SmpRequest = limine::request::SmpRequest::new();
|
||||||
|
#[used]
|
||||||
|
#[unsafe(link_section = ".requests")]
|
||||||
|
pub static FILE_REQUEST: KernelFileRequest = limine::request::KernelFileRequest::new();
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -1,14 +1,16 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
|
|
||||||
/// Process representation.
|
/// Boot services, handled by the Limine boot protocol.
|
||||||
pub mod process;
|
pub mod boot;
|
||||||
/// Memory regions, allocation, flags, and whatnot.
|
/// Memory regions, allocation, flags, and whatnot.
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
/// Panic handling function logic.
|
/// Panic handling function logic.
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
/// Boot services, handled by the Limine boot protocol.
|
/// Kernel command line parameter structure and enums.
|
||||||
pub mod boot;
|
pub mod params;
|
||||||
|
/// Process representation.
|
||||||
|
pub mod process;
|
||||||
/// Resources accessible from many parts of the code.
|
/// Resources accessible from many parts of the code.
|
||||||
pub mod resources;
|
pub mod resources;
|
||||||
|
|
||||||
|
26
src/main.rs
26
src/main.rs
@ -1,35 +1,31 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use core::arch::asm;
|
use gila::arch::current::*;
|
||||||
|
|
||||||
use gila::boot::*;
|
use gila::boot::*;
|
||||||
use gila::process;
|
|
||||||
use gila::memory;
|
use gila::memory;
|
||||||
use gila::panic;
|
use gila::panic;
|
||||||
use gila::boot;
|
use gila::params;
|
||||||
use gila::arch::current::display;
|
use gila::params::get_kernel_params;
|
||||||
|
use gila::process;
|
||||||
|
//use gila::arch::current::display;
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn main() -> !{
|
unsafe extern "C" fn main() -> ! {
|
||||||
|
|
||||||
assert!(BASE_REVISION.is_supported());
|
assert!(BASE_REVISION.is_supported());
|
||||||
|
|
||||||
|
let kernel_file_response = FILE_REQUEST.get_response().unwrap();
|
||||||
|
|
||||||
|
let _kernel_parameters = get_kernel_params(kernel_file_response.file().cmdline());
|
||||||
|
|
||||||
let _smp_response = SMP_REQUEST.get_response();
|
let _smp_response = SMP_REQUEST.get_response();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe {
|
||||||
#[cfg(target_arch = "x86_64")]
|
asm::halt();
|
||||||
asm!("hlt");
|
|
||||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
|
||||||
asm!("wfi");
|
|
||||||
#[cfg(target_arch = "loongarch64")]
|
|
||||||
asm!("idle 0");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
use flagset::flags;
|
use flagset::flags;
|
||||||
|
|
||||||
use talc::*;
|
|
||||||
use spin;
|
|
||||||
use core::alloc::{Allocator, Layout};
|
use core::alloc::{Allocator, Layout};
|
||||||
|
use spin;
|
||||||
|
use talc::*;
|
||||||
|
|
||||||
static mut ARENA: [u8; 10000] = [0; 10000];
|
static mut ARENA: [u8; 10000] = [0; 10000];
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
|
|||||||
// if we're in a hosted environment, the Rust runtime may allocate before
|
// if we're in a hosted environment, the Rust runtime may allocate before
|
||||||
// main() is called, so we need to initialize the arena automatically
|
// main() is called, so we need to initialize the arena automatically
|
||||||
ClaimOnOom::new(Span::from_array(core::ptr::addr_of!(ARENA).cast_mut()))
|
ClaimOnOom::new(Span::from_array(core::ptr::addr_of!(ARENA).cast_mut()))
|
||||||
}).lock();
|
})
|
||||||
|
.lock();
|
||||||
|
|
||||||
pub struct MemoryRegion {
|
pub struct MemoryRegion {
|
||||||
start_address: usize,
|
start_address: usize,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use core::panic::*;
|
use core::panic::*;
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
|
24
src/params.rs
Normal file
24
src/params.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
extern crate alloc;
|
||||||
|
use alloc::string::String;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
pub type KernelParameters = alloc::collections::BTreeMap<String, String>;
|
||||||
|
|
||||||
|
// This parsing is godawful.
|
||||||
|
pub fn get_kernel_params(cmdline: &[u8]) -> KernelParameters {
|
||||||
|
let cmd_str = String::from_utf8_lossy(cmdline).into_owned();
|
||||||
|
let args: Vec<&str> = cmd_str.split_ascii_whitespace().collect();
|
||||||
|
let mut params: alloc::collections::BTreeMap<String, String> =
|
||||||
|
alloc::collections::BTreeMap::new();
|
||||||
|
for arg in args {
|
||||||
|
let split: Vec<&str> = arg.split('=').collect();
|
||||||
|
if let Some(first) = split.first() {
|
||||||
|
if split.len() > 1 {
|
||||||
|
params.insert(String::from(*first), split[1..].join("="));
|
||||||
|
} else {
|
||||||
|
params.insert(String::from(*first), String::new());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params
|
||||||
|
}
|
@ -6,8 +6,8 @@ use crate::memory::MemoryRegion;
|
|||||||
use lazy_static;
|
use lazy_static;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::vec::Vec;
|
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
pub struct ProcessTable {}
|
pub struct ProcessTable {}
|
||||||
|
|
||||||
@ -39,5 +39,4 @@ pub enum ProcessState {
|
|||||||
WAITING,
|
WAITING,
|
||||||
SLEEPING,
|
SLEEPING,
|
||||||
SUSPENDED,
|
SUSPENDED,
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1 @@
|
|||||||
|
|
Loading…
Reference in New Issue
Block a user