diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 17:24:49 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 22:00:07 +0200 |
commit | 20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec (patch) | |
tree | 473281e5fc8b256827ce1a678573444e1aa5f669 | |
parent | Generate src/conf.h (diff) | |
download | kernel-20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec.tar.xz |
Bazel build
-rw-r--r-- | .bazel/compiler_flags.bazelrc | 27 | ||||
-rw-r--r-- | .bazelrc | 11 | ||||
-rw-r--r-- | .gitignore | 12 | ||||
-rw-r--r-- | BUILD.bazel | 13 | ||||
-rw-r--r-- | MODULE.bazel | 12 | ||||
-rw-r--r-- | arch/i386/BUILD.bazel | 44 | ||||
-rw-r--r-- | arch/i386/boot.s (renamed from i686/boot.s) | 0 | ||||
-rw-r--r-- | arch/i386/gdt.c (renamed from i686/gdt.c) | 0 | ||||
-rw-r--r-- | arch/i386/gdt.h (renamed from i686/include/gdt.h) | 0 | ||||
-rw-r--r-- | arch/i386/idt.h (renamed from i686/include/idt.h) | 0 | ||||
-rw-r--r-- | arch/i386/init.s (renamed from i686/init.s) | 0 | ||||
-rw-r--r-- | arch/i386/isr.c (renamed from i686/isr.c) | 0 | ||||
-rw-r--r-- | arch/i386/lgdt.c (renamed from i686/lgdt.c) | 0 | ||||
-rw-r--r-- | arch/i386/lidt.c (renamed from i686/lidt.c) | 0 | ||||
-rw-r--r-- | arch/i386/linker.ld (renamed from i686/linker.ld) | 0 | ||||
-rw-r--r-- | arch/i386/paging.h (renamed from i686/include/paging.h) | 0 | ||||
-rw-r--r-- | arch/i386/sys/control.h (renamed from i686/include/sys/control.h) | 0 | ||||
-rw-r--r-- | arch/i386/sys/cpuid.h (renamed from i686/include/sys/cpuid.h) | 0 | ||||
-rw-r--r-- | arch/i386/sys/io.h (renamed from i686/include/sys/io.h) | 0 | ||||
-rw-r--r-- | arch/i386/sys/syscall.h (renamed from i686/include/sys/syscall.h) | 0 | ||||
-rw-r--r-- | arch/i386/test_gdt.cc (renamed from i686/test_gdt.cc) | 3 | ||||
-rw-r--r-- | config.mk | 61 | ||||
-rw-r--r-- | devices/BUILD.bazel | 22 | ||||
-rw-r--r-- | devices/meson.build | 27 | ||||
-rw-r--r-- | grub/BUILD.bazel | 9 | ||||
-rw-r--r-- | grub/include/multiboot2.h (renamed from grub/multiboot2.h) | 0 | ||||
-rw-r--r-- | grub/meson.build | 2 | ||||
-rw-r--r-- | i686/meson.build | 24 | ||||
-rw-r--r-- | kernel/BUILD.bazel | 37 | ||||
-rw-r--r-- | kernel/boot.h (renamed from src/boot.h) | 0 | ||||
-rw-r--r-- | kernel/conf.h.in | 4 | ||||
-rw-r--r-- | kernel/kernel.c (renamed from src/kernel.c) | 0 | ||||
-rw-r--r-- | kernel/mem.h (renamed from src/mem.h) | 0 | ||||
-rw-r--r-- | kernel/mem/vmm.c (renamed from src/mem/vmm.c) | 0 | ||||
-rw-r--r-- | kernel/mmap.c (renamed from src/mmap.c) | 0 | ||||
-rw-r--r-- | kernel/mmap.h (renamed from src/mmap.h) | 0 | ||||
-rw-r--r-- | kernel/multiboot2.c (renamed from src/multiboot2.c) | 0 | ||||
-rw-r--r-- | kernel/sched.hpp (renamed from src/sched.hpp) | 0 | ||||
-rw-r--r-- | kernel/sched/roundrobin.cpp (renamed from src/sched/roundrobin.cpp) | 0 | ||||
-rw-r--r-- | kernel/sched/test_roundrobin.cc (renamed from src/sched/test_roundrobin.cc) | 0 | ||||
-rw-r--r-- | kernel/sched/test_taskqueue.cc (renamed from src/sched/test_taskqueue.cc) | 0 | ||||
-rw-r--r-- | kernel/task.h (renamed from src/task.h) | 0 | ||||
-rw-r--r-- | lib/blake2/BUILD.bazel | 28 | ||||
-rw-r--r-- | lib/blake2/blake2s_kat.h (renamed from lib/blake2/tests/blake2s_kat.h) | 0 | ||||
-rw-r--r-- | lib/blake2/blake2s_selftest.cc (renamed from lib/blake2/tests/blake2s_selftest.cc) | 0 | ||||
-rw-r--r-- | lib/blake2/meson.build | 24 | ||||
-rw-r--r-- | lib/libk/BUILD.bazel | 80 | ||||
-rw-r--r-- | lib/libk/meson.build | 41 | ||||
-rw-r--r-- | meson.build | 39 | ||||
-rw-r--r-- | meson/compiler_flags/meson.build | 34 | ||||
-rw-r--r-- | platforms/BUILD.bazel | 7 | ||||
-rw-r--r-- | project_config.bzl | 2 | ||||
-rw-r--r-- | src/meson.build | 36 | ||||
-rw-r--r-- | toolchains/BUILD.bazel | 34 | ||||
-rw-r--r-- | toolchains/i386_elf_gcc.bzl | 123 | ||||
-rw-r--r-- | toolchains/i386_qemu.bzl | 8 | ||||
-rw-r--r-- | tools/BUILD.bazel | 6 | ||||
-rw-r--r-- | tools/configure_file.bzl | 29 | ||||
-rw-r--r-- | tools/make_iso.bzl | 41 | ||||
-rw-r--r-- | tools/qemu.bzl | 33 |
60 files changed, 573 insertions, 300 deletions
diff --git a/.bazel/compiler_flags.bazelrc b/.bazel/compiler_flags.bazelrc new file mode 100644 index 0000000..59a87f3 --- /dev/null +++ b/.bazel/compiler_flags.bazelrc @@ -0,0 +1,27 @@ +build --copt=-Wall +build --copt=-Wextra +build --copt=-Wpedantic +build --copt=-Werror=shadow +build --copt=-Wunused-parameter +build --copt=-Wmisleading-indentation +build --copt=-Wundef +build --copt=-Wuninitialized + +# cast warnings +build --copt=-Wcast-align +build --copt=-Wcast-qual + +# conversion +build --copt=-Wconversion +build --copt=-Wsign-conversion +build --copt=-Wdouble-promotion + +# pointers +build --copt=-Wpointer-arith +build --copt=-Wnull-dereference + +# cpp flags +build --cxxopt=-Wnon-virtual-dtor +build --cxxopt=-Woverloaded-virtual +build --cxxopt=-Wold-style-cast + diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..2a0a947 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,11 @@ +# compiler flags +try-import %workspace%/.bazel/compiler_flags.bazelrc + +build --instrument_test_targets + +build:i386 --compilation_mode=opt +build:i386 --platforms=//platforms:i386 + +coverage --combined_report=lcov + +test --compilation_mode=dbg @@ -1,13 +1,3 @@ -lib/musl* -build -*.a -*.elf -*.iso -isodir -src/conf.h +bazel-* .config.old -doc -# test files -test_* -!test_*.cc diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..9c05b27 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,13 @@ +load("//tools:make_iso.bzl", "make_iso") +load("//tools:qemu.bzl", "qemu") + +make_iso( + name = "glitch", + bootloader = "//grub:grub.cfg", + kernel = "//kernel:glitch.elf", +) + +qemu( + name = "qemu", + cdrom = ":glitch", +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..fbf1ad8 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,12 @@ +############################################################################### +# Bazel now uses Bzlmod by default to manage external dependencies. +# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. +# +# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 +############################################################################### + +register_toolchains( + "//toolchains:i386_elf_gcc", +) + +bazel_dep(name = "googletest", version = "1.14.0") diff --git a/arch/i386/BUILD.bazel b/arch/i386/BUILD.bazel new file mode 100644 index 0000000..2842a5b --- /dev/null +++ b/arch/i386/BUILD.bazel @@ -0,0 +1,44 @@ +exports_files( + ["linker.ld"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "arch", + srcs = [ + "boot.s", + "gdt.c", + "init.s", + "isr.c", + "lgdt.c", + "lidt.c", + ], + hdrs = [ + "gdt.h", + "idt.h", + "paging.h", + ] + glob(["sys/*.h"]), + includes = ["."], + target_compatible_with = [ + "@platforms//os:none", + ], + visibility = ["//visibility:public"], + deps = ["//lib/libk:k"], +) + +# tests +cc_test( + name = "test_gdt", + srcs = [ + "gdt.c", + "gdt.h", + "test_gdt.cc", + ], + target_compatible_with = select({ + "@platforms//os:none": ["@platforms//:incompatible"], + "//conditions:default": [], + }), + deps = [ + "@googletest//:gtest_main", + ], +) diff --git a/i686/boot.s b/arch/i386/boot.s index 40b0389..40b0389 100644 --- a/i686/boot.s +++ b/arch/i386/boot.s diff --git a/i686/gdt.c b/arch/i386/gdt.c index 3148096..3148096 100644 --- a/i686/gdt.c +++ b/arch/i386/gdt.c diff --git a/i686/include/gdt.h b/arch/i386/gdt.h index 2bdfb22..2bdfb22 100644 --- a/i686/include/gdt.h +++ b/arch/i386/gdt.h diff --git a/i686/include/idt.h b/arch/i386/idt.h index ca39bde..ca39bde 100644 --- a/i686/include/idt.h +++ b/arch/i386/idt.h diff --git a/i686/init.s b/arch/i386/init.s index ad329bb..ad329bb 100644 --- a/i686/init.s +++ b/arch/i386/init.s diff --git a/i686/isr.c b/arch/i386/isr.c index acc2961..acc2961 100644 --- a/i686/isr.c +++ b/arch/i386/isr.c diff --git a/i686/lgdt.c b/arch/i386/lgdt.c index 473a91d..473a91d 100644 --- a/i686/lgdt.c +++ b/arch/i386/lgdt.c diff --git a/i686/lidt.c b/arch/i386/lidt.c index 86567f8..86567f8 100644 --- a/i686/lidt.c +++ b/arch/i386/lidt.c diff --git a/i686/linker.ld b/arch/i386/linker.ld index 61a3be9..61a3be9 100644 --- a/i686/linker.ld +++ b/arch/i386/linker.ld diff --git a/i686/include/paging.h b/arch/i386/paging.h index f5bfa78..f5bfa78 100644 --- a/i686/include/paging.h +++ b/arch/i386/paging.h diff --git a/i686/include/sys/control.h b/arch/i386/sys/control.h index 89ab067..89ab067 100644 --- a/i686/include/sys/control.h +++ b/arch/i386/sys/control.h diff --git a/i686/include/sys/cpuid.h b/arch/i386/sys/cpuid.h index 6613967..6613967 100644 --- a/i686/include/sys/cpuid.h +++ b/arch/i386/sys/cpuid.h diff --git a/i686/include/sys/io.h b/arch/i386/sys/io.h index 4ff5d85..4ff5d85 100644 --- a/i686/include/sys/io.h +++ b/arch/i386/sys/io.h diff --git a/i686/include/sys/syscall.h b/arch/i386/sys/syscall.h index 9e62c89..9e62c89 100644 --- a/i686/include/sys/syscall.h +++ b/arch/i386/sys/syscall.h diff --git a/i686/test_gdt.cc b/arch/i386/test_gdt.cc index e437168..3501ae9 100644 --- a/i686/test_gdt.cc +++ b/arch/i386/test_gdt.cc @@ -1,7 +1,8 @@ #include <gtest/gtest.h> -#include "gdt.c" +extern "C" { #include "gdt.h" +} TEST(i686GDT, KnownAccessByteValues) { diff --git a/config.mk b/config.mk deleted file mode 100644 index 36fc32f..0000000 --- a/config.mk +++ /dev/null @@ -1,61 +0,0 @@ -# -# Automatically generated file; DO NOT EDIT. -# Main menu -# - -# -# Toolchain -# -CONFIG_ARCH_i686=y -# CONFIG_ARCH_mips is not set -CONFIG_TOOLCHAIN_i686_gcc=y -CONFIG_CFLAGS="-g -Og" -CONFIG_CXXFLAGS="-g -Og" -CONFIG_LDFLAGS="" -# end of Toolchain - -# -# Devices -# -CONFIG_PIC_8259=y -CONFIG_UART_16550=y -CONFIG_VGA_TEXT_MODE=y -CONFIG_KB_PS2=y -# end of Devices - -## toolchain.mk -ARCH=i686 - -# define compiler, linker, archiver and strip and their flags -${ARCH}_AS := i686-elf-as - -${ARCH}_CC := i686-elf-gcc -ansi -${ARCH}_CCID := $(shell ${${ARCH}_CC} --version | head -n1) -${ARCH}_CFLAGS := -Wall -Wextra -Wpedantic -Werror=shadow -Wconversion -fanalyzer \ - -D__ARCH__="${ARCH}" -ffreestanding -mgeneral-regs-only \ - $(shell echo ${CONFIG_CFLAGS}) - -${ARCH}_LD := i686-elf-ld -${ARCH}_LDID := $(shell ${${ARCH}_LD} --version | head -n1) -${ARCH}_LDFLAGS := -static -nostdlib \ - $(shell echo ${CONFIG_LDFLAGS}) - -${ARCH}_AR := i686-elf-ar -${ARCH}_ARFLAGS := -crus - -${ARCH}_STRIP := i686-elf-strip - -# define compiler and flags for test targets -HOST_CC := gcc -HOST_CFLAGS := -Wall -Wextra -Wpedantic -Werror=shadow -Wconversion \ - ${CFLAGS} -HOST_CXX := g++ -HOST_CXXFLAGS := -Wall -Wextra -Wpedantic -Werror=shadow -Wconversion -g -Og \ - $(shell pkg-config --cflags gtest gtest_main gmock) \ - ${CXXFLAGS} - -HOST_LDFLAGS := $(shell pkg-config --libs gtest gtest_main gmock) - -# emulator name and flags -QEMU := qemu-system-i386 -accel kvm -machine pc - diff --git a/devices/BUILD.bazel b/devices/BUILD.bazel new file mode 100644 index 0000000..0c58d48 --- /dev/null +++ b/devices/BUILD.bazel @@ -0,0 +1,22 @@ +cc_library( + name = "drivers", + srcs = [ + "i8042.c", + "mouse.c", + "pckbd.c", + "pic_8259.c", + "uart/uart_16550.c", + "uart/uart_16550.h", + "vga.c", + ], + hdrs = glob(["include/*.h"]), + defines = [ + "__ARCH__=i386", + ], + includes = ["include"], + visibility = ["//visibility:public"], + deps = [ + "//arch/i386:arch", + "//lib/libk:k", + ], +) diff --git a/devices/meson.build b/devices/meson.build deleted file mode 100644 index d6f4739..0000000 --- a/devices/meson.build +++ /dev/null @@ -1,27 +0,0 @@ -devs_srcs = files( - 'pic_8259.c', - 'uart/uart_16550.c', - 'vga.c', - 'i8042.c', - 'pckbd.c', - 'mouse.c', -) -devs_incl = include_directories('include') - -devs = declare_dependency( - link_with: static_library('devs', devs_srcs, - include_directories: devs_incl, - dependencies: [ libk, i686 ], - ), - include_directories: devs_incl, -) - -# tests -test('uart_16550', - executable('test_uart_16550', 'uart/uart_16550.c', 'uart/unittest_uart_16550.cc', - include_directories: devs_incl, - dependencies: [ gtest, gmock ], - native: true), - suite: 'dev' -) - diff --git a/grub/BUILD.bazel b/grub/BUILD.bazel new file mode 100644 index 0000000..2d12cc1 --- /dev/null +++ b/grub/BUILD.bazel @@ -0,0 +1,9 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files(["grub.cfg"]) + +cc_library( + name = "multiboot2", + hdrs = ["include/multiboot2.h"], + includes = ["include"], +) diff --git a/grub/multiboot2.h b/grub/include/multiboot2.h index 5a3db5a..5a3db5a 100644 --- a/grub/multiboot2.h +++ b/grub/include/multiboot2.h diff --git a/grub/meson.build b/grub/meson.build deleted file mode 100644 index 917f8d7..0000000 --- a/grub/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -grub_incl = include_directories('.', is_system: true) - diff --git a/i686/meson.build b/i686/meson.build deleted file mode 100644 index 21ff729..0000000 --- a/i686/meson.build +++ /dev/null @@ -1,24 +0,0 @@ - -i686_srcs = files( - 'boot.s', 'init.s', - 'gdt.c', 'lgdt.c', - 'lidt.c', 'isr.c', -) -i686_incl = include_directories('include') - -i686 = declare_dependency( - link_with: static_library('i686', i686_srcs, - include_directories: i686_incl, - dependencies: libk - ), - include_directories: i686_incl, -) - -# tests -test('GDT', - executable('test_gdt', 'test_gdt.cc', - include_directories: i686_incl, - dependencies: [ gtest ], - native: true), - suite: 'i686' -) diff --git a/kernel/BUILD.bazel b/kernel/BUILD.bazel new file mode 100644 index 0000000..e7ed087 --- /dev/null +++ b/kernel/BUILD.bazel @@ -0,0 +1,37 @@ +load("//tools:configure_file.bzl", "configure_file") + +configure_file( + name = "conf", + template = "conf.h.in", +) + +cc_binary( + name = "glitch.elf", + srcs = [ + "boot.h", + "kernel.c", + "mem.h", + "mem/vmm.c", + "mmap.c", + "mmap.h", + "multiboot2.c", + "task.h", + ":conf.h", + ], + includes = ["."], + linkopts = [ + "-T", + "$(location //arch/i386:linker.ld)", + ], + target_compatible_with = [ + "@platforms//os:none", + ], + visibility = ["//visibility:public"], + deps = [ + "//arch/i386:arch", + "//arch/i386:linker.ld", + "//devices:drivers", + "//grub:multiboot2", + "//lib/libk:k", + ], +) diff --git a/src/boot.h b/kernel/boot.h index 646fb4c..646fb4c 100644 --- a/src/boot.h +++ b/kernel/boot.h diff --git a/kernel/conf.h.in b/kernel/conf.h.in new file mode 100644 index 0000000..61352d7 --- /dev/null +++ b/kernel/conf.h.in @@ -0,0 +1,4 @@ +#pragma once + +#define VERSION {VERSION} +#define CC {CC} diff --git a/src/kernel.c b/kernel/kernel.c index 98269c1..98269c1 100644 --- a/src/kernel.c +++ b/kernel/kernel.c diff --git a/src/mem/vmm.c b/kernel/mem/vmm.c index a07dd72..a07dd72 100644 --- a/src/mem/vmm.c +++ b/kernel/mem/vmm.c diff --git a/src/mmap.c b/kernel/mmap.c index e5d4be6..e5d4be6 100644 --- a/src/mmap.c +++ b/kernel/mmap.c diff --git a/src/mmap.h b/kernel/mmap.h index 13f40f2..13f40f2 100644 --- a/src/mmap.h +++ b/kernel/mmap.h diff --git a/src/multiboot2.c b/kernel/multiboot2.c index bd6250f..bd6250f 100644 --- a/src/multiboot2.c +++ b/kernel/multiboot2.c diff --git a/src/sched.hpp b/kernel/sched.hpp index cfa3ff0..cfa3ff0 100644 --- a/src/sched.hpp +++ b/kernel/sched.hpp diff --git a/src/sched/roundrobin.cpp b/kernel/sched/roundrobin.cpp index c3d6cb6..c3d6cb6 100644 --- a/src/sched/roundrobin.cpp +++ b/kernel/sched/roundrobin.cpp diff --git a/src/sched/test_roundrobin.cc b/kernel/sched/test_roundrobin.cc index 89f60bf..89f60bf 100644 --- a/src/sched/test_roundrobin.cc +++ b/kernel/sched/test_roundrobin.cc diff --git a/src/sched/test_taskqueue.cc b/kernel/sched/test_taskqueue.cc index 217c44d..217c44d 100644 --- a/src/sched/test_taskqueue.cc +++ b/kernel/sched/test_taskqueue.cc diff --git a/src/task.h b/kernel/task.h index 0d59bb1..0d59bb1 100644 --- a/src/task.h +++ b/kernel/task.h diff --git a/lib/blake2/BUILD.bazel b/lib/blake2/BUILD.bazel new file mode 100644 index 0000000..4723ae6 --- /dev/null +++ b/lib/blake2/BUILD.bazel @@ -0,0 +1,28 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "blake2s", + srcs = ["blake2s.c"], + hdrs = ["include/blake2s.h"], + includes = ["include"], + deps = select({ + "@platforms//os:none": ["//lib/libk:k"], + "//conditions:default": [], + }), +) + +cc_test( + name = "test_blake2s", + srcs = [ + "blake2s_kat.h", + "blake2s_selftest.cc", + ], + target_compatible_with = select({ + "@platforms//os:none": ["@platforms//:incompatible"], + "//conditions:default": [], + }), + deps = [ + "//lib/blake2:blake2s", + "@googletest//:gtest_main", + ], +) diff --git a/lib/blake2/tests/blake2s_kat.h b/lib/blake2/blake2s_kat.h index dec250a..dec250a 100644 --- a/lib/blake2/tests/blake2s_kat.h +++ b/lib/blake2/blake2s_kat.h diff --git a/lib/blake2/tests/blake2s_selftest.cc b/lib/blake2/blake2s_selftest.cc index 420544d..420544d 100644 --- a/lib/blake2/tests/blake2s_selftest.cc +++ b/lib/blake2/blake2s_selftest.cc diff --git a/lib/blake2/meson.build b/lib/blake2/meson.build deleted file mode 100644 index dc06f3e..0000000 --- a/lib/blake2/meson.build +++ /dev/null @@ -1,24 +0,0 @@ - -blake2s_srcs = files('blake2s.c') -blake2s_incl = include_directories('include') - -blake2s = declare_dependency( - link_with: static_library('blake2s', blake2s_srcs, - include_directories: blake2s_incl, - dependencies: libk), - include_directories: blake2s_incl, -) - -# tests -blake2s_sut = declare_dependency( - link_with: library('blake2s_sut', blake2s_srcs, - include_directories: blake2s_incl, - native: true), - include_directories: blake2s_incl, -) - -test('blake2s selftest', - executable('test_blake2s_selftest', 'tests/blake2s_selftest.cc', - dependencies: [ blake2s_sut, gtest ], - native: true) -) diff --git a/lib/libk/BUILD.bazel b/lib/libk/BUILD.bazel new file mode 100644 index 0000000..51b4c1b --- /dev/null +++ b/lib/libk/BUILD.bazel @@ -0,0 +1,80 @@ +filegroup( + name = "k_srcs", + srcs = [ + "endian/little.c", + "stdio/fprintf.c", + "stdio/printf.c", + "stdio/vfprintf.c", + "stdlib/linked_list_allocator.c", + "stdlib/memcpy.c", + "stdlib/memset.c", + "string/itoa.c", + ], +) + +cc_library( + name = "k", + srcs = [":k_srcs"], + hdrs = glob(["include/*.h"]), + includes = ["include"], + target_compatible_with = [ + "@platforms//os:none", + ], + visibility = ["//visibility:public"], +) + +# tests +cc_library( + name = "k_sut", + includes = ["."], + target_compatible_with = select({ + "@platforms//os:none": ["@platforms//:incompatible"], + "//conditions:default": [], + }), + textual_hdrs = [":k_srcs"], +) + +cc_test( + name = "test_endian_little", + srcs = [ + "endian/test_endian_little.cc", + ], + deps = [ + ":k_sut", + "@googletest//:gtest_main", + ], +) + +cc_test( + name = "test_linked_list_allocator", + srcs = [ + "stdlib/test_allocator.hh", + "stdlib/test_linked_list_allocator.cc", + ], + deps = [ + ":k_sut", + "@googletest//:gtest_main", + ], +) + +cc_test( + name = "test_mem", + srcs = [ + "stdlib/test_mem.cc", + ], + deps = [ + ":k_sut", + "@googletest//:gtest_main", + ], +) + +cc_test( + name = "test_string", + srcs = [ + "string/test_string.cc", + ], + deps = [ + ":k_sut", + "@googletest//:gtest_main", + ], +) diff --git a/lib/libk/meson.build b/lib/libk/meson.build deleted file mode 100644 index 669780b..0000000 --- a/lib/libk/meson.build +++ /dev/null @@ -1,41 +0,0 @@ - -libk_srcs = files( - 'endian/little.c', - 'stdio/printf.c', 'stdio/fprintf.c', 'stdio/vfprintf.c', - 'stdlib/memcpy.c', 'stdlib/memset.c', 'stdlib/linked_list_allocator.c', - 'string/itoa.c') -libk_incl = include_directories('include') - -libk = declare_dependency( - link_with: static_library('k', libk_srcs, include_directories: libk_incl), - include_directories: libk_incl, -) - -# tests -test('endian little', - executable('test_endian_little', 'endian/test_endian_little.cc', - dependencies: [ gtest ], - native: true), - suite: 'libk' -) - -test('linked list allocator', - executable('test_linked_list_allocator', 'stdlib/test_linked_list_allocator.cc', - dependencies: [ gtest ], - native: true), - suite: 'libk' -) - -test('mem', - executable('test_mem', 'stdlib/test_mem.cc', - dependencies: [ gtest ], - native: true), - suite: 'libk' -) - -test('string', - executable('test_string', 'string/test_string.cc', - dependencies: [ gtest ], - native: true), - suite: 'libk' -) diff --git a/meson.build b/meson.build deleted file mode 100644 index b5c6763..0000000 --- a/meson.build +++ /dev/null @@ -1,39 +0,0 @@ -project('glitch', ['c', 'cpp'], - version: '0.1.0', - default_options: { - 'c_std': 'c89', - 'cpp_std': 'c++20', - 'warning_level': '3', - 'buildtype': 'plain', - 'b_staticpic': false, - } -) - -# meson includes -subdir('meson/compiler_flags') - -# common dependencies -pymod = import('python') -python = pymod.find_installation() -qemu_i386 = find_program('qemu-system-i386') -gtest = dependency('gtest', main: true, native: true, disabler: true) -gmock = dependency('gmock', native: true, disabler: true) - -# components -subdir('grub') -subdir('lib/libk') -subdir('lib/blake2') -subdir('i686') -subdir('devices') -subdir('src') - -glitch_iso = custom_target('glitch.iso', - input: ['tools/make_iso.py', 'grub/grub.cfg', glitch_elf], - output: 'glitch.iso', - command: [python, '@INPUT0@', '-c=@INPUT1@', '-k=@INPUT2@', '-o=@OUTPUT@'], -) - -run_target('run_i686', - command: [qemu_i386, '-accel', 'kvm', '-machine', 'pc', '-cdrom', glitch_iso, - '-d', 'cpu_reset', '-display', 'gtk,zoom-to-fit=on'], -) diff --git a/meson/compiler_flags/meson.build b/meson/compiler_flags/meson.build deleted file mode 100644 index f159eb4..0000000 --- a/meson/compiler_flags/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -# global compiler settings -common_compiler_flags = [ - '-Wshadow', - '-Wunused', '-Wunused-parameter', - '-Wmisleading-indentation', - '-Wundef', - '-Wuninitialized', - # casts - '-Wcast-align', # performance problem casts - '-Wcast-qual', - # conversion - '-Wconversion', # type conversion may lose data - '-Wsign-conversion', # sign conversion - '-Wdouble-promotion', # implicit float to double - # pointers - '-Wpointer-arith', - '-Wnull-dereference', -] -c_compiler_flags = [ - '-fanalyzer', -] -cpp_compiler_flags = [ - '-Weffc++', - # inheritance - '-Wnon-virtual-dtor', # class with virtual functions has non-virt dtor - '-Woverloaded-virtual', # overloaded (not override) virtual function - # casts - '-Wold-style-cast', # C-style casts -] -add_project_arguments(common_compiler_flags, c_compiler_flags, language: 'c') -add_project_arguments(common_compiler_flags, cpp_compiler_flags, language: 'cpp') -add_project_arguments('-D__ARCH__=i686', language: 'c', native: false) - -subdir_done() diff --git a/platforms/BUILD.bazel b/platforms/BUILD.bazel new file mode 100644 index 0000000..1f13594 --- /dev/null +++ b/platforms/BUILD.bazel @@ -0,0 +1,7 @@ +platform( + name = "i386", + constraint_values = [ + "@platforms//cpu:i386", + "@platforms//os:none", + ], +) diff --git a/project_config.bzl b/project_config.bzl new file mode 100644 index 0000000..a4c58fb --- /dev/null +++ b/project_config.bzl @@ -0,0 +1,2 @@ +def version(): + return "0.1.0" diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index 881dffa..0000000 --- a/src/meson.build +++ /dev/null @@ -1,36 +0,0 @@ - -# generated files -conf_h = configure_file( - #input: 'conf.h.in', - output: 'conf.h', - configuration: { - 'VERSION': '"@0@"'.format(meson.project_version()), - 'CC': '"@0@-@1@"'.format(meson.get_compiler('c').version(), - meson.get_compiler('c').get_id()), - } -) - -kernel_srcs = files('multiboot2.c', 'mmap.c', 'kernel.c', 'mem/vmm.c') -kernel_incl = include_directories('.') - -glitch_elf = executable('glitch.elf', kernel_srcs, - include_directories: [ kernel_incl, grub_incl ], - dependencies: [ libk, devs, i686 ], - link_args: [ '-static', '-nostdlib', '-T', '../i686/linker.ld' ], -) - -# tests -test('taskqueue', - executable('test_taskqueue', 'sched/test_taskqueue.cc', - dependencies: [ gtest ], - native: true), - suite: 'kernel' -) - -test('roundrobin', - executable('test_roundrobin', 'sched/test_roundrobin.cc', - dependencies: [ gtest ], - native: true), - suite: 'kernel' -) - diff --git a/toolchains/BUILD.bazel b/toolchains/BUILD.bazel new file mode 100644 index 0000000..d46f812 --- /dev/null +++ b/toolchains/BUILD.bazel @@ -0,0 +1,34 @@ +load(":i386_elf_gcc.bzl", "cc_toolchain_config") + +package(default_visibility = ["//visibility:public"]) + +filegroup(name = "empty") + +cc_toolchain_config(name = "i386_elf_gcc_toolchain_config") + +cc_toolchain( + name = "i386_elf_gcc_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":i386_elf_gcc_toolchain_config", + toolchain_identifier = "none_i386-toolchain", +) + +toolchain( + name = "i386_elf_gcc", + exec_compatible_with = [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + target_compatible_with = [ + "@platforms//cpu:i386", + "@platforms//os:none", + ], + toolchain = ":i386_elf_gcc_toolchain", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/toolchains/i386_elf_gcc.bzl b/toolchains/i386_elf_gcc.bzl new file mode 100644 index 0000000..ad933d2 --- /dev/null +++ b/toolchains/i386_elf_gcc.bzl @@ -0,0 +1,123 @@ +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "flag_group", + "flag_set", + "tool_path", +) + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +all_compile_actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.clif_match, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.lto_backend, + ACTION_NAMES.preprocess_assemble, +] + +def _impl(ctx): + tool_paths = [ + tool_path( + name = "gcc", + path = "/usr/bin/i686-elf-gcc", + ), + tool_path( + name = "ld", + path = "/usr/bin/i686-elf-ld", + ), + tool_path( + name = "ar", + path = "/usr/bin/i686-elf-ar", + ), + tool_path( + name = "cpp", + path = "/usr/bin/i686-elf-cpp", + ), + tool_path( + name = "gcov", + path = "/bin/false", + ), + tool_path( + name = "nm", + path = "/usr/bin/i686-elf-nm", + ), + tool_path( + name = "objdump", + path = "/usr/bin/i686-elf-objdump", + ), + tool_path( + name = "strip", + path = "/usr/bin/i686-elf-strip", + ), + ] + + features = [ + feature( + name = "default_compiler_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = [ + "-fanalyzer", + "-ffreestanding", + "-mgeneral-regs-only", + ], + ), + ], + ), + ], + ), + feature( + name = "default_linker_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = ([ + flag_group( + flags = [ + "-nostdlib", + ], + ), + ]), + ), + ], + ), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + cxx_builtin_include_directories = [ + "/usr/lib/gcc/i686-elf", + ], + toolchain_identifier = "local", + host_system_name = "local", + target_system_name = "local", + target_cpu = "i686", + target_libc = "unknown", + compiler = "gcc", + abi_version = "unknown", + abi_libc_version = "unknown", + tool_paths = tool_paths, + ) + +cc_toolchain_config = rule( + implementation = _impl, + attrs = {}, + provides = [CcToolchainConfigInfo], +) diff --git a/toolchains/i386_qemu.bzl b/toolchains/i386_qemu.bzl new file mode 100644 index 0000000..c9f8535 --- /dev/null +++ b/toolchains/i386_qemu.bzl @@ -0,0 +1,8 @@ +_wrapper_template = """\ +#!/bin/bash +qemu-system-i386 -accel kvm -machine pc -d cpu_reset -display gtk,zoom-to-fit=on -cdrom {cdrom} +""" + +def qemu_wrapper(): + return _wrapper_template + diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel new file mode 100644 index 0000000..fddb974 --- /dev/null +++ b/tools/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +py_binary( + name = "make_iso", + srcs = ["make_iso.py"], +) diff --git a/tools/configure_file.bzl b/tools/configure_file.bzl new file mode 100644 index 0000000..8fdd75c --- /dev/null +++ b/tools/configure_file.bzl @@ -0,0 +1,29 @@ +load("//:project_config.bzl", "version") +load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain") + +def configure_file(**kwargs): + _configure_file( + source_file = "{name}.h".format(**kwargs), + **kwargs + ) + +def _configure_file_impl(ctx): + cc_toolchain = find_cc_toolchain(ctx) + + ctx.actions.expand_template( + template = ctx.file.template, + output = ctx.outputs.source_file, + substitutions = { + "{VERSION}": '"{}"'.format(version()), + "{CC}": '"{} " __VERSION__'.format(cc_toolchain.compiler), + }, + ) + +_configure_file = rule( + attrs = { + "template": attr.label(allow_single_file = True), + "source_file": attr.output(mandatory = True), + }, + toolchains = use_cc_toolchain(), + implementation = _configure_file_impl, +) diff --git a/tools/make_iso.bzl b/tools/make_iso.bzl new file mode 100644 index 0000000..5ff20f5 --- /dev/null +++ b/tools/make_iso.bzl @@ -0,0 +1,41 @@ +def make_iso(**kwargs): + _make_iso( + image = "{name}.iso".format(**kwargs), + **kwargs + ) + +def _make_iso_impl(ctx): + inputs = [] + outputs = [] + args = ctx.actions.args() + + args.add("-c", ctx.file.bootloader.path) + inputs.append(ctx.file.bootloader) + args.add("-k", ctx.file.kernel.path) + inputs.append(ctx.file.kernel) + + args.add("-o", ctx.outputs.image.path) + outputs.append(ctx.outputs.image) + + ctx.actions.run( + inputs = inputs, + outputs = outputs, + arguments = [args], + executable = ctx.executable._generator, + progress_message = "Generating ISO image %s" % ctx.label.name, + ) + +_make_iso = rule( + attrs = { + "bootloader": attr.label(allow_single_file = True), + "kernel": attr.label(allow_single_file = True), + "image": attr.output(), + "_generator": attr.label( + default = Label(":make_iso"), + executable = True, + allow_files = True, + cfg = "exec", + ), + }, + implementation = _make_iso_impl, +) diff --git a/tools/qemu.bzl b/tools/qemu.bzl new file mode 100644 index 0000000..9493306 --- /dev/null +++ b/tools/qemu.bzl @@ -0,0 +1,33 @@ +load("//toolchains:i386_qemu.bzl", qemu_i386 = "qemu_wrapper") + +def qemu(**kwargs): + _qemu( + wrapper_content = select({ + "@platforms//cpu:i386": qemu_i386(), + "//conditions:default": "/bin/false", + }), + **kwargs + ) + +def _qemu_impl(ctx): + print(ctx) + print(ctx.attr) + + wrapper = ctx.actions.declare_file("%s_wrapper" % ctx.label.name) + wrapper_content = ctx.attr.wrapper_content.format( + cdrom = ctx.file.cdrom.basename, + ) + ctx.actions.write(wrapper, wrapper_content, is_executable = True) + + runfiles = ctx.runfiles(files = [ctx.file.cdrom]) + + return [DefaultInfo(executable = wrapper, runfiles = runfiles)] + +_qemu = rule( + implementation = _qemu_impl, + attrs = { + "cdrom": attr.label(allow_single_file = True), + "wrapper_content": attr.string(), + }, + executable = True, +) |