diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e265cca --- /dev/null +++ b/build.sh @@ -0,0 +1,76 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: Top-level build driver +# Author: Chloe M. +# + +# Globals +MAKE=make + +# +# Check if a list of programs are installed on the system +# +# <@>: List of programs to check +# +check_deps() { + for dep in $@; do + printf "\033[33;40mChecking if $dep is installed... " + which $dep &>/dev/null + if [ $? -ne 0 ]; then + echo -e "\033[31;40mno" + echo -e "fatal: Please install '$dep'!\033[0m" + exit 1 + fi + + echo -e "\033[32;40myes\033[0m" + done +} + +# +# Verify that the build environment is sane before we actually +# start. +# +build_verify() { + check_deps \ + clang \ + rsync \ + xorriso + + # We need build envs !! + if [ -z "${ST_BUILD_SOURCED}" ] + then + echo -e "\033[31;40mfatal\033[0m: Please run '. paw/devel/build.env' first!" + exit 1 + fi +} + +# +# <$1>: Build target +# <$2>: Build message +# +make_build() { + echo -e "\033[37m[\033[35m*\033[37m] \033[32;40m$2\033[0m" + pushd $1; \ + $MAKE + popd +} + +# +# Kick off the actual build process +# +build() { + mkdir -p artifacts/ + + make_build \ + paw/stos \ + "Building system kernel..." + + make_build \ + paw/boot \ + "Building bootloader..." +} + +build_verify +build diff --git a/paw/base/boot/limine.conf b/paw/base/boot/limine.conf new file mode 100644 index 0000000..f1ccef8 --- /dev/null +++ b/paw/base/boot/limine.conf @@ -0,0 +1,12 @@ +timeout: 16 +interface_branding_color: 7 + +interface_branding: -- Yiff! -- + +editor_enabled: no +interface_help_hidden: yes +randomize_hhdm_base: yes + +/SystemPaw 3 + protocol: limine + kernel_path: boot():/boot/stoskrnl.sys diff --git a/paw/base/boot/splash.rgba b/paw/base/boot/splash.rgba new file mode 100644 index 0000000..8202951 Binary files /dev/null and b/paw/base/boot/splash.rgba differ diff --git a/paw/boot/Makefile b/paw/boot/Makefile new file mode 100644 index 0000000..6286de1 --- /dev/null +++ b/paw/boot/Makefile @@ -0,0 +1,15 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# + +.PHONY: all +all: deps iso + +.PHONY: deps +deps: + ./host/deps.sh + +.PHONY: iso +iso: + ./host/iso.sh diff --git a/paw/boot/host/deps.sh b/paw/boot/host/deps.sh new file mode 100755 index 0000000..7dc252d --- /dev/null +++ b/paw/boot/host/deps.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# + +if [ ! -d stand/limine ]; then + git clone https://codeberg.org/Limine/Limine.git --branch=v10.x-binary --depth=1 stand/limine + make -C stand/limine +fi diff --git a/paw/boot/host/iso.sh b/paw/boot/host/iso.sh new file mode 100755 index 0000000..a9f4835 --- /dev/null +++ b/paw/boot/host/iso.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# + +set -e + +ISO=$ST_PROJECT_ROOT/artifacts/sp3.iso +CONFIG=$ST_PROJECT_ROOT/paw/base/boot/limine.conf +KERNEL=$ST_PROJECT_ROOT/artifacts/stoskrnl.sys + +mkdir -p iso_root/boot/ + +# Copy the kernel to the ISO root +cp $KERNEL iso_root/boot + +# Copy boot files +cp $CONFIG stand/limine/limine-bios.sys \ + stand/limine/limine-bios-cd.bin \ + stand/limine/limine-uefi-cd.bin \ + iso_root/ + +# Generate the ISO +xorriso -as mkisofs -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 \ + -boot-info-table --efi-boot limine-uefi-cd.bin -efi-boot-part \ + --efi-boot-image --protective-msdos-label iso_root/ -o $ISO 2>/dev/null + +stand/limine/limine bios-install $ISO 2>/dev/null +rm -rf iso_root diff --git a/paw/devel/build.env b/paw/devel/build.env new file mode 100644 index 0000000..ef69c50 --- /dev/null +++ b/paw/devel/build.env @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: Build envs +# Author: Chloe M. +# + +# Source build variables +. paw/devel/vars.env + +# Export envs +export ST_PROJECT_ROOT=$ST_PROJECT_ROOT +export ST_TARGET_ARCH=$ST_TARGET_ARCH +export ST_BOOT_PROTOCOL=$ST_BOOT_PROTOCOL + +if [ "$ST_BUILD_SOURCED" != "1" ] +then + echo "[*] build env ok" + export PS1="~ $PS1" +fi + +# Indicate that we have been sourced +export ST_BUILD_SOURCED=1 diff --git a/paw/devel/vars.env b/paw/devel/vars.env new file mode 100644 index 0000000..6727220 --- /dev/null +++ b/paw/devel/vars.env @@ -0,0 +1,11 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: Build variables +# Author: Chloe M. +# + +ST_PROJECT_ROOT=$(pwd) +ST_TARGET_ARCH=amd64 +ST_BOOT_PROTOCOL=limine diff --git a/paw/mk/stos.mk b/paw/mk/stos.mk new file mode 100644 index 0000000..94e6467 --- /dev/null +++ b/paw/mk/stos.mk @@ -0,0 +1,52 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: Build flags and such +# Author: Chloe M. +# + +PROMPT := printf "%s\t\t%s\n" +CC_PREFIX = + +ifeq ($(ST_TARGET_ARCH), amd64) + CC_TARGET = x86_64-unknown-elf +else + CC_TARGET = +endif + +CC = \ + clang +LD = \ + ld + +SYS_CFLAGS = \ + -nostdlib \ + -nostdinc \ + -ffreestanding \ + -fexceptions \ + -target $(CC_TARGET)\ + -mcmodel=kernel \ + -Wno-attributes \ + -Wno-multichar \ + -fno-stack-protector\ + -D_ST_MULTICORE \ + +ifeq ($(ST_TARGET_ARCH),amd64) + SYS_CFLAGS += \ + -mno-sse \ + -mno-sse2 \ + -mno-sse3 \ + -mno-avx \ + -mno-avx2 \ + -mno-80387 \ + -mno-3dnow \ + -mno-mmx +endif + +PASSDOWN_ARGS = \ + ARCH=$(ST_TARGET_ARCH) \ + SYS_CC=$(CC) \ + SYS_LD=$(LD) \ + SYS_CFLAGS="$(SYS_CFLAGS)"\ + ARCH_TARGET=$(ARCH_TARGET) diff --git a/paw/stos/Makefile b/paw/stos/Makefile new file mode 100644 index 0000000..b47037f --- /dev/null +++ b/paw/stos/Makefile @@ -0,0 +1,17 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: OS core build script +# Author: Chloe M. +# + +.SILENT: +include ../mk/stos.mk + +.PHONY: all +all: machine + +.PHONY: machine +machine: + cd arch/$(ST_TARGET_ARCH)/; $(MAKE) $(PASSDOWN_ARGS) diff --git a/paw/stos/arch/amd64/Makefile b/paw/stos/arch/amd64/Makefile new file mode 100644 index 0000000..182de7c --- /dev/null +++ b/paw/stos/arch/amd64/Makefile @@ -0,0 +1,30 @@ +# +# Copyright (c) 2026, Chloe M. +# Provided under the BSD-3 clause +# +# Description: AMD64 port build script +# Author: Chloe M. +# + +.SILENT: +include ../../../mk/stos.mk + +ASMFILES = $(shell find . -name "*.S") +ASMOFILES = $(ASMFILES:.S=.S.o) + +KERNEL_PATH = \ + $(ST_PROJECT_ROOT)/artifacts/stoskrnl.sys +CFLAGS = \ + $(SYS_CFLAGS) + +.PHONY: all +all: bin + +.PHONY: bin +bin: $(ASMOFILES) + $(PROMPT) "LD" $(KERNEL_PATH) + $(SYS_LD) -Tdevel/link.ld $(ASMOFILES) -o $(KERNEL_PATH) + +%.S.o: %.S + $(PROMPT) "AS" $< + $(SYS_CC) -c $< $(CFLAGS) -o $@ diff --git a/paw/stos/arch/amd64/cpu/locore.S b/paw/stos/arch/amd64/cpu/locore.S new file mode 100644 index 0000000..b4871ad --- /dev/null +++ b/paw/stos/arch/amd64/cpu/locore.S @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Low-level processor init + * Author: Chloe M. + */ + + .text + .globl _start +_start: + cli /* Just in case */ + xor %rbp, %rbp /* Terminate callstack */ + + mfence /* Flush caches */ +1: cli /* Disable interrupts */ + hlt /* Suspend processor */ diff --git a/paw/stos/arch/amd64/devel/link.ld b/paw/stos/arch/amd64/devel/link.ld new file mode 100644 index 0000000..a2732ec --- /dev/null +++ b/paw/stos/arch/amd64/devel/link.ld @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Kernel linker script + * Author: Chloe M. + */ + +OUTPUT_FORMAT(elf64-x86-64) +OUTPUT_ARCH(i386:x86-64) +ENTRY(_start) + +PHDRS { + text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; + rodata PT_LOAD FLAGS((1 << 2)) ; + data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; +} + +SECTIONS +{ + . = 0xFFFFFFFF80000000; + __KernelStart = .; + + .text : { + *(.text .text.*) + } :text + + . += CONSTANT(MAXPAGESIZE); + + .rodata : { + *(.rodata .rodata.*) + } :rodata + + . += CONSTANT(MAXPAGESIZE); + + .driver : { + __driver_start = .; + KEEP(*(.driver .driver)); + __driver_end = .; + } + + . += CONSTANT(MAXPAGESIZE); + + .font : { + KEEP(*(.font .font)); + } + + . += CONSTANT(MAXPAGESIZE); + + .data : { + *(.data) + } :data + + .bss : { + *(COMMON) + *(.bss .bss.*) + } :data + + __KernelEnd = .; + . += CONSTANT(MAXPAGESIZE); + + /DISCARD/ : { + *(.eh_frame .eh_frame.*) + *(.note .note.*) + } +}