diff options
30 files changed, 841 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..461a13b --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.a +*.o +*.elf +*.hdd +.ccls* +tools +ovmf* +limine diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a550a15 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "kernel"] + path = kernel + url = ssh://git@git.jonsantmyer.com:49/home/git/jove-kernel diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a342acc --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +TOOLSDIR := $(PWD)/tools +KERNELDIR := $(PWD)/kernel +SYSROOTDIR := $(PWD)/sysroot +INITRDDIR := $(PWD)/initrd +LIBDIR := $(PWD)/lib + +include kernel/config.mk + +CC = $(TOOLSDIR)/bin/$(TARGET_TRIPLET)-gcc +LD = $(TOOLSDIR)/bin/$(TARGET_TRIPLET)-ld +AS = $(TOOLSDIR)/bin/$(TARGET_TRIPLET)-as + +KERNEL_BIN := $(KERNELDIR)/jove.elf +LIBC := $(SYSROOTDIR)/lib/libc.a + +INITRD_TAR := $(SYSROOTDIR)/boot/initrd.tar + +TEST_HDD := $(PWD)/test.hdd +TEST_HDD_SIZEM = 64 +TEST_HDD_DIR := $(PWD)/test_hdd + +all: $(KERNEL_BIN) + +.PHONY: clean +clean: + $(MAKE) -C $(KERNELDIR) clean + +.PHONY: $(KERNEL_BIN) +$(KERNEL_BIN): + $(MAKE) -C $(KERNELDIR) CC=$(CC) LD=$(LD) AS=$(AS) + +.PHONY: test +.ONESHELL: +test: $(TEST_HDD) $(KERNEL_BIN) + sudo rm -rf $(TEST_HDD_DIR) + mkdir -p $(TEST_HDD_DIR) + export LOOPBACK_DEV=$(shell sudo losetup -Pf --show $(TEST_HDD)) + sudo partprobe $$LOOPBACK_DEV + sudo mkfs.fat -F 32 "$$LOOPBACK_DEV"p1 + sudo mount "$$LOOPBACK_DEV"p1 $(TEST_HDD_DIR) + sudo cp -r $(SYSROOTDIR)/* $(TEST_HDD_DIR) + sudo cp $(KERNEL_BIN) $(TEST_HDD_DIR)/boot + sudo cp limine/limine.exe $(TEST_HDD_DIR)/boot + sudo mkdir -p $(TEST_HDD_DIR)/EFI/BOOT + sudo cp limine/BOOTX64.EFI $(TEST_HDD_DIR)/EFI/BOOT + sync + sudo umount $(TEST_HDD_DIR) + sudo losetup -d $$LOOPBACK_DEV + sudo rm -rf $(TEST_HDD_DIR) + qemu-system-x86_64 -m 512M -M q35 -bios ovmf-x64/OVMF.fd -net none -smp 4 -hda test.hdd -serial stdio -no-shutdown -no-reboot -s + +.PHONY: $(TEST_HDD) +$(TEST_HDD): $(INITRD_TAR) + rm -f $(TEST_HDD) + dd if=/dev/zero bs=1M count=0 seek=$(TEST_HDD_SIZEM) of=$(TEST_HDD) + parted -s $(TEST_HDD) mklabel gpt + parted -s $(TEST_HDD) mkpart primary 2048s 100% + +.PHONY: $(INITRD_TAR) +$(INITRD_TAR): $(LIBC) + $(MAKE) -C $(INITRDDIR) OUT=$(INITRD_TAR) ABIDIR=$(KERNELDIR)/abi LIBDIR=$(LIBDIR) + +.PHONY: $(LIBC) +$(LIBC): + $(MAKE) -C $(LIBDIR)/crt LIBDIR=$(SYSROOTDIR)/lib TARGET_MACHINE=$(TARGET_MACHINE) + $(MAKE) -C $(LIBDIR)/jlibc OUT=$@ diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..5e3aaad --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,3 @@ +-Ikernel/abi +-ffreestanding +-nostdlib diff --git a/initrd/Makefile b/initrd/Makefile new file mode 100644 index 0000000..66f3753 --- /dev/null +++ b/initrd/Makefile @@ -0,0 +1,15 @@ +ARCHIVEDIR := archive +PROGRAMSDIR := programs +FILESDIR := files + +PROGRAMDIRS := $(wildcard $(PROGRAMSDIR)/*) +PROGRAMBINS := $(patsubst $(PROGRAMSDIR)/%,$(ARCHIVEDIR)/%,$(PROGRAMDIRS)) + +OUT = initrd.tar + +all: ${PROGRAMBINS} + tar -cf $(OUT) -C $(ARCHIVEDIR) . + +.PHONY: $(ARCHIVEDIR)/% +$(ARCHIVEDIR)/% : $(PROGRAMSDIR)/% + $(MAKE) -C $< OUT=../../$@ ABIDIR=$(ABIDIR) diff --git a/initrd/archive/init b/initrd/archive/init Binary files differnew file mode 100755 index 0000000..44e70d6 --- /dev/null +++ b/initrd/archive/init diff --git a/initrd/programs/init/Makefile b/initrd/programs/init/Makefile new file mode 100644 index 0000000..3a283de --- /dev/null +++ b/initrd/programs/init/Makefile @@ -0,0 +1,8 @@ +CFILES := $(wildcard *.c) +OFILES := $(patsubst %.c,%.o,$(CFILES)) + +all: ${OFILES} + $(CC) $< -o $(OUT) -lc + +%.o : %.c + $(CC) -I$(ABIDIR) -g $(CFLAGS) -c $< -o $@ diff --git a/initrd/programs/init/main.c b/initrd/programs/init/main.c new file mode 100644 index 0000000..870ad28 --- /dev/null +++ b/initrd/programs/init/main.c @@ -0,0 +1,9 @@ +#include "syscall.h" + +int +main(int argc, char *argv[]) +{ + _syscall_log("Hello, Userland!\n"); + for(;;); + return 0; +} diff --git a/kernel b/kernel new file mode 160000 +Subproject d1ff7bcc91886626dc9060ec5fb67ee102ab7c1 diff --git a/lib/crt/Makefile b/lib/crt/Makefile new file mode 100644 index 0000000..8b809fa --- /dev/null +++ b/lib/crt/Makefile @@ -0,0 +1,8 @@ +SFILES := $(wildcard $(TARGET_MACHINE)/*.s) +OFILES := $(patsubst %.s,%.o,$(SFILES)) + +all: ${OFILES} + cp ${OFILES} $(LIBDIR)/ + +%.o:%.s + $(AS) $< -o $@ diff --git a/lib/crt/x86_64/crt0.s b/lib/crt/x86_64/crt0.s new file mode 100644 index 0000000..c5a0ba9 --- /dev/null +++ b/lib/crt/x86_64/crt0.s @@ -0,0 +1,22 @@ +.section .text +.global _start +_start: + #Setup start of stack frame + xorq %rbp, %rbp + pushq %rbp + pushq %rbp + movq %rsp, %rbp + + #Save arguments passed to main + pushq %rdi + pushq %rsi + + #Setup libc and call global constructors + + #Call main + call main + + #Exit + movq %rax, %rdi + call exit +.size _start, . - _start diff --git a/lib/crt/x86_64/crti.s b/lib/crt/x86_64/crti.s new file mode 100644 index 0000000..0f06273 --- /dev/null +++ b/lib/crt/x86_64/crti.s @@ -0,0 +1,11 @@ +.section .init +.global _init +_init: + pushq %rbp + movq %rsp, %rbp + +.section .fini +.global _fini +_fini: + pushq %rbp + movq %rsp, %rbp diff --git a/lib/crt/x86_64/crtn.s b/lib/crt/x86_64/crtn.s new file mode 100644 index 0000000..9e31c23 --- /dev/null +++ b/lib/crt/x86_64/crtn.s @@ -0,0 +1,7 @@ +.section .init + popq %rbp + ret + +.section .fini + popq %rbp + ret diff --git a/lib/jlibc/Makefile b/lib/jlibc/Makefile new file mode 100644 index 0000000..65e645c --- /dev/null +++ b/lib/jlibc/Makefile @@ -0,0 +1,12 @@ +CFILES := $(wildcard *.c) +CFILES += $(wildcard */*.c) + +OFILES := $(patsubst %.c,%.o,$(CFILES)) + +all: $(OUT) + +$(OUT): ${OFILES} + ar rcs $@ ${OFILES} + +%.o:%.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/lib/jlibc/stdlib/exit.c b/lib/jlibc/stdlib/exit.c new file mode 100644 index 0000000..225f74e --- /dev/null +++ b/lib/jlibc/stdlib/exit.c @@ -0,0 +1,5 @@ +__attribute__((noreturn)) +void exit(int status) +{ + +} diff --git a/limine.mk b/limine.mk new file mode 100644 index 0000000..796c8bd --- /dev/null +++ b/limine.mk @@ -0,0 +1,9 @@ +LIMINE_VERSION := 6.x +LIMINE_GIT := https://github.com/limine-bootloader/limine.git +LIMINE_DIR := $(PWD)/limine + +all: $(LIMINE_DIR) + +$(LIMINE_DIR): + git clone $(LIMINE_GIT) --branch=v$(LIMINE_VERSION)-branch-binary --depth=1 + diff --git a/scripts/binutils-2.41.diff b/scripts/binutils-2.41.diff new file mode 100644 index 0000000..363e9ca --- /dev/null +++ b/scripts/binutils-2.41.diff @@ -0,0 +1,78 @@ +diff -rNau binutils-2.41/bfd/config.bfd binutils-2.41-patched/bfd/config.bfd +--- binutils-2.41/bfd/config.bfd 2023-07-02 19:00:00.000000000 -0400 ++++ binutils-2.41-patched/bfd/config.bfd 2024-03-10 23:19:47.522036207 -0400 +@@ -714,6 +714,13 @@ + targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec" + want64=true + ;; ++#ifdef BFD64 ++ x86_64-*-jove*) ++ targ_defvec=x86_64_elf64_vec ++ targ_selvecs=i386_elf32_vec ++ want64=true ++ ;; ++#endif + x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin) + targ_defvec=x86_64_pe_vec + targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_big_vec x86_64_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec" +diff -rNau binutils-2.41/config.sub binutils-2.41-patched/config.sub +--- binutils-2.41/config.sub 2023-07-02 19:00:00.000000000 -0400 ++++ binutils-2.41-patched/config.sub 2024-03-10 23:33:30.546506756 -0400 +@@ -1758,7 +1758,7 @@ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ +- | fiwix* | mlibc* ) ++ | fiwix* | mlibc* | jove* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) +diff -rNau binutils-2.41/gas/configure.tgt binutils-2.41-patched/gas/configure.tgt +--- binutils-2.41/gas/configure.tgt 2023-07-02 19:00:00.000000000 -0400 ++++ binutils-2.41-patched/gas/configure.tgt 2024-03-10 23:22:33.351797968 -0400 +@@ -231,6 +231,7 @@ + i386-*-haiku*) fmt=elf em=haiku ;; + i386-*-genode*) fmt=elf ;; + i386-*-bsd*) fmt=aout em=386bsd ;; ++ i386-*-jove*) fmt=elf ;; + i386-*-netbsd*-gnu* | \ + i386-*-knetbsd*-gnu | \ + i386-*-netbsd* | \ +diff -rNau binutils-2.41/ld/configure.tgt binutils-2.41-patched/ld/configure.tgt +--- binutils-2.41/ld/configure.tgt 2023-07-02 19:00:00.000000000 -0400 ++++ binutils-2.41-patched/ld/configure.tgt 2024-03-10 23:24:16.838998259 -0400 +@@ -1053,6 +1053,9 @@ + targ_extra_ofiles="deffilep.o pdb.o pep-dll.o pe-dll.o" + test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api' + ;; ++x86_64-*-jove*) targ_emul=elf_x86_64_jove ++ targ_extra_emuls="elf_x86_64" ++ ;; + x86_64-*-mingw*) targ_emul=i386pep ; + targ_extra_emuls=i386pe + targ_extra_ofiles="deffilep.o pdb.o pep-dll.o pe-dll.o" +diff -rNau binutils-2.41/ld/emulparams/elf_x86_64_jove.sh binutils-2.41-patched/ld/emulparams/elf_x86_64_jove.sh +--- binutils-2.41/ld/emulparams/elf_x86_64_jove.sh 1969-12-31 19:00:00.000000000 -0500 ++++ binutils-2.41-patched/ld/emulparams/elf_x86_64_jove.sh 2024-03-10 23:25:24.152469179 -0400 +@@ -0,0 +1 @@ ++source_sh ${srcdir}/emulparams/elf_x86_64.sh +diff -rNau binutils-2.41/ld/Makefile.am binutils-2.41-patched/ld/Makefile.am +--- binutils-2.41/ld/Makefile.am 2023-07-02 19:00:00.000000000 -0400 ++++ binutils-2.41-patched/ld/Makefile.am 2024-03-10 23:26:41.812851367 -0400 +@@ -951,6 +951,7 @@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Pc@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Pc@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Pc@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_jove.Pc@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@ +@@ -455,6 +455,7 @@ + eelf64tilegx_be.c \ + eelf_mipsel_haiku.c \ + eelf_x86_64.c \ ++ eelf_x86_64_jove.c \ + eelf_x86_64_cloudabi.c \ + eelf_x86_64_fbsd.c \ + eelf_x86_64_haiku.c \ + diff --git a/scripts/buildtools.mk b/scripts/buildtools.mk new file mode 100644 index 0000000..6160d01 --- /dev/null +++ b/scripts/buildtools.mk @@ -0,0 +1,63 @@ +BINUTILS_VERSION := 2.41 +GCC_VERSION := 13.2.0 +TOOLCHAIN := x86_64-jove + +TOOLDIR := $(PWD)/tools +SCRIPTDIR := $(PWD)/scripts +TOOL_SRCDIR := $(TOOLDIR)/src +TOOL_BUILDDIR := $(TOOLDIR)/build +SYSROOT_DIR := $(PWD)/sysroot + +BINUTILS_ARCHIVE := binutils-$(BINUTILS_VERSION).tar.gz +BINUTILS_URL := https://ftp.gnu.org/gnu/binutils/$(BINUTILS_ARCHIVE) +BINUTILS_PATCHFILE := $(SCRIPTDIR)/binutils-$(BINUTILS_VERSION).diff +BINUTILS_SRCDIR := $(TOOL_SRCDIR)/binutils-$(BINUTILS_VERSION) +BINUTILS_BUILDDIR := $(TOOL_BUILDDIR)/binutils + +GCC_ARCHIVE := gcc-$(GCC_VERSION).tar.gz +GCC_URL := https://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION)/$(GCC_ARCHIVE) +GCC_PATCHFILE := $(SCRIPTDIR)/gcc-$(GCC_VERSION).diff +GCC_SRCDIR := $(TOOL_SRCDIR)/gcc-$(GCC_VERSION) +GCC_BUILDDIR := $(TOOL_BUILDDIR)/gcc + +all: $(TOOLDIR) $(BINUTILS_BUILDDIR) $(GCC_BUILDDIR) + +.ONESHELL: +$(BINUTILS_BUILDDIR): $(BINUTILS_SRCDIR) + mkdir -p $(BINUTILS_BUILDDIR) + cd $(BINUTILS_BUILDDIR) + $(BINUTILS_SRCDIR)/configure --target=$(TOOLCHAIN) --prefix="$(TOOLDIR)" --with-sysroot=$(SYSROOT_DIR) --disable-nls --disable-werror + make -j4 + make install + +.PHONY: $(GCC_BUILDDIR) +.ONESHELL: +$(GCC_BUILDDIR): $(GCC_SRCDIR) + mkdir -p $(GCC_BUILDDIR) + cd $(GCC_BUILDDIR) + $(GCC_SRCDIR)/configure --target=$(TOOLCHAIN) --prefix="$(TOOLDIR)" --disable-nls --enable-languages=c --with-sysroot=$(SYSROOT_DIR) + make all-gcc -j4 + make all-target-libgcc -j4 + make install-gcc + make install-target-libgcc + +$(BINUTILS_SRCDIR): $(TOOLDIR)/$(BINUTILS_ARCHIVE) + tar -xzvf $(TOOLDIR)/$(BINUTILS_ARCHIVE) -C $(TOOL_SRCDIR) + patch --directory=$(BINUTILS_SRCDIR) --strip=1 < $(BINUTILS_PATCHFILE) + cd $(BINUTILS_SRCDIR)/ld && automake + +$(GCC_SRCDIR): $(TOOLDIR)/$(GCC_ARCHIVE) + tar -xzvf $(TOOLDIR)/$(GCC_ARCHIVE) -C $(TOOL_SRCDIR) + patch --directory=$(GCC_SRCDIR) --strip=1 < $(GCC_PATCHFILE) + cd $(GCC_SRCDIR) && ./contrib/download_prerequisites + +$(TOOLDIR)/$(BINUTILS_ARCHIVE): + wget $(BINUTILS_URL) -O $(TOOLDIR)/$(BINUTILS_ARCHIVE) + +$(TOOLDIR)/$(GCC_ARCHIVE): + wget $(GCC_URL) -O $(TOOLDIR)/$(GCC_ARCHIVE) + +$(TOOLDIR): + mkdir -p $(TOOLDIR) + mkdir -p $(TOOL_SRCDIR) + mkdir -p $(TOOL_BUILDDIR) diff --git a/scripts/gcc-13.2.0.diff b/scripts/gcc-13.2.0.diff new file mode 100644 index 0000000..45dbe98 --- /dev/null +++ b/scripts/gcc-13.2.0.diff @@ -0,0 +1,78 @@ +diff -rNau gcc-13.2.0/config.sub gcc-13.2.0-patched/config.sub +--- gcc-13.2.0/config.sub 2023-07-27 04:13:03.000000000 -0400 ++++ gcc-13.2.0-patched/config.sub 2024-03-10 23:33:56.596289806 -0400 +@@ -1749,7 +1749,7 @@ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ +- | fiwix* ) ++ | fiwix* | jove* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) +diff -rNau gcc-13.2.0/fixincludes/mkfixinc.sh gcc-13.2.0-patched/fixincludes/mkfixinc.sh +--- gcc-13.2.0/fixincludes/mkfixinc.sh 2023-07-27 04:13:03.000000000 -0400 ++++ gcc-13.2.0-patched/fixincludes/mkfixinc.sh 2024-03-10 23:49:24.405547826 -0400 +@@ -20,6 +20,7 @@ + powerpcle-*-eabisim* | \ + powerpcle-*-eabi* | \ + *-*-vxworks7* | \ ++ *-*-jove* | \ + *-musl* ) + # IF there is no include fixing, + # THEN create a no-op fixer and exit +diff -rNau gcc-13.2.0/gcc/config/jove.h gcc-13.2.0-patched/gcc/config/jove.h +--- gcc-13.2.0/gcc/config/jove.h 1969-12-31 19:00:00.000000000 -0500 ++++ gcc-13.2.0-patched/gcc/config/jove.h 2024-03-10 23:44:13.570083205 -0400 +@@ -0,0 +1,8 @@ ++#undef TARGET_JOVE ++#define TARGET_JOVE 1 ++ ++#undef LIB_SPEC ++#define LIB_SPEC "-lc" ++ ++#undef STARTFILE_SPEC ++#define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s" ++ ++#undef ENDFILE_SPEC ++#define ENDFILE_SPEC "crtend.o%s crtn.o%s" +diff -rNau gcc-13.2.0/gcc/config.gcc gcc-13.2.0-patched/gcc/config.gcc +--- gcc-13.2.0/gcc/config.gcc 2023-07-27 04:13:04.000000000 -0400 ++++ gcc-13.2.0-patched/gcc/config.gcc 2024-03-10 23:42:11.659119360 -0400 +@@ -843,6 +843,12 @@ + *-*-fuchsia*) + native_system_header_dir=/include + ;; ++*-*-jove*) ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ use_gcc_stdint=provide ++ ;; + *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-uclinuxfdpiceabi) + extra_options="$extra_options gnu-user.opt" + gas=yes +@@ -1891,6 +1897,9 @@ + x86_64-*-freebsd*) + tm_file="${tm_file} i386/unix.h i386/att.h elfos.h ${fbsd_tm_file} i386/x86-64.h i386/freebsd.h i386/freebsd64.h" + ;; ++x86_64-*-jove*) ++ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h jove.h" ++ ;; + i[34567]86-*-netbsdelf*) + tm_file="${tm_file} i386/unix.h i386/att.h elfos.h ${nbsd_tm_file} i386/netbsd-elf.h" + extra_options="${extra_options} netbsd.opt netbsd-elf.opt" +diff -rNau gcc-13.2.0/libgcc/config.host gcc-13.2.0-patched/libgcc/config.host +--- gcc-13.2.0/libgcc/config.host 2023-07-27 04:13:07.000000000 -0400 ++++ gcc-13.2.0-patched/libgcc/config.host 2024-03-10 23:47:32.669386544 -0400 +@@ -386,6 +386,10 @@ + esac + + case ${host} in ++x86_64-*-jove*) ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o" ++ ;; + aarch64*-*-elf | aarch64*-*-rtems*) + extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o" + extra_parts="$extra_parts crtfastmath.o" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7905cf3 --- /dev/null +++ b/shell.nix @@ -0,0 +1,29 @@ +{ pkgs ? import <nixpkgs> {} }: +pkgs.mkShell { + name = "jove-build-env"; + hardeningDisable = [ "format" ]; + buildInputs = with pkgs; [ + # Library depends + gmp gmp.dev + isl + libffi libffi.dev + libmpc + libxcrypt + mpfr mpfr.dev + xz xz.dev + zlib zlib.dev + + m4 + bison + flex + texinfo + + gcc + stdenv.cc + stdenv.cc.libc stdenv.cc.libc_dev + + # Test suite + qemu_kvm + parted + ]; +} diff --git a/sysroot/boot/initrd.tar b/sysroot/boot/initrd.tar Binary files differnew file mode 100644 index 0000000..3165525 --- /dev/null +++ b/sysroot/boot/initrd.tar diff --git a/sysroot/boot/limine.cfg b/sysroot/boot/limine.cfg new file mode 100644 index 0000000..86ee54c --- /dev/null +++ b/sysroot/boot/limine.cfg @@ -0,0 +1,13 @@ +${JOVE_KERNEL}=boot:///boot/jove.elf +${INITRD}=boot:///boot/initrd.tar + +DEFAULT_ENTRY=1 +TIMEOUT=3 +VERBOSE=yes + +:Jove + PROTOCOL=limine + KERNEL_PATH=${JOVE_KERNEL} + KERNEL_CMDLINE=initrd=/boot/initrd.tar init=./init + + MODULE_PATH=${INITRD} diff --git a/sysroot/usr/include/errno.h b/sysroot/usr/include/errno.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sysroot/usr/include/errno.h diff --git a/sysroot/usr/include/stdint.h b/sysroot/usr/include/stdint.h new file mode 100644 index 0000000..165a201 --- /dev/null +++ b/sysroot/usr/include/stdint.h @@ -0,0 +1,319 @@ +/* Copyright (C) 1997-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +/* + * ISO C99: 7.18 Integer types <stdint.h> + */ + +#ifndef _STDINT_H +#define _STDINT_H 1 + +#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#include <bits/libc-header-start.h> +#include <bits/types.h> +#include <bits/wchar.h> +#include <bits/wordsize.h> + +/* Exact integral types. */ + +/* Signed. */ +#include <bits/stdint-intn.h> + +/* Unsigned. */ +#include <bits/stdint-uintn.h> + + +/* Small types. */ + +/* Signed. */ +typedef __int_least8_t int_least8_t; +typedef __int_least16_t int_least16_t; +typedef __int_least32_t int_least32_t; +typedef __int_least64_t int_least64_t; + +/* Unsigned. */ +typedef __uint_least8_t uint_least8_t; +typedef __uint_least16_t uint_least16_t; +typedef __uint_least32_t uint_least32_t; +typedef __uint_least64_t uint_least64_t; + + +/* Fast types. */ + +/* Signed. */ +typedef signed char int_fast8_t; +#if __WORDSIZE == 64 +typedef long int int_fast16_t; +typedef long int int_fast32_t; +typedef long int int_fast64_t; +#else +typedef int int_fast16_t; +typedef int int_fast32_t; +__extension__ +typedef long long int int_fast64_t; +#endif + +/* Unsigned. */ +typedef unsigned char uint_fast8_t; +#if __WORDSIZE == 64 +typedef unsigned long int uint_fast16_t; +typedef unsigned long int uint_fast32_t; +typedef unsigned long int uint_fast64_t; +#else +typedef unsigned int uint_fast16_t; +typedef unsigned int uint_fast32_t; +__extension__ +typedef unsigned long long int uint_fast64_t; +#endif + + +/* Types for `void *' pointers. */ +#if __WORDSIZE == 64 +# ifndef __intptr_t_defined +typedef long int intptr_t; +# define __intptr_t_defined +# endif +typedef unsigned long int uintptr_t; +#else +# ifndef __intptr_t_defined +typedef int intptr_t; +# define __intptr_t_defined +# endif +typedef unsigned int uintptr_t; +#endif + + +/* Largest integral types. */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + + +# if __WORDSIZE == 64 +# define __INT64_C(c) c ## L +# define __UINT64_C(c) c ## UL +# else +# define __INT64_C(c) c ## LL +# define __UINT64_C(c) c ## ULL +# endif + +/* Limits of integral types. */ + +/* Minimum of signed integral types. */ +# define INT8_MIN (-128) +# define INT16_MIN (-32767-1) +# define INT32_MIN (-2147483647-1) +# define INT64_MIN (-__INT64_C(9223372036854775807)-1) +/* Maximum of signed integral types. */ +# define INT8_MAX (127) +# define INT16_MAX (32767) +# define INT32_MAX (2147483647) +# define INT64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of unsigned integral types. */ +# define UINT8_MAX (255) +# define UINT16_MAX (65535) +# define UINT32_MAX (4294967295U) +# define UINT64_MAX (__UINT64_C(18446744073709551615)) + + +/* Minimum of signed integral types having a minimum size. */ +# define INT_LEAST8_MIN (-128) +# define INT_LEAST16_MIN (-32767-1) +# define INT_LEAST32_MIN (-2147483647-1) +# define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1) +/* Maximum of signed integral types having a minimum size. */ +# define INT_LEAST8_MAX (127) +# define INT_LEAST16_MAX (32767) +# define INT_LEAST32_MAX (2147483647) +# define INT_LEAST64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of unsigned integral types having a minimum size. */ +# define UINT_LEAST8_MAX (255) +# define UINT_LEAST16_MAX (65535) +# define UINT_LEAST32_MAX (4294967295U) +# define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615)) + + +/* Minimum of fast signed integral types having a minimum size. */ +# define INT_FAST8_MIN (-128) +# if __WORDSIZE == 64 +# define INT_FAST16_MIN (-9223372036854775807L-1) +# define INT_FAST32_MIN (-9223372036854775807L-1) +# else +# define INT_FAST16_MIN (-2147483647-1) +# define INT_FAST32_MIN (-2147483647-1) +# endif +# define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1) +/* Maximum of fast signed integral types having a minimum size. */ +# define INT_FAST8_MAX (127) +# if __WORDSIZE == 64 +# define INT_FAST16_MAX (9223372036854775807L) +# define INT_FAST32_MAX (9223372036854775807L) +# else +# define INT_FAST16_MAX (2147483647) +# define INT_FAST32_MAX (2147483647) +# endif +# define INT_FAST64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of fast unsigned integral types having a minimum size. */ +# define UINT_FAST8_MAX (255) +# if __WORDSIZE == 64 +# define UINT_FAST16_MAX (18446744073709551615UL) +# define UINT_FAST32_MAX (18446744073709551615UL) +# else +# define UINT_FAST16_MAX (4294967295U) +# define UINT_FAST32_MAX (4294967295U) +# endif +# define UINT_FAST64_MAX (__UINT64_C(18446744073709551615)) + + +/* Values to test for integral types holding `void *' pointer. */ +# if __WORDSIZE == 64 +# define INTPTR_MIN (-9223372036854775807L-1) +# define INTPTR_MAX (9223372036854775807L) +# define UINTPTR_MAX (18446744073709551615UL) +# else +# define INTPTR_MIN (-2147483647-1) +# define INTPTR_MAX (2147483647) +# define UINTPTR_MAX (4294967295U) +# endif + + +/* Minimum for largest signed integral type. */ +# define INTMAX_MIN (-__INT64_C(9223372036854775807)-1) +/* Maximum for largest signed integral type. */ +# define INTMAX_MAX (__INT64_C(9223372036854775807)) + +/* Maximum for largest unsigned integral type. */ +# define UINTMAX_MAX (__UINT64_C(18446744073709551615)) + + +/* Limits of other integer types. */ + +/* Limits of `ptrdiff_t' type. */ +# if __WORDSIZE == 64 +# define PTRDIFF_MIN (-9223372036854775807L-1) +# define PTRDIFF_MAX (9223372036854775807L) +# else +# if __WORDSIZE32_PTRDIFF_LONG +# define PTRDIFF_MIN (-2147483647L-1) +# define PTRDIFF_MAX (2147483647L) +# else +# define PTRDIFF_MIN (-2147483647-1) +# define PTRDIFF_MAX (2147483647) +# endif +# endif + +/* Limits of `sig_atomic_t'. */ +# define SIG_ATOMIC_MIN (-2147483647-1) +# define SIG_ATOMIC_MAX (2147483647) + +/* Limit of `size_t' type. */ +# if __WORDSIZE == 64 +# define SIZE_MAX (18446744073709551615UL) +# else +# if __WORDSIZE32_SIZE_ULONG +# define SIZE_MAX (4294967295UL) +# else +# define SIZE_MAX (4294967295U) +# endif +# endif + +/* Limits of `wchar_t'. */ +# ifndef WCHAR_MIN +/* These constants might also be defined in <wchar.h>. */ +# define WCHAR_MIN __WCHAR_MIN +# define WCHAR_MAX __WCHAR_MAX +# endif + +/* Limits of `wint_t'. */ +# define WINT_MIN (0u) +# define WINT_MAX (4294967295u) + +/* Signed. */ +# define INT8_C(c) c +# define INT16_C(c) c +# define INT32_C(c) c +# if __WORDSIZE == 64 +# define INT64_C(c) c ## L +# else +# define INT64_C(c) c ## LL +# endif + +/* Unsigned. */ +# define UINT8_C(c) c +# define UINT16_C(c) c +# define UINT32_C(c) c ## U +# if __WORDSIZE == 64 +# define UINT64_C(c) c ## UL +# else +# define UINT64_C(c) c ## ULL +# endif + +/* Maximal type. */ +# if __WORDSIZE == 64 +# define INTMAX_C(c) c ## L +# define UINTMAX_C(c) c ## UL +# else +# define INTMAX_C(c) c ## LL +# define UINTMAX_C(c) c ## ULL +# endif + +#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) + +# define INT8_WIDTH 8 +# define UINT8_WIDTH 8 +# define INT16_WIDTH 16 +# define UINT16_WIDTH 16 +# define INT32_WIDTH 32 +# define UINT32_WIDTH 32 +# define INT64_WIDTH 64 +# define UINT64_WIDTH 64 + +# define INT_LEAST8_WIDTH 8 +# define UINT_LEAST8_WIDTH 8 +# define INT_LEAST16_WIDTH 16 +# define UINT_LEAST16_WIDTH 16 +# define INT_LEAST32_WIDTH 32 +# define UINT_LEAST32_WIDTH 32 +# define INT_LEAST64_WIDTH 64 +# define UINT_LEAST64_WIDTH 64 + +# define INT_FAST8_WIDTH 8 +# define UINT_FAST8_WIDTH 8 +# define INT_FAST16_WIDTH __WORDSIZE +# define UINT_FAST16_WIDTH __WORDSIZE +# define INT_FAST32_WIDTH __WORDSIZE +# define UINT_FAST32_WIDTH __WORDSIZE +# define INT_FAST64_WIDTH 64 +# define UINT_FAST64_WIDTH 64 + +# define INTPTR_WIDTH __WORDSIZE +# define UINTPTR_WIDTH __WORDSIZE + +# define INTMAX_WIDTH 64 +# define UINTMAX_WIDTH 64 + +# define PTRDIFF_WIDTH __WORDSIZE +# define SIG_ATOMIC_WIDTH 32 +# define SIZE_WIDTH __WORDSIZE +# define WCHAR_WIDTH 32 +# define WINT_WIDTH 32 + +#endif + +#endif /* stdint.h */ diff --git a/sysroot/usr/include/stdio.h b/sysroot/usr/include/stdio.h new file mode 100644 index 0000000..f1f8470 --- /dev/null +++ b/sysroot/usr/include/stdio.h @@ -0,0 +1,26 @@ +#ifndef _STDIO_H +#define _STDIO_H 1 + +#include <stdarg.h> +#include <stddef.h> + +#define SEEK_SET 0 +typedef struct { int unused; } FILE; + +extern FILE *stderr; +#define stderr stderr + +int fclose(FILE *file); +int fflush(FILE *file); +FILE *fopen(const char *path, const char *flags); + +size_t fread(void *buf, size_t size, size_t nmemb, FILE* file); +int fseek(FILE *file, long offset, int whence); +long ftell(FILE *file); +size_t fwrite(const void *buf, size_t size, size_t nmemb, FILE *file); +void setbuf(FILE *file, char *buf); + +int fprintf(FILE *file, const char *fmt, ...); +int vfprintf(FILE *file, const char *fmt, va_list ap); + +#endif diff --git a/sysroot/usr/include/stdlib.h b/sysroot/usr/include/stdlib.h new file mode 100644 index 0000000..f29cce7 --- /dev/null +++ b/sysroot/usr/include/stdlib.h @@ -0,0 +1,17 @@ +#ifndef _STDLIB_H +#define _STDLIB_H 1 + +#include <stddef.h> + +__attribute__((noreturn)) void abort(void); +int atexit(void (*callback)(void)); + +int atoi(const char*); + +void free(void *ptr); +void *malloc(size_t size); +void *calloc(size_t nmemb, size_t size); + +char *getenv(const char *key); + +#endif diff --git a/sysroot/usr/include/string.h b/sysroot/usr/include/string.h new file mode 100644 index 0000000..d55bc37 --- /dev/null +++ b/sysroot/usr/include/string.h @@ -0,0 +1,11 @@ +#ifndef _STRING_H +#define _STRING_H 1 + +#include <stddef.h> + +void *memcpy(void *dest, const void *src, size_t size); +void *memset(void *dest, int byte, size_t size); +char *strcpy(char *dest, const char *src); +size_t strlen(const char *str); + +#endif diff --git a/sysroot/usr/include/sys/types.h b/sysroot/usr/include/sys/types.h new file mode 100644 index 0000000..058c38a --- /dev/null +++ b/sysroot/usr/include/sys/types.h @@ -0,0 +1,6 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H 1 + +typedef int pid_t; + +#endif diff --git a/sysroot/usr/include/time.h b/sysroot/usr/include/time.h new file mode 100644 index 0000000..c73ee97 --- /dev/null +++ b/sysroot/usr/include/time.h @@ -0,0 +1,4 @@ +#ifndef _TIME_H +#define _TIME_H 1 + +#endif diff --git a/sysroot/usr/include/unistd.h b/sysroot/usr/include/unistd.h new file mode 100644 index 0000000..4e14be9 --- /dev/null +++ b/sysroot/usr/include/unistd.h @@ -0,0 +1,11 @@ +#ifndef _UNISTD_H +#define _UNISTD_H 1 + +#include <sys/types.h> + +int execv(const char *pathname, char *const argv[]); +int execve(const char *pathname, char *const argv[], char *const envp[]); +int execvp(const char *pathname, char *const argv[]); +pid_t fork(void); + +#endif |