commit 1d21e34174446ed1e6eb42ddb09d28e51bb37fed Author: Evie Viau Date: Mon Jun 30 19:48:24 2025 -0700 init diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..379267c --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "./x86_64-unknown-hypericum.json" + +[unstable] +build-std = ["core", "alloc"] \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f320c71 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +**/debug +**/target + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Generated by cargo mutants +# Contains mutation testing data +**/mutants.out*/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..471d399 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,50 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "libgoatweed" +version = "0.1.0" +dependencies = [ + "linked_list_allocator", +] + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +dependencies = [ + "lock_api", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..aff585c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "libgoatweed" +version = "0.1.0" +edition = "2024" +license = "MIT" + +[dependencies] +linked_list_allocator = { version = "0.10.5", optional = true } + +[features] +default = ["alloc", "panic"] +alloc = ["dep:linked_list_allocator"] +panic = [] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3a6122d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Evie Robert Dolomont Viau-Chow-Stuart + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3eb91e4 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# libgoatweed +Library for the [Hypericum](https://forge.gaycatgirl.sex/hypericum) operating system. \ No newline at end of file diff --git a/src/alloc.rs b/src/alloc.rs new file mode 100644 index 0000000..ad22fe1 --- /dev/null +++ b/src/alloc.rs @@ -0,0 +1,23 @@ +use crate::syscalls; +use linked_list_allocator::LockedHeap; + +// TODO: replace with a more dynamic allocator +#[global_allocator] +static ALLOCATOR: LockedHeap = LockedHeap::empty(); + +/// Initializes the global heap allocator. +/// +/// This function must be called exactly once from the user-space program before +/// any allocations are made. +/// +/// THIS WILL PROBABLY BE REPLACED IN THE FUTURE BUT THE API WILL STAY THE SAME +pub fn init() { + const HEAP_SIZE: usize = 128 * 1024; // 128 KiB heap + let heap_start = syscalls::m_map(HEAP_SIZE); + + if !heap_start.is_null() { + unsafe { + ALLOCATOR.lock().init(heap_start, HEAP_SIZE); + } + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1865aad --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,28 @@ +#![no_std] + +use core::panic::PanicInfo; + +pub mod syscalls; + +#[cfg(feature = "alloc")] +pub mod alloc; + +#[cfg(feature = "panic")] +#[panic_handler] +fn panic(_: &PanicInfo) -> ! { + loop { + core::hint::spin_loop(); + } +} + +pub enum ProcessState { + Running, + Sleeping, + Zombie, +} + +pub struct ProcessInfo { + pub pid: usize, + pub parent_pid: usize, + pub state: ProcessState, +} diff --git a/src/syscalls.rs b/src/syscalls.rs new file mode 100644 index 0000000..d79a0e7 --- /dev/null +++ b/src/syscalls.rs @@ -0,0 +1,60 @@ +use core::arch::asm; + +#[repr(u64)] +pub enum Syscall { + KTest = 0, + PSpawn, + MMap, + MUnmap, + KQuirky, + Invalid = 999999999999999, +} + +impl From for Syscall { + fn from(value: u64) -> Self { + match value { + 0 => Syscall::KTest, + 1 => Syscall::PSpawn, + 2 => Syscall::MMap, + 3 => Syscall::MUnmap, + 4 => Syscall::KQuirky, + _ => Syscall::Invalid, + } + } +} + +pub fn k_test() { + unsafe { + asm!("mov rax, {}", "int 0x80", in(reg) Syscall::KTest as u64); + } +} + +pub fn p_spawn(location: *const u8, length: usize) { + unsafe { + asm!("mov rax, {}", "mov rbx, {}", "mov rcx, {}", "int 0x80", in(reg) Syscall::PSpawn as u64, in(reg) location, in(reg) length); + } +} + +pub fn m_map(size: usize) -> *mut u8 { + let mut addr: usize; + + unsafe { + asm!("mov rax, {}", "mov rbx, {}", "int 0x80", in(reg) Syscall::MMap as u64, in(reg) size); + + asm!("mov {}, rax", out(reg) addr); + } + + addr as *mut u8 +} + +pub fn m_unmap(addr: *mut u8, size: usize) { + unsafe { + asm!("mov rax, {}", "mov rbx, {}", "mov rcx, {}", "int 0x80", in(reg) Syscall::MUnmap as u64, in(reg) addr, in(reg) size); + } +} + +pub fn k_quirky(num: u64) { + unsafe { + asm!("mov rax, {}", "mov rbx, {}", "int 0x80", in(reg) Syscall::KQuirky as u64, in(reg) num); + } +} diff --git a/x86_64-unknown-hypericum.json b/x86_64-unknown-hypericum.json new file mode 100644 index 0000000..f77865a --- /dev/null +++ b/x86_64-unknown-hypericum.json @@ -0,0 +1,32 @@ +{ + "arch": "x86_64", + "cpu": "x86-64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", + "disable-redzone": true, + "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2,+soft-float", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "x86_64-unknown-none-elf", + "max-atomic-width": 64, + "metadata": { + "description": "Hypericum", + "host_tools": false, + "std": false + }, + "os": "hypericum", + "panic-strategy": "abort", + "plt-by-default": false, + "position-independent-executables": false, + "relro-level": "off", + "rustc-abi": "x86-softfloat", + "stack-probes": { + "kind": "inline" + }, + "static-position-independent-executables": true, + "supported-sanitizers": [ + "kcfi", + "kernel-address" + ], + "target-pointer-width": "64" +} \ No newline at end of file