diff --git a/Makefile.toml b/Makefile.toml index 0594723..345caea 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -19,15 +19,18 @@ env_scripts = [ set_env QEMUCOMMAND "qemu-system-loongarch64" set_env LIMINEBIN "BOOTLOONGARCH64.EFI" end + if eq ${LIMINEDIR} "" + set_env LIMINEDIR "/usr/share/limine" + end ''' ] -[config] +[config] default_to_workspace = false [env] # Directory for Limine binaries -LIMINEDIR = "/usr/share/limine" + # Compile target TARGET = "x86_64-unknown-none" diff --git a/configs/limine.conf b/configs/limine.conf index cd77d0d..b67cd90 100644 --- a/configs/limine.conf +++ b/configs/limine.conf @@ -4,6 +4,5 @@ timeout: 0 protocol: limine kernel_path: boot():/boot/${ARCH}/gila cmdline: -loglevel=Trace -logdev=display,serial -initramfs=/boot/${ARCH}/initramfs.tar.lzma - module_path: boot():/boot/${ARCH}/initramfs.tar.lzma kaslr: yes randomize_hhdm_base: yes diff --git a/docs/DEVELOPMENT.MD b/docs/DEVELOPMENT.MD index f6cb2cd..27b11c1 100644 --- a/docs/DEVELOPMENT.MD +++ b/docs/DEVELOPMENT.MD @@ -54,14 +54,23 @@ containing system servers, such as the init server and device drivers. This project uses [cargo-make](https://github.com/sagiegurari/cargo-make) to handle building ISOs and managing files not associated with Cargo. You need to install it before you can build an ISO automatically. To do so, you can run -`cargo install cargo-make`. In addition, you will also need: +`cargo install cargo-make`. + +### Dependencies + +If you use NixOS or the Nix package manager, simply run `nix-shell` in the root +directory. All necessary dependencies will be made available. + +If not, the following dependencies will need to be manually installed: - `rustup` command installed - `limine` command installed - `xorriso` command installed - `qemu-system-{your target architecture}` command installed (for running) -Then run `cargo make` to invoke the [Makefile.toml](../Makefile.toml). +### Build System + +Run `cargo make` to invoke the [Makefile.toml](../Makefile.toml). - `cargo make clean_all`: Cleans all built binaries, libraries, initramfs files, and ISOs. diff --git a/kernel/src/arch/x86_64/gdt.rs b/kernel/src/arch/x86_64/gdt.rs index 4441748..b9b98dd 100644 --- a/kernel/src/arch/x86_64/gdt.rs +++ b/kernel/src/arch/x86_64/gdt.rs @@ -44,6 +44,7 @@ pub fn read_gdt() -> GlobalDescriptorTable { // Bits 16 through 79 are the virtual address of the GDT. let limit = addr.bits(0..=15) as usize + 1; let base = addr.bits(16..=79) as u64; - let gdt_raw: &[u64] = unsafe { core::slice::from_raw_parts(base as *const u64, (limit / 8) - 1) }; + let gdt_raw: &[u64] = + unsafe { core::slice::from_raw_parts(base as *const u64, (limit / 8) - 1) }; GlobalDescriptorTable::from_raw_entries(gdt_raw) } diff --git a/kernel/src/boot/modules.rs b/kernel/src/boot/modules.rs index 9d40939..6e9bb47 100644 --- a/kernel/src/boot/modules.rs +++ b/kernel/src/boot/modules.rs @@ -19,20 +19,22 @@ pub static FILE_REQUEST: ExecutableFileRequest = limine::request::ExecutableFile pub static MODULE_REQUEST: ModuleRequest = limine::request::ModuleRequest::new(); lazy_static! { - pub static ref MODULE_RESPONSE: &'static ModuleResponse = MODULE_REQUEST - .get_response() - .expect("Bootloader did not return kernel modules"); + pub static ref MODULE_RESPONSE: Option<&'static ModuleResponse> = MODULE_REQUEST.get_response(); } pub fn log_modules() { - if !MODULE_RESPONSE.modules().is_empty() { - let mut log_msg: String = String::from("Kernel modules list:\n"); - for module in MODULE_RESPONSE.modules() { - log_msg.push_str(&format!( - "\t{}", - String::from_utf8_lossy(module.path().to_bytes()) - )); + if let Some(modules) = *MODULE_RESPONSE { + if !modules.modules().is_empty() { + let mut log_msg: String = String::from("Kernel modules list:\n"); + for module in modules.modules() { + log_msg.push_str(&format!( + "\t{}", + String::from_utf8_lossy(module.path().to_bytes()) + )); + } + log_trace!("{log_msg}") } - log_trace!("{log_msg}") + } else { + log_trace!("No modules found."); } } diff --git a/kernel/src/main.rs b/kernel/src/main.rs index fb6b456..66454e2 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -16,8 +16,6 @@ mod panic; mod process; mod util; -use core::{arch::asm, ptr::addr_of}; - use arch::x86_64::interrupts::IDT; use arch::x86_64::serial::SerialPort; use boot::{BASE_REVISION, params, *}; @@ -31,7 +29,10 @@ use limine::firmware_type::FirmwareType; use spin::mutex::Mutex; use crate::{ - arch::x86_64::{cpuid::{CPUID, virt_supported}, gdt::GdtEntryRead}, + arch::x86_64::{ + cpuid::{CPUID, virt_supported}, + gdt::GdtEntryRead, + }, memory::HHDM_RESPONSE, }; @@ -168,7 +169,11 @@ unsafe extern "C" fn main() -> ! { let gdt = crate::arch::x86_64::gdt::read_gdt(); log_info!("GDT length: {}", gdt.limit() + 1); for entry in gdt.entries() { - log_info!("GDT entry: Flags 0b{:b}, Access 0b{:b}", entry.flags(), entry.access()); + log_info!( + "GDT entry: Flags 0b{:b}, Access 0b{:b}", + entry.flags(), + entry.access() + ); } panic!("Finished boot, but cannot start init because processes not implemented!"); diff --git a/kernel/src/memory/mod.rs b/kernel/src/memory/mod.rs index 0bc0542..a90d935 100644 --- a/kernel/src/memory/mod.rs +++ b/kernel/src/memory/mod.rs @@ -96,7 +96,10 @@ pub fn log_address() { resp.physical_base() ); log_info!("Kernel virtual start address: 0x{:x}", resp.virtual_base()); - log_info!("Kernel physical start address (calculated): 0x{:x}", 0i64 - resp.virtual_base() as i64 + resp.physical_base() as i64); + log_info!( + "Kernel physical start address (calculated): 0x{:x}", + 0i64 - resp.virtual_base() as i64 + resp.physical_base() as i64 + ); } else { log_warning!("No kernel address response provided."); } diff --git a/kernel/src/memory/paging.rs b/kernel/src/memory/paging.rs index 7ed5262..7bd8529 100644 --- a/kernel/src/memory/paging.rs +++ b/kernel/src/memory/paging.rs @@ -1,17 +1,14 @@ - -use x86_64::structures::paging::PageTable; -use x86_64::VirtAddr; use lazy_static::lazy_static; +use x86_64::VirtAddr; +use x86_64::structures::paging::PageTable; use x86_64::structures::paging::PageTableFlags; use crate::log::*; -use crate::memory::format; use crate::memory::HHDM_RESPONSE; +use crate::memory::format; #[allow(dead_code)] -pub unsafe fn active_level_4_table() - -> &'static mut PageTable -{ +pub unsafe fn active_level_4_table() -> &'static mut PageTable { use x86_64::registers::control::Cr3; let (level_4_table_frame, _) = Cr3::read(); @@ -44,9 +41,6 @@ pub fn iter_table(level: usize, table: &PageTable) { } } - - - /* let l4_table = unsafe { active_level_4_table() }; @@ -68,4 +62,4 @@ pub fn iter_table(level: usize, table: &PageTable) { } } } -*/ \ No newline at end of file +*/ diff --git a/libgila/src/syscall/mod.rs b/libgila/src/syscall/mod.rs index 3d5f69c..c903cff 100644 --- a/libgila/src/syscall/mod.rs +++ b/libgila/src/syscall/mod.rs @@ -5,8 +5,7 @@ use num_traits::FromPrimitive; use crate::arch; -pub struct SyscallError { -} +pub struct SyscallError {} #[repr(u32)] #[derive(FromPrimitive, Debug)] diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..716c9fb --- /dev/null +++ b/shell.nix @@ -0,0 +1,28 @@ +let + nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"; + pkgs = import nixpkgs { config = {}; overlays = []; }; +in + +pkgs.mkShell { + + packages = with pkgs; [ + bash + limine-full + xorriso + rustup + qemu + cargo-make + ]; + + buildInputs = with pkgs; [ + limine-full + ]; + + shellHook = '' + rustup default nightly; + rustup target add x86_64-unknown-none + export LIMINEDIR="${pkgs.limine-full}/share/limine" + ''; + +} +