This commit is contained in:
Evie Viau-Chow-Stuart 2025-06-30 19:48:24 -07:00
commit 1d21e34174
Signed by: evie
GPG key ID: 928652CDFCEC8099
10 changed files with 248 additions and 0 deletions

5
.cargo/config.toml Normal file
View file

@ -0,0 +1,5 @@
[build]
target = "./x86_64-unknown-hypericum.json"
[unstable]
build-std = ["core", "alloc"]

14
.gitignore vendored Normal file
View file

@ -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*/

50
Cargo.lock generated Normal file
View file

@ -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",
]

13
Cargo.toml Normal file
View file

@ -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 = []

21
LICENSE Normal file
View file

@ -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.

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# libgoatweed
Library for the [Hypericum](https://forge.gaycatgirl.sex/hypericum) operating system.

23
src/alloc.rs Normal file
View file

@ -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);
}
}
}

28
src/lib.rs Normal file
View file

@ -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,
}

60
src/syscalls.rs Normal file
View file

@ -0,0 +1,60 @@
use core::arch::asm;
#[repr(u64)]
pub enum Syscall {
KTest = 0,
PSpawn,
MMap,
MUnmap,
KQuirky,
Invalid = 999999999999999,
}
impl From<u64> 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);
}
}

View file

@ -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"
}