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
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ jobs:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

# Performing the wget on the GCC and sources takes almost 45min !
# So we try caching it.
#
# NOTE: If ever changing the GCC version, do not forget to also
# update the cached version's release parameter (same for binutils).

- name: Cache GCC sources
id: cache-gcc
uses: actions/cache@v4
env:
cache-name: gcc-sources
release: 12.3.0
with:
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }}
path: toolchain/gcc/gcc-${{ env.release }}.tar.gz

- name: Cache binutils/gdb sources
id: cache-binutils
uses: actions/cache@v4
env:
cache-name: binutils-sources
release: 2.44
with:
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }}
path: toolchain/binutils/binutils-${{ env.release }}.tar.gz

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

- name: Build Kernel
run: |
nix develop --command make kernel
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
build
compile_commands.json

*.tar
*.tar.*

docs/doxygen/doc

initramfs.*
Expand Down
43 changes: 36 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ else
$(info Compiling using host toolchain)
endif

NCORES ?= $(shell nproc)
$(info Compiling sub-targets using $(NCORES) cores)

WGET := wget --no-verbose --show-progress
MAKE := $(MAKE) -j$(NCORES) --no-print-directory

ifneq ($(VERBOSE),y)
SILENT := @
SILENT_OUTPUT := 1> /dev/null 2> /dev/null
endif

BUILD_DIR := build
INC_DIR := include
LIB_DIR := lib
KERNEL_DIR := kernel
SCRIPTS_DIR := scripts
DOCS_DIR := docs
BUILD_DIR := build
INC_DIR := include
LIB_DIR := lib
KERNEL_DIR := kernel
SCRIPTS_DIR := scripts
DOCS_DIR := docs
TOOLCHAIN_DIR := toolchain

DEBUG ?= y

Expand Down Expand Up @@ -68,8 +75,25 @@ define ASSERT_EXE_EXISTS
)
endef

define REDIRECT_OUTPUT
1> $(1).log 2> $(1).err
endef

ifeq ($(VERBOSE),y)
define MAKE_RECURSIVE
$(call LOG,MAKE,$(3)$(2))
$(SILENT)$(MAKE) -C $(1) $(2)
endef
else
define MAKE_RECURSIVE
$(call LOG,MAKE,$(3)$(2))
$(SILENT)$(MAKE) -C $(1) $(2) $(call REDIRECT_OUTPUT,$(1)/make)
endef
endif

all: kernel

include $(TOOLCHAIN_DIR)/build.mk
include $(LIB_DIR)/build.mk
include $(KERNEL_DIR)/build.mk
include $(DOCS_DIR)/build.mk
Expand All @@ -95,8 +119,13 @@ compile_commands.json:
$(call ASSERT_EXE_EXISTS,bear)
$(SILENT)bear -- $(MAKE) -B all

.PHONY: clean
clean:
$(RM) -rf $(BUILD_DIR)

distclean: clean
$(RM) -rf $(TOOLCHAIN_LOCATION)
$(RM) -rf $(BINUTILS_DIR) $(GCC_DIR)

.PHONY: clean distclean

-include $(DEPS)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ $ nix develop .#kernel
## Building

```bash
$ export CROSS_COMPILE=i686-elf- # The target architecturea toolchain's prefix
$ # Use our custom toolchain for building
$ export CROSS_COMPILE=toolchain/opt/i686-dailyrun/bin/i686-dailyrun-
$ export ARCH=i686 # The architecture's name
$ make iso # builds the kernel.iso file
$ make qemu # boots up qemu using the iso file
Expand Down
55 changes: 30 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "A very basic flake";
description = "Kernel";

inputs = {

Expand All @@ -22,60 +22,40 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pkgs-i686 = pkgs.pkgsCross.i686-embedded;
in
rec {
packages = rec {
kernel = pkgs-i686.stdenv.mkDerivation {
name = "kernel";
src = self;
version = "0.1.0";
inherit (devShells.kernel) nativeBuildInputs;

# FIXME: cannot execute ISO from target script inside nix derivation
installPhase = ''
mkdir -p $out
cp -v kernel/kernel.bin $out
'';
};

default = kernel;
};

{
devShells =
let
native_build_required = with pkgs; [ gnumake ];
in
rec {
default = kernel;
kernel = pkgs.mkShell.override { inherit (pkgs-i686) stdenv; } {
kernel = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
# building
grub2
libisoburn
binutils
nasm
mtools
# QOL
bear
shellcheck
clang-tools
qemu
doxygen
graphviz
] ++ native_build_required;

buildInputs = [ pkgs.pkgsi686Linux.glibc ];
hardeningDisable = [ "fortify" ];

shellHook = ''
export ARCH=i686
export CROSS_COMPILE=i686-elf-
export CROSS_COMPILE=toolchain/opt/bin/i686-dailyrun-
'';
};

test = pkgs.mkShell rec {
nativeBuildInputs = with pkgs; [
# Testing
criterion.out
criterion.dev
gcovr
Expand All @@ -85,6 +65,31 @@
hardeningDisable = [ "fortify" ];
};

# Useful to build our gcc target
gcc = pkgs.mkShell {
hardeningDisable = [ "all" ];
buildInputs = with pkgs; [
# Required executables
gnumake
pkg-config
autoconf-archive
autoconf
automake
# Required libraries
gmp.dev
libmpc
mpfr.dev
flex
bison
isl
];

shellHook = ''
export TARGET=i686-dailyrun
export ARCH=
export CROSS_COMPILE=
'';
};
};
}
);
Expand Down
2 changes: 0 additions & 2 deletions include/kernel/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include <utils/compiler.h>

#include <wchar.h>

/**
* @struct kernel_symbol
* @brief A single symbol entry inside the symbol table
Expand Down
2 changes: 1 addition & 1 deletion kernel/devices/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void pci_device_setup_bars(struct pci_device *device)
}
}

static error_t __pci_device_handle_interrupt(void *device)
static u32 __pci_device_handle_interrupt(void *device)
{
struct pci_device *pdev = device;
error_t ret;
Expand Down
2 changes: 1 addition & 1 deletion kernel/devices/rtl8139.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static error_t rtl8139_receive_packet(struct rtl8139 *rtl8139)
return ret;
}

static error_t rtl8139_interrupt_handler(void *data)
static u32 rtl8139_interrupt_handler(void *data)
{
struct rtl8139 *rtl8139 = data;
uint16_t isr = rtl8139_readw(rtl8139, INTERRUPT_STATUS);
Expand Down
1 change: 0 additions & 1 deletion kernel/memory/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <utils/macro.h>
#include <utils/math.h>

#include <assert.h>
#include <multiboot.h>
#include <stddef.h>
#include <string.h>
Expand Down
2 changes: 2 additions & 0 deletions toolchain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
opt
build
1 change: 1 addition & 0 deletions toolchain/binutils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
binutils-*
43 changes: 43 additions & 0 deletions toolchain/binutils/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
TOOLCHAIN_BINUTILS_DIR := $(TOOLCHAIN_DIR)/binutils

BINUTILS_VERSION := 2.44
BINUTILS_TAR_URL := https://ftp.gnu.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
BINUTILS_TAR := $(TOOLCHAIN_BINUTILS_DIR)/binutils-$(BINUTILS_VERSION).tar.gz
BINUTILS_DIR := $(TOOLCHAIN_BINUTILS_DIR)/binutils-$(BINUTILS_VERSION)
BINUTILS_BUILD_DIR := $(BUILD_DIR)/binutils-$(BINUTILS_VERSION)/$(TARGET)
BINUTILS_LD := $(TOOLCHAIN_LOCATION)/bin/$(TARGET)-ld

$(BINUTILS_TAR):
$(call COMPILE,WGET,$@)
$(SILENT)$(WGET) $(BINUTILS_TAR_URL) -O $@

binutils/prepare: $(BINUTILS_DIR)
$(BINUTILS_DIR): $(BINUTILS_TAR)
$(call COMPILE,EXTRACT,$@)
$(SILENT)tar xf $(BINUTILS_TAR) -C $(dir $@)
$(call LOG,PATCH,$@)
$(SILENT)cp -rf $(TOOLCHAIN_BINUTILS_DIR)/target/* $@

binutils/configure: $(BINUTILS_BUILD_DIR)/config.status
$(BINUTILS_BUILD_DIR)/config.status: $(BINUTILS_DIR)
$(call COMPILE,CONFIGURE,$@)
$(SILENT)\
cd $(dir $@) && \
$(PWD)/$(BINUTILS_DIR)/configure \
--disable-nls --disable-werror \
--with-sysroot=$(PWD)/$(TOOLCHAIN_SYSROOT) \
--host="$(HOST)" \
--target="$(TARGET)" \
--prefix="$(PREFIX)" \
$(BINUTILS_CONFIGURE_FLAGS) \
> configure.log \
2> configure.err

# Target an arbitrary binutil to avoid recompiling everything
binutils: $(BINUTILS_LD)
$(BINUTILS_LD): binutils/configure
$(call LOG,MAKE,binutils-$(BINUTILS_VERSION)/$(TARGET))
$(call MAKE_RECURSIVE,$(BINUTILS_BUILD_DIR),all,binutils/)
$(call MAKE_RECURSIVE,$(BINUTILS_BUILD_DIR),install,binutils/)

.PHONY: binutils binutils/configure binutils/prepare
Loading