aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-10-08 19:50:00 +0300
committeraqua <aqua@iserlohn-fortress.net>2023-11-27 21:02:22 +0200
commitfc13fb2ba5993d06d9d6ae5e80bc337aebbdc119 (patch)
tree9607ab4d5f1d4069d4f761a0b25eada36088bd6b
parentrules.mk: make include paths absolute (diff)
downloadkernel-fc13fb2ba5993d06d9d6ae5e80bc337aebbdc119.tar.xz
Use meson build system
-rw-r--r--.gitignore1
-rw-r--r--devices/include/keyboard.h (renamed from devices/keyboard.h)0
-rw-r--r--devices/include/mouse.h (renamed from devices/mouse.h)0
-rw-r--r--devices/include/pic.h (renamed from devices/pic.h)0
-rw-r--r--devices/include/ps2_controller.h (renamed from devices/ps2_controller.h)0
-rw-r--r--devices/include/uart.h (renamed from devices/uart.h)4
-rw-r--r--devices/include/vga.h (renamed from devices/vga.h)0
-rw-r--r--devices/meson.build27
-rwxr-xr-xdevices/mk14
-rw-r--r--devices/uart/uart_16550.h2
-rw-r--r--devices/uart/unittest_uart_16550.cc2
-rw-r--r--grub/meson.build2
-rw-r--r--i686-elf-gcc.txt9
-rw-r--r--i686/include/gdt.h (renamed from i686/gdt.h)0
-rw-r--r--i686/include/idt.h (renamed from i686/idt.h)0
-rw-r--r--i686/include/paging.h (renamed from i686/paging.h)0
-rw-r--r--i686/include/sys/control.h (renamed from i686/sys/control.h)0
-rw-r--r--i686/include/sys/cpuid.h (renamed from i686/sys/cpuid.h)0
-rw-r--r--i686/include/sys/io.h (renamed from i686/sys/io.h)0
-rw-r--r--i686/include/sys/syscall.h (renamed from i686/sys/syscall.h)0
-rw-r--r--i686/meson.build24
-rwxr-xr-xi686/mk16
-rw-r--r--i686/toolchain.mk35
-rw-r--r--lib/blake2/include/blake2s.h (renamed from lib/blake2/blake2s.h)0
-rw-r--r--lib/blake2/meson.build24
-rw-r--r--lib/blake2/tests/blake2s_kat.h (renamed from lib/blake2/test_blake2_kat.h)2
-rw-r--r--lib/blake2/tests/blake2s_selftest.cc (renamed from lib/blake2/test_blake2s_selftest.cc)13
-rw-r--r--lib/libk/include/endian.h (renamed from lib/libk/endian.h)0
-rw-r--r--lib/libk/include/stdio.h (renamed from lib/libk/stdio.h)0
-rw-r--r--lib/libk/include/stdlib.h (renamed from lib/libk/stdlib.h)0
-rw-r--r--lib/libk/include/string.h (renamed from lib/libk/string.h)0
-rw-r--r--lib/libk/meson.build41
-rwxr-xr-xlib/mk36
-rwxr-xr-xmach22
-rw-r--r--meson.build39
-rw-r--r--meson/compiler_flags/meson.build34
-rwxr-xr-xmk57
-rw-r--r--root.mk43
-rw-r--r--rules.mk146
-rw-r--r--src/meson.build25
-rwxr-xr-xsrc/mk25
-rwxr-xr-xtools/make_iso.py58
42 files changed, 294 insertions, 407 deletions
diff --git a/.gitignore b/.gitignore
index 6009cfd..8ae6f9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,6 @@ isodir
src/conf.h
.config.old
doc
-include/
# test files
test_*
diff --git a/devices/keyboard.h b/devices/include/keyboard.h
index 5f4fcc2..5f4fcc2 100644
--- a/devices/keyboard.h
+++ b/devices/include/keyboard.h
diff --git a/devices/mouse.h b/devices/include/mouse.h
index a34ecb4..a34ecb4 100644
--- a/devices/mouse.h
+++ b/devices/include/mouse.h
diff --git a/devices/pic.h b/devices/include/pic.h
index c545c60..c545c60 100644
--- a/devices/pic.h
+++ b/devices/include/pic.h
diff --git a/devices/ps2_controller.h b/devices/include/ps2_controller.h
index d2f7e80..d2f7e80 100644
--- a/devices/ps2_controller.h
+++ b/devices/include/ps2_controller.h
diff --git a/devices/uart.h b/devices/include/uart.h
index 53a4f41..8b44519 100644
--- a/devices/uart.h
+++ b/devices/include/uart.h
@@ -5,7 +5,7 @@
#include <sys/io.h>
#else
-// from stdio
+/* from stdio */
typedef struct FILE {
int id;
void (*putc)(const struct FILE *, char);
@@ -13,7 +13,7 @@ typedef struct FILE {
void (*flush)(const struct FILE *);
} FILE;
-// from sys/io
+/* from sys/io */
unsigned char inb(unsigned short);
void outb(unsigned char, unsigned short);
diff --git a/devices/vga.h b/devices/include/vga.h
index df0d921..df0d921 100644
--- a/devices/vga.h
+++ b/devices/include/vga.h
diff --git a/devices/meson.build b/devices/meson.build
new file mode 100644
index 0000000..d6f4739
--- /dev/null
+++ b/devices/meson.build
@@ -0,0 +1,27 @@
+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/devices/mk b/devices/mk
deleted file mode 100755
index b27d945..0000000
--- a/devices/mk
+++ /dev/null
@@ -1,14 +0,0 @@
-#!../mach
-
-INCLUDES := -I../${ARCH}
-${ARCH}_CFLAGS += ${INCLUDES}
-${ARCH}_CXXFLAGS += ${INCLUDES}
-
-TARGETLIB += devs
-devs.SRCS = pic_8259.c uart/uart_16550.c vga.c i8042.c pckbd.c mouse.c
-
-HOSTTARGETBIN += uart/test_uart_16550
-uart/test_uart_16550.SRCS = uart/uart_16550.c uart/unittest_uart_16550.cc
-
-TESTS += uart/test_uart_16550
-
diff --git a/devices/uart/uart_16550.h b/devices/uart/uart_16550.h
index d4f470e..bbeb9b7 100644
--- a/devices/uart/uart_16550.h
+++ b/devices/uart/uart_16550.h
@@ -1,6 +1,6 @@
#pragma once
-#include "../uart.h"
+#include "uart.h"
int uart_thre(unsigned short port);
void uart_putc(const FILE *self, char a);
diff --git a/devices/uart/unittest_uart_16550.cc b/devices/uart/unittest_uart_16550.cc
index 16e7202..f8124bb 100644
--- a/devices/uart/unittest_uart_16550.cc
+++ b/devices/uart/unittest_uart_16550.cc
@@ -7,7 +7,7 @@ using ::testing::Return;
namespace k {
extern "C" {
-#include "../uart.h"
+#include "uart.h"
#include "uart_16550.h"
}
} // namespace k
diff --git a/grub/meson.build b/grub/meson.build
new file mode 100644
index 0000000..917f8d7
--- /dev/null
+++ b/grub/meson.build
@@ -0,0 +1,2 @@
+grub_incl = include_directories('.', is_system: true)
+
diff --git a/i686-elf-gcc.txt b/i686-elf-gcc.txt
new file mode 100644
index 0000000..b5f3bd0
--- /dev/null
+++ b/i686-elf-gcc.txt
@@ -0,0 +1,9 @@
+[binaries]
+c = 'i686-elf-gcc'
+cpp = 'i686-elf-g++'
+ld = 'i686-elf-ld'
+ar = 'i686-elf-ar'
+strip = 'i686-elf-strip'
+
+[built-in options]
+c_args = ['-ffreestanding', '-mgeneral-regs-only']
diff --git a/i686/gdt.h b/i686/include/gdt.h
index 2bdfb22..2bdfb22 100644
--- a/i686/gdt.h
+++ b/i686/include/gdt.h
diff --git a/i686/idt.h b/i686/include/idt.h
index ca39bde..ca39bde 100644
--- a/i686/idt.h
+++ b/i686/include/idt.h
diff --git a/i686/paging.h b/i686/include/paging.h
index f5bfa78..f5bfa78 100644
--- a/i686/paging.h
+++ b/i686/include/paging.h
diff --git a/i686/sys/control.h b/i686/include/sys/control.h
index 89ab067..89ab067 100644
--- a/i686/sys/control.h
+++ b/i686/include/sys/control.h
diff --git a/i686/sys/cpuid.h b/i686/include/sys/cpuid.h
index 6613967..6613967 100644
--- a/i686/sys/cpuid.h
+++ b/i686/include/sys/cpuid.h
diff --git a/i686/sys/io.h b/i686/include/sys/io.h
index 4ff5d85..4ff5d85 100644
--- a/i686/sys/io.h
+++ b/i686/include/sys/io.h
diff --git a/i686/sys/syscall.h b/i686/include/sys/syscall.h
index 9e62c89..9e62c89 100644
--- a/i686/sys/syscall.h
+++ b/i686/include/sys/syscall.h
diff --git a/i686/meson.build b/i686/meson.build
new file mode 100644
index 0000000..21ff729
--- /dev/null
+++ b/i686/meson.build
@@ -0,0 +1,24 @@
+
+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/i686/mk b/i686/mk
deleted file mode 100755
index 312e553..0000000
--- a/i686/mk
+++ /dev/null
@@ -1,16 +0,0 @@
-#!../mach
-
-INCLUDES := -isystem../grub
-${ARCH}_CFLAGS += ${INCLUDES}
-${ARCH}_CXXFLAGS += ${INCLUDES}
-
-TARGETLIB += arch
-arch.SRCS = boot.s init.s \
- gdt.c lgdt.c \
- lidt.c isr.c
-
-HOSTTARGETBIN += test_gdt
-test_gdt.SRCS = test_gdt.cc
-
-TESTS += test_gdt
-
diff --git a/i686/toolchain.mk b/i686/toolchain.mk
deleted file mode 100644
index 460717e..0000000
--- a/i686/toolchain.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-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/lib/blake2/blake2s.h b/lib/blake2/include/blake2s.h
index ede170c..ede170c 100644
--- a/lib/blake2/blake2s.h
+++ b/lib/blake2/include/blake2s.h
diff --git a/lib/blake2/meson.build b/lib/blake2/meson.build
new file mode 100644
index 0000000..dc06f3e
--- /dev/null
+++ b/lib/blake2/meson.build
@@ -0,0 +1,24 @@
+
+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/blake2/test_blake2_kat.h b/lib/blake2/tests/blake2s_kat.h
index aa42ef5..dec250a 100644
--- a/lib/blake2/test_blake2_kat.h
+++ b/lib/blake2/tests/blake2s_kat.h
@@ -1,5 +1,7 @@
#pragma once
+#include <cstdint>
+
static const unsigned KATs_len = 256;
static const uint8_t KAT_secret[32] = { 0xba, 0x80, 0xfb, 0x8f, 0x1b, 0x7b, 0xa1, 0x49, 0x3c, 0x6a, 0xe8, 0x8f, 0xd, 0x66, 0xa1, 0xae, 0xff, 0xa2, 0x5c, 0x8a, 0x7d, 0x4c, 0x1f, 0xb6, 0x81, 0x1, 0xb5, 0xe4, 0xc2, 0x8e, 0x37, 0x3 };
static const uint8_t KATs[256][32] = {
diff --git a/lib/blake2/test_blake2s_selftest.cc b/lib/blake2/tests/blake2s_selftest.cc
index 2c046b2..420544d 100644
--- a/lib/blake2/test_blake2s_selftest.cc
+++ b/lib/blake2/tests/blake2s_selftest.cc
@@ -1,8 +1,11 @@
// Self test Modules for BLAKE2s
-#include "blake2s.c"
-#include "test_blake2_kat.h"
+#include "blake2s_kat.h"
#include <gtest/gtest.h>
+extern "C" {
+#include "blake2s.h"
+}
+
static_assert(sizeof(BLAKE2s_param) == (8 * sizeof(uint32_t)), "sizeof struct BLAKE2s_param");
// Deterministic sequences (Fibonacci generator).
@@ -66,12 +69,6 @@ blake2s_selftest()
return 0;
}
-TEST(blake2s, rotr_u32)
-{
- EXPECT_EQ(rotr_u32(0xdecafade, 16), 0xfadedeca);
- EXPECT_EQ(rotr_u32(0xdecafade, 8), 0xdedecafa);
-}
-
TEST(blake2s, selftest) { EXPECT_EQ(blake2s_selftest(), 0); }
TEST(blake2s, selftestAllInOne)
diff --git a/lib/libk/endian.h b/lib/libk/include/endian.h
index 6aa2669..6aa2669 100644
--- a/lib/libk/endian.h
+++ b/lib/libk/include/endian.h
diff --git a/lib/libk/stdio.h b/lib/libk/include/stdio.h
index 7a6e663..7a6e663 100644
--- a/lib/libk/stdio.h
+++ b/lib/libk/include/stdio.h
diff --git a/lib/libk/stdlib.h b/lib/libk/include/stdlib.h
index 143c931..143c931 100644
--- a/lib/libk/stdlib.h
+++ b/lib/libk/include/stdlib.h
diff --git a/lib/libk/string.h b/lib/libk/include/string.h
index 45b05a5..45b05a5 100644
--- a/lib/libk/string.h
+++ b/lib/libk/include/string.h
diff --git a/lib/libk/meson.build b/lib/libk/meson.build
new file mode 100644
index 0000000..669780b
--- /dev/null
+++ b/lib/libk/meson.build
@@ -0,0 +1,41 @@
+
+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/lib/mk b/lib/mk
deleted file mode 100755
index 06c6006..0000000
--- a/lib/mk
+++ /dev/null
@@ -1,36 +0,0 @@
-#!../mach
-
-# minimal C standard library
-TARGETLIB += libk
-libk.SRCS = \
- libk/endian/little.c \
- libk/stdio/printf.c libk/stdio/fprintf.c libk/stdio/vfprintf.cpp \
- libk/stdlib/memcpy.c libk/stdlib/memset.c libk/stdlib/linked_list_allocator.c \
- libk/string/itoa.c
-
-HOSTTARGETBIN += libk/endian/test_endian_little
-libk/endian/test_endian_little.SRCS = libk/endian/test_endian_little.cc
-
-HOSTTARGETBIN += libk/stdlib/test_linked_list_allocator
-libk/stdlib/test_linked_list_allocator.SRCS = libk/stdlib/test_linked_list_allocator.cc
-
-HOSTTARGETBIN += libk/stdlib/test_mem
-libk/stdlib/test_mem.SRCS = libk/stdlib/test_mem.cc
-
-HOSTTARGETBIN += libk/string/test_string
-libk/string/test_string.SRCS = libk/string/test_string.cc
-
-TESTS += \
- libk/endian/test_endian_little \
- libk/stdlib/test_linked_list_allocator libk/stdlib/test_mem \
- libk/string/test_string
-
-# blake2s hash algorithm
-TARGETLIB += blake2
-blake2.SRCS = blake2/blake2s.c
-
-HOSTTARGETBIN += blake2/test_blake2s_selftest
-blake2/test_blake2s_selftest.SRCS = blake2/test_blake2s_selftest.cc
-
-TESTS += blake2/test_blake2s_selftest
-
diff --git a/mach b/mach
deleted file mode 100755
index fbc10d7..0000000
--- a/mach
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-# =====================================================================
-# filename: mach
-# description: make wrapper used to run mk files
-# To use, add the relative path to this script as a
-# shebang in mk and make it executable.
-# spdx-license-identifier: ISC
-# =====================================================================
-
-if [[ $1 != "./mk" ]]
-then
- echo "Usage: $0 ./mk; argument passed: $1"
- exit 1
-fi
-
-# remove ./mk from args
-ARGS=${@:2}
-
-# root.mk should be next to this script
-ROOT=`dirname $0`
-
-make --silent -f ${ROOT}/root.mk -C ${PWD} ${ARGS}
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..b5c6763
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,39 @@
+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
new file mode 100644
index 0000000..f159eb4
--- /dev/null
+++ b/meson/compiler_flags/meson.build
@@ -0,0 +1,34 @@
+# 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/mk b/mk
deleted file mode 100755
index f4de64b..0000000
--- a/mk
+++ /dev/null
@@ -1,57 +0,0 @@
-#!./mach
-
-SUBDIRS := lib ${ARCH} devices src
-
-${ARCH}_LDFLAGS += -T ${ROOTDIR}${ARCH}/linker.ld
-
-TARGETBIN += glitch
-glitch.OBJS += ${ARCH}/arch.a src/kernel.a devices/devs.a lib/libk.a
-
-lib/libk.a:
- @${MAKE} -C lib -f ../root.mk libk.a
-i686/arch.a:
- @${MAKE} -C ${ARCH} -f ../root.mk arch.a
-devices/devs.a:
- @${MAKE} -C devices -f ../root.mk devs.a
-src/kernel.a:
- @${MAKE} -C src -f ../root.mk kernel.a
-kconfig:
- @${MAKE} -C tools/kconfig -f ../../root.mk
-
-run: glitch.iso
- qemu-system-i386 -accel kvm -machine pc -cdrom $^ -d cpu_reset -display gtk,zoom-to-fit=on
-
-# configure targets
-.config: Kconfig
- @alldefconfig
-
-config.mk: .config ${ARCH}/toolchain.mk
- @cat .config > $@
- @echo -e '\n## toolchain.mk' >> $@
- @cat ${ARCH}/toolchain.mk >> $@
-
-# iso image
-glitch.iso: glitch.elf grub/grub.cfg
- @grub-file --is-x86-multiboot2 glitch.elf
- @mkdir -p isodir/boot/grub
- @mkdir -p isodir/boot/glitch
- @grub-script-check grub/grub.cfg
- @cp grub/grub.cfg isodir/boot/grub/grub.cfg
- @cp glitch.elf isodir/boot/glitch/glitch.elf
- @i686-elf-strip isodir/boot/glitch/glitch.elf
- @rm -f isodir/boot/glitch/checksums
- @sha512sum isodir/boot/glitch/* > isodir/boot/glitch/checksums
- @sed -i s/isodir// isodir/boot/glitch/checksums
- @grub-mkrescue -o glitch.iso isodir
-
-clean: clean_subdirs
-clean_subdirs:
- @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk clean; done
-
-test: test_subdirs
-test_subdirs:
- @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk test.quiet; done
-
-valgrind: valgrind_subdirs
-valgrind_subdirs:
- @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk valgrind.quiet; done
diff --git a/root.mk b/root.mk
deleted file mode 100644
index 87ac276..0000000
--- a/root.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-# glitch root makefile
-# usage: make -C <part> -f <path to root.mk> <target(s)>
-
-# location of root makefile
-ROOTDIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))
-# include config and toolchain
-include $(join ${ROOTDIR},config.mk)
-
-help:
- @echo "info: show current configuration"
- @echo "all: build kernel image"
- @echo "run: run kernel image in qemu"
- @echo "test: run all tests"
- @echo "valgrind: run all tests in valgrind"
-
-info:
- @echo "- target:"
- @echo " ARCH: ${ARCH}"
- @echo " CC: ${${ARCH}_CC}"
- @echo " CCID: ${${ARCH}_CCID}"
- @echo " CFLAGS: ${${ARCH}_CFLAGS}"
- @echo " LD: ${${ARCH}_LD}"
- @echo " LDID: ${${ARCH}_LDID}"
- @echo " LDFLAGS: ${${ARCH}_LDFLAGS}"
- @echo "- host:"
- @echo " CC: ${HOST_CC}"
- @echo " CFLAGS: ${HOST_CFLAGS}"
- @echo " CXX: ${HOST_CXX}"
- @echo " CXXFLAGS: ${HOST_CXXFLAGS}"
- @echo " QEMU: ${QEMU}"
-
-# for auto-completion purposes
-list-targets:
-
-# include build from current dir
-include mk
-
-SUBDIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))
-COMPONENT := $(lastword $(subst /, ,${SUBDIR}))
-
-# generate build rules
-include $(join ${ROOTDIR},rules.mk)
-
diff --git a/rules.mk b/rules.mk
deleted file mode 100644
index ed72b27..0000000
--- a/rules.mk
+++ /dev/null
@@ -1,146 +0,0 @@
-# variables
-VCS_ROOT = $(shell git rev-parse --show-toplevel)
-CWD = $(shell pwd)
-
-# generate build rules from variables
-# This makefile defines the following targets:
-# - all: default goal, build all default targets
-
-# generate objects from sources
-# arg 1: target.SRCS
-# arg 2: object suffix prefix
-# returns: target.OBJS
-objects = $(foreach f,$($1),$(addprefix build/,$(addsuffix $2.o,$(basename $f))))
-
-# generate depends from .S .c .cpp sources
-# arg 1: target.SRCS
-# arg 2: dependency suffix prefix
-# returns: target.DEPS
-depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addprefix build/,$(addsuffix $2.d,$(basename $f))))
-
-# default target
-.DEFAULT_GOAL := all
-
-
-# TARGETBIN: binaries using the target architecture
-$(foreach T,${TARGETBIN},\
- $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \
- $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \
- $(eval -include $($T.DEPS) ) \
- $(eval $T.elf: ${$T.OBJS} ) \
- $(eval DEFAULT_TARGETS += $T.elf) \
-)
-
-# TARGETLIB: static libraries using the target architecture
-$(foreach T,${TARGETLIB},\
- $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \
- $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \
- $(eval -include $($T.DEPS) ) \
- $(eval $T.a: ${$T.OBJS} ) \
- $(eval DEFAULT_TARGETS += $T.a) \
-)
-
-# HOSTTARGETBIN: binaries using the host compiler
-$(foreach T,${HOSTTARGETBIN},\
- $(eval $T.OBJS += $(call objects,$T.SRCS,) ) \
- $(eval $T.DEPS += $(call depends,$T.SRCS,) ) \
- $(eval -include $($T.DEPS) ) \
- $(eval $T: ${$T.OBJS}; @echo ' HOST LD $T'; ${HOST_CXX} ${HOST_LDFLAGS} -o $T ${$T.OBJS} ) \
- $(eval DEFAULT_TARGETS += $T) \
-)
-
-list-targets:
- @echo TARGETBIN
- @echo ${TARGETBIN} | tr ' ' '\n' | xargs -n1 echo " "
- @echo TARGETLIB
- @echo ${TARGETLIB} | tr ' ' '\n' | xargs -n1 echo " "
- @echo HOSTTARGETBIN
- @echo ${HOSTTARGETBIN} | tr ' ' '\n' | xargs -n1 echo " "
- @echo HOSTTARGETLIB
- @echo ${HOSTTARGETLIB} | tr ' ' '\n' | xargs -n1 echo " "
- @echo DEFAULT_TARGETS
- @echo ${DEFAULT_TARGETS} | tr ' ' '\n' | xargs -n1 echo " "
- @echo TESTS
- @echo ${TESTS} | tr ' ' '\n' | xargs -n1 echo " "
-
-%.info:
- @echo "Target: $(basename $@)"
- @echo " ARCH: ${ARCH}"
- @echo " SRCS: ${$(basename $@).SRCS}"
- @echo " OBJS: ${$(basename $@).OBJS}"
- @echo " DEPS: ${$(basename $@).DEPS}"
- @echo " LD ${${ARCH}_LDFLAGS}"
-
-all: ${DEFAULT_TARGETS}
- @echo " -> Built all in ${COMPONENT}"
-
-# extra flags
-${ARCH}_CFLAGS += -I${VCS_ROOT}/lib/libk \
- -Werror=implicit-function-declaration
-${ARCH}_CXXFLAGS += -I${VCS_ROOT}/lib/libk -Drestrict=__restrict__
-
-# Target suffix rules
-# -MD output makefile dependency rule
-# -MT target change the target of the rule
-# -MF file write the dependencies to file
-%.a:
- @echo ' AR $@'
- @${${ARCH}_AR} ${${ARCH}_ARFLAGS} $@ $(filter %.o,$^)
-
-build/%_${ARCH}.o: %.s
- @echo ' AS $<'
- @mkdir -p $(dir $@)
- @${${ARCH}_AS} ${${ARCH}_ASFLAGS} -c -o $@ $<
-
-build/%_${ARCH}.o: %.S
- @echo ' CC $<'
- @mkdir -p $(dir $@)
- @${${ARCH}_CC} ${${ARCH}_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $<
-
-build/%_${ARCH}.o: %.c
- @echo ' CC $<'
- @mkdir -p $(dir $@)
- @${${ARCH}_CC} ${${ARCH}_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $<
-
-%.elf:
- @echo ' LD $@'
- @${${ARCH}_LD} ${${ARCH}_LDFLAGS} -o $@ $^
- @echo -n ' B2b '
- @b2sum $@ | cut -d' ' -f1
-
-# Host suffix rules
-build/%.o: %.c
- @echo ' HOST CC $<'
- @mkdir -p $(dir $@)
- @${HOST_CC} ${HOST_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $<
-
-build/%.o: %.cc
- @echo ' HOST CXX $<'
- @mkdir -p $(dir $@)
- @${HOST_CXX} ${HOST_CXXFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $<
-
-.PHONY: test test.quiet valgrind valgrind.quiet clean.base FORCE
-test: ${TESTS}
- @echo " -> Running tests in $(CWD:${VCS_ROOT}/%=%)"
- @[[ -z "${TESTS}" ]] || ${VCS_ROOT}/scripts/test_runner.py --verbose ${TESTS}
-
-test.quiet: ${TESTS}
- @echo " -> Running tests in $(CWD:${VCS_ROOT}/%=%)"
- @[[ -z "${TESTS}" ]] || ${VCS_ROOT}/scripts/test_runner.py ${TESTS}
-
-valgrind: ${TESTS}
- @echo " -> Running valgrind on tests in $(CWD:${VCS_ROOT}/%=%)"
- @[[ -z "${TESTS}" ]] || ${VCS_ROOT}/scripts/test_runner.py --verbose --valgrind ${TESTS}
-
-valgrind.quiet: ${TESTS}
- @echo " -> Running valgrind on tests in $(CWD:${VCS_ROOT}/%=%)"
- @[[ -z "${TESTS}" ]] || ${VCS_ROOT}/scripts/test_runner.py --valgrind ${TESTS}
-
-clean: FORCE
- @echo " -> Cleaning $(shell pwd | xargs basename)"
- @$(foreach V,$(filter %.OBJS, ${.VARIABLES}), rm -rf $($(V)))
- @$(foreach V,$(filter %.DEPS, ${.VARIABLES}), rm -rf $($(V)))
- @rm -rf *.a ${CLEAN_FILES}
- @rm -rf ${TESTS}
-
-FORCE: ;
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..128a7b5
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,25 @@
+
+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/src/mk b/src/mk
deleted file mode 100755
index 84a735f..0000000
--- a/src/mk
+++ /dev/null
@@ -1,25 +0,0 @@
-#!../mach
-
-INCLUDES := -isystem${ROOTDIR}grub -I${ROOTDIR}${ARCH} -I${ROOTDIR}devices
-${ARCH}_CFLAGS += ${INCLUDES}
-${ARCH}_CXXFLAGS += ${INCLUDES}
-
-TARGETLIB += kernel
-kernel.SRCS := multiboot2.c mmap.c kernel.cpp mem/vmm.c
-
-HOSTTARGETBIN += sched/test_taskqueue
-sched/test_taskqueue.SRCS = sched/test_taskqueue.cc
-
-HOSTTARGETBIN += sched/test_roundrobin
-sched/test_roundrobin.SRCS = sched/test_roundrobin.cc
-
-TESTS += \
- sched/test_taskqueue sched/test_roundrobin
-
-kernel.c: conf.h
-conf.h: conf.h.in
- @echo ' GEN $@'
- @cp conf.h.in conf.h
- @sed -i 's/@VERSION@/$(shell git describe)/' conf.h
- @sed -i 's/@CC@/${${ARCH}_CCID}/' conf.h
-
diff --git a/tools/make_iso.py b/tools/make_iso.py
new file mode 100755
index 0000000..7cb4506
--- /dev/null
+++ b/tools/make_iso.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+from subprocess import run
+import argparse
+import os
+import shutil
+import hashlib
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('-k', '--kernel', required=True, help='path to kernel binary')
+ parser.add_argument('-c', '--config', required=True, help='path to bootloader config')
+ parser.add_argument('-o', '--output', required=True, help='path for output image')
+
+ parser.add_argument('--prefix-dir', default='isodir', help='prefix dir')
+ parser.add_argument('--boot-dir', default='boot/grub', help='bootloader dir')
+ parser.add_argument('--kernel-dir', default='boot/glitch', help='kernel dir')
+
+ # grub tools
+ parser.add_argument('--grub-file', default='grub-file',
+ help='grub-file executable')
+ parser.add_argument('--grub-script-check', default='grub-script-check',
+ help='grub-script-check executable')
+ parser.add_argument('--grub-mkrescue', default='grub-mkrescue',
+ help='grub-mkrescue executable')
+ # other tools
+ parser.add_argument('--strip', default='i686-elf-strip',
+ help='strip executable')
+
+ args = parser.parse_args()
+ args.boot_dir = f'{args.prefix_dir}/{args.boot_dir}'
+ args.kernel_dir = f'{args.prefix_dir}/{args.kernel_dir}'
+
+ # check inputs
+ run([ args.grub_file, '--is-x86-multiboot2', args.kernel ], check=True)
+ run([ args.grub_script_check, args.config ], check=True)
+
+ # create directory structure and copy files
+ os.makedirs(args.boot_dir, exist_ok=True)
+ os.makedirs(args.kernel_dir, exist_ok=True)
+ shutil.copyfile(args.config, f'{args.boot_dir}/grub.cfg')
+ shutil.copyfile(args.kernel, f'{args.kernel_dir}/glitch.elf')
+
+ # strip and hash binary
+ run([ args.strip, f'{args.kernel_dir}/glitch.elf' ], check=True)
+ with open(f'{args.kernel_dir}/checksums', 'w') as checksums:
+ with open(f'{args.kernel_dir}/glitch.elf', 'rb') as f:
+ digest = hashlib.file_digest(f, 'sha512').hexdigest()
+ path = f'{args.kernel_dir}/{args.kernel}'.removeprefix(args.prefix_dir)
+ print(f'{digest} {path}', file=checksums)
+
+ # create iso image
+ run([ args.grub_mkrescue, '-o', args.output, args.prefix_dir ], check=True)
+
+ # cleanup
+ #shutil.rmtree(args.prefix_dir)
+