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"
|
||||
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:
|
||||
@ -12,17 +24,9 @@ prepare:
|
||||
# Run the ISO in an emulator.
|
||||
run: build/gila.iso
|
||||
|
||||
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"
|
||||
else ifeq ($(TARGET),loongarch64-unknown-none)
|
||||
QEMU = "qemu-system-loongarch64"
|
||||
endif
|
||||
echo $(qemu)
|
||||
|
||||
$(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.
|
||||
.PHONY: build/iso/gila
|
||||
|
3
build.rs
3
build.rs
@ -1,8 +1,7 @@
|
||||
fn main() {
|
||||
|
||||
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
||||
// Tell cargo to pass the linker script to the linker..
|
||||
println!("cargo:rustc-link-arg=-Tlinker-scripts/linker-{arch}.ld");
|
||||
// ..and to re-run if it changes.
|
||||
println!("cargo:rerun-if-changed=linker-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;
|
@ -1,4 +1,19 @@
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub mod 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,
|
||||
}
|
||||
}
|
||||
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 display;
|
||||
pub mod asm;
|
||||
pub mod display;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use limine::{request::*, BaseRevision};
|
||||
use limine::{BaseRevision, request::*};
|
||||
|
||||
#[used]
|
||||
#[unsafe(link_section = ".requests_start_marker")]
|
||||
@ -14,4 +14,7 @@ static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
|
||||
pub static BASE_REVISION: BaseRevision = limine::BaseRevision::new();
|
||||
#[used]
|
||||
#[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]
|
||||
#![feature(allocator_api)]
|
||||
|
||||
/// Process representation.
|
||||
pub mod process;
|
||||
/// Boot services, handled by the Limine boot protocol.
|
||||
pub mod boot;
|
||||
/// Memory regions, allocation, flags, and whatnot.
|
||||
pub mod memory;
|
||||
/// Panic handling function logic.
|
||||
pub mod panic;
|
||||
/// Boot services, handled by the Limine boot protocol.
|
||||
pub mod boot;
|
||||
/// 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;
|
||||
|
||||
|
26
src/main.rs
26
src/main.rs
@ -1,35 +1,31 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#![feature(allocator_api)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
use gila::arch::current::*;
|
||||
use gila::boot::*;
|
||||
use gila::process;
|
||||
use gila::memory;
|
||||
use gila::panic;
|
||||
use gila::boot;
|
||||
use gila::arch::current::display;
|
||||
use gila::params;
|
||||
use gila::params::get_kernel_params;
|
||||
use gila::process;
|
||||
//use gila::arch::current::display;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn main() -> !{
|
||||
|
||||
unsafe extern "C" fn main() -> ! {
|
||||
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();
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
asm!("hlt");
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
||||
asm!("wfi");
|
||||
#[cfg(target_arch = "loongarch64")]
|
||||
asm!("idle 0");
|
||||
asm::halt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
use flagset::flags;
|
||||
|
||||
use talc::*;
|
||||
use spin;
|
||||
use core::alloc::{Allocator, Layout};
|
||||
use spin;
|
||||
use talc::*;
|
||||
|
||||
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
|
||||
// main() is called, so we need to initialize the arena automatically
|
||||
ClaimOnOom::new(Span::from_array(core::ptr::addr_of!(ARENA).cast_mut()))
|
||||
}).lock();
|
||||
|
||||
})
|
||||
.lock();
|
||||
|
||||
pub struct MemoryRegion {
|
||||
start_address: usize,
|
||||
@ -29,4 +29,4 @@ flags! {
|
||||
WRITABLE,
|
||||
EXECUTABLE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
use core::panic::*;
|
||||
|
||||
#[panic_handler]
|
||||
pub fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub struct ProcessTable {}
|
||||
|
||||
@ -39,5 +39,4 @@ pub enum ProcessState {
|
||||
WAITING,
|
||||
SLEEPING,
|
||||
SUSPENDED,
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user