Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ jobs:

- name: Build Toolchain
run: |
nix develop .#gcc --command make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE=
nix develop .#gcc --command make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= GCC_CONFIGURE_FLAGS="--with-newlib"

- name: Build Newlib (libc)
run: |
nix develop .#newlib --command make newlib ARCH=i686 CROSS_COMPILE=

- name: Build Kernel
run: |
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ define MAKE_RECURSIVE
endef
endif

define newline


endef

all: kernel

include $(TOOLCHAIN_DIR)/build.mk
Expand Down Expand Up @@ -119,12 +124,14 @@ compile_commands.json:
$(call ASSERT_EXE_EXISTS,bear)
$(SILENT)bear -- $(MAKE) -B all

clean/%:
$(RM) -rf $(shell echo "$@" | sed "s/clean/$(BUILD_DIR)/")

clean:
$(RM) -rf $(BUILD_DIR)
$(foreach to_clean,$(TO_CLEAN),$(RM) -rf $(to_clean) $(newline))

distclean: clean
$(RM) -rf $(TOOLCHAIN_LOCATION)
$(RM) -rf $(BINUTILS_DIR) $(GCC_DIR)
$(foreach to_clean,$(TO_DISTCLEAN),$(RM) -rf $(to_clean) $(newline))

.PHONY: clean distclean

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ $ make iso # builds the kernel.iso file
$ make qemu # boots up qemu using the iso file
```

### Toolchain

If you do not already have an available `i686-elf` toolchain, a custom GCC target for this kernel (i686-dailyrun)
is available for you to build inside the `toolchain` directory. Note that using this toolchain is required when
building userland executables destined to be used with this kernel.

```bash
$ make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE=
$ make libc ARCH=i686 CROSS_COMPILE=
```

## Testing

I don't know how I can test kernel code, so all tests are performed manually for the time being ...
Expand Down
20 changes: 18 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
gnumake
pkg-config
autoconf-archive
autoconf
automake
autoconf269 # newlib requires using v2.69 exactly
automake115x
autogen
# Required libraries
gmp.dev
libmpc
Expand All @@ -90,6 +91,21 @@
export CROSS_COMPILE=
'';
};

newlib = pkgs.mkShell.override { stdenv = pkgs.stdenvNoCC; } {
hardeningDisable = [ "all" ];
buildInputs = with pkgs; [
gnumake
pkg-config
autoconf269 # newlib requires using v2.69 exactly
automake115x
];

shellHook = ''
export ARCH=i686
export CROSS_COMPILE=
'';
};
};
}
);
Expand Down
4 changes: 3 additions & 1 deletion kernel/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ DEPS += $(KERNEL_OBJS:.o=.d)

KERNEL_LDSCRIPT := $(BUILD_DIR)/kernel/linker.ld

KERNEL_LIBS := c algo path uacpi
KERNEL_LIBS := k algo path uacpi

$(KERNEL_BIN): CPPFLAGS += -DKERNEL -DUACPI_FORMATTED_LOGGING
$(KERNEL_BIN): | $(KERNEL_LDSCRIPT)
Expand Down Expand Up @@ -80,4 +80,6 @@ qemu-server: $(KERNEL_ISO)
$(call ASSERT_EXE_EXISTS,$(QEMU))
$(SILENT)$(QEMU) -cdrom $(KERNEL_ISO) $(QEMU_ARGS)

TO_CLEAN += $(BUILD_DIR)/$(KERNEL_DIR) $(KERNEL_BIN) $(KERNEL_ISO) $(BUILD_DIR)/kernel.map $(BUILD_DIR)/kernel.sym

.PHONY: qemu qemu-server
7 changes: 5 additions & 2 deletions lib/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ $(BUILD_DIR)/$(1).a: $$($(1)_OBJS)

DEPS += $$($(1)_OBJS:.o=.d)

TO_CLEAN += $$(BUILD_DIR)/$(1).a

endef

define DEFINE_STATIC_LIBRARY
$(call DEFINE_STATIC_LIBRARY_AT,$(1),$(1),include,src,$(2))
endef

include $(LIB_DIR)/libtest/build.mk
TO_CLEAN += $(BUILD_DIR)/$(LIB_DIR)

include $(LIB_DIR)/libc/build.mk
include $(LIB_DIR)/libtest/build.mk
include $(LIB_DIR)/libk/build.mk
include $(LIB_DIR)/libalgo/build.mk
include $(LIB_DIR)/libpath/build.mk
include $(LIB_DIR)/uacpi/build.mk
Expand Down
5 changes: 0 additions & 5 deletions lib/libc/build.mk

This file was deleted.

18 changes: 0 additions & 18 deletions lib/libc/include/string.h

This file was deleted.

5 changes: 5 additions & 0 deletions lib/libk/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(eval $(call DEFINE_STATIC_LIBRARY,libk, \
string.c \
memcpy.c \
memset.c \
))
File renamed without changes.
File renamed without changes.
16 changes: 10 additions & 6 deletions lib/libc/src/string.c → lib/libk/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ char *strncpy(char *dst, const char *src, size_t n)
return dst;
}

char *strlcpy(char *dst, const char *src, size_t n)
size_t strlcpy(char *dst, const char *src, size_t n)
{
if (n == 0)
return dst;
size_t i;

strncpy(dst, src, n - 1);
dst[n - 1] = '\0';
for (i = 0; i < n - 1; ++i) {
dst[i] = src[i];
if (dst[i] == '\0')
break;
}

return dst;
dst[i] = '0';

return i;
}

int strcmp(const char *s1, const char *s2)
Expand Down
2 changes: 2 additions & 0 deletions toolchain/binutils/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ $(BINUTILS_LD): binutils/configure
$(call MAKE_RECURSIVE,$(BINUTILS_BUILD_DIR),install,binutils/)

.PHONY: binutils binutils/configure binutils/prepare

TO_DISTCLEAN += $(BINUTILS_BUILD_DIR) $(BINUTILS_DIR)
3 changes: 3 additions & 0 deletions toolchain/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export PATH := $(PREFIX)/bin:$(PREFIX)/usr/bin:$(PATH)

include $(TOOLCHAIN_DIR)/binutils/build.mk
include $(TOOLCHAIN_DIR)/gcc/build.mk
include $(TOOLCHAIN_DIR)/newlib/build.mk

TO_DISTCLEAN += $(TOOLCHAIN_LOCATION)
2 changes: 2 additions & 0 deletions toolchain/gcc/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ $(GCC_GCC): gcc/configure
$(call MAKE_RECURSIVE,$(GCC_BUILD_DIR),install-target-libgcc,gcc/)

.PHONY: gcc gcc/configure gcc/prepare

TO_DISTCLEAN += $(GCC_BUILD_DIR) $(GCC_DIR)
1 change: 1 addition & 0 deletions toolchain/newlib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
newlib-*/
45 changes: 45 additions & 0 deletions toolchain/newlib/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
TOOLCHAIN_NEWLIB_DIR := $(TOOLCHAIN_DIR)/newlib

NEWLIB_VERSION := 4.5.0.20241231
NEWLIB_TAR_URL := ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
NEWLIB_DIR := $(TOOLCHAIN_NEWLIB_DIR)/newlib-$(NEWLIB_VERSION)
NEWLIB_TAR := $(NEWLIB_DIR).tar.gz
NEWLIB_BUILD_DIR := $(BUILD_DIR)/newlib-$(NEWLIB_VERSION)

newlib/tar: $(NEWLIB_TAR)
$(NEWLIB_TAR):
$(call COMPILE,WGET,$@)
$(SILENT)$(WGET) $(NEWLIB_TAR_URL) -O $@

newlib/prepare: $(NEWLIB_DIR)
$(NEWLIB_DIR): $(NEWLIB_TAR)
$(call COMPILE,EXTRACT,$@)
$(SILENT)tar xf $(NEWLIB_TAR) -C $(dir $@)
$(call LOG,PATCH,$@)
$(SILENT)cp -rf $(TOOLCHAIN_NEWLIB_DIR)/port/* $@
$(call LOG,RECONF,$@)
$(SILENT)cd $@/newlib && autoreconf -vfi $(SILENT_OUTPUT)
$(SILENT)cp -rf $(TOOLCHAIN_NEWLIB_DIR)/port/* $@

newlib/configure: $(NEWLIB_BUILD_DIR)/config.status
$(NEWLIB_BUILD_DIR)/config.status: $(NEWLIB_DIR)
$(call COMPILE,CONFIGURE,$@)
$(SILENT)\
cd $(dir $@) && \
$(PWD)/$(NEWLIB_DIR)/configure \
--target="$(TARGET)" \
--prefix="$(PREFIX)" \
$(NEWLIB_CONFIGURE_FLAGS) \
> configure.log \
2> configure.err

libc: newlib
newlib: newlib/configure
$(call LOG,MAKE,newlib)
$(call MAKE_RECURSIVE,$(NEWLIB_BUILD_DIR),all CFLAGS='$(ASFLAGS)',newlib/)
$(call MAKE_RECURSIVE,$(NEWLIB_BUILD_DIR),install,newlib/)

.PHONY: libc newlib newlib/configure newlib/prepare newlib/tar

TO_CLEAN += $(NEWLIB_BUILD_DIR)
TO_DISTCLEAN += $(NEWLIB_DIR)
Loading