From 643d3ed251a93007d3638a403ee65452c82c4669 Mon Sep 17 00:00:00 2001 From: fef Date: Sat, 31 Jul 2021 19:39:51 +0200 Subject: [PATCH] build: migrate to CMake --- .gitignore | 7 +- .vscode/c_cpp_properties.json | 4 +- CMakeLists.txt | 96 +++++++++++++++++++ Makefile | 95 ------------------ README.md | 22 ++--- init/Makefile => arch/CMakeLists.txt | 13 +-- arch/Makefile | 18 ---- arch/at91sam3x8e/CMakeLists.txt | 33 +++++++ arch/at91sam3x8e/Makefile | 37 ------- arch/at91sam3x8e/entry.c | 2 +- .../at91sam3x8e/include/arch}/hardware.h | 0 .../at91sam3x8e/include/arch}/interrupt.h | 0 .../at91sam3x8e/include/arch}/serial.h | 1 + arch/at91sam3x8e/interrupt.c | 4 +- arch/at91sam3x8e/sched.c | 6 +- arch/at91sam3x8e/serial.c | 6 +- arch/at91sam3x8e/startup.c | 5 +- arch/at91sam3x8e/sys.c | 3 +- arch/at91sam3x8e/toolchain.cmake | 38 ++++++++ arch/at91sam3x8e/watchdog.c | 4 +- include/{arch => arch-generic}/entry.h | 0 include/{arch => arch-generic}/hardware.h | 9 -- include/{arch => arch-generic}/sched.h | 1 - include/{arch => arch-generic}/serial.h | 4 +- include/{arch => arch-generic}/syscall.h | 0 include/{arch => arch-generic}/watchdog.h | 0 include/ardix/syscall.h | 2 +- include/ardix/types.h | 1 + include/{arch/arch_include.h => config.h.in} | 15 ++- lib/Makefile => init/CMakeLists.txt | 26 ++--- kernel/CMakeLists.txt | 31 ++++++ kernel/Makefile | 28 ------ kernel/fs/CMakeLists.txt | 23 +++++ kernel/{io => }/io.c | 0 kernel/io/Makefile | 17 ---- kernel/sched.c | 4 +- lib/CMakeLists.txt | 27 ++++++ kernel/fs/Makefile => options.cmake | 15 ++- 38 files changed, 318 insertions(+), 279 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile rename init/Makefile => arch/CMakeLists.txt (74%) delete mode 100644 arch/Makefile create mode 100644 arch/at91sam3x8e/CMakeLists.txt delete mode 100644 arch/at91sam3x8e/Makefile rename {include/arch/at91sam3x8e => arch/at91sam3x8e/include/arch}/hardware.h (100%) rename {include/arch/at91sam3x8e => arch/at91sam3x8e/include/arch}/interrupt.h (100%) rename {include/arch/at91sam3x8e => arch/at91sam3x8e/include/arch}/serial.h (97%) create mode 100644 arch/at91sam3x8e/toolchain.cmake rename include/{arch => arch-generic}/entry.h (100%) rename include/{arch => arch-generic}/hardware.h (90%) rename include/{arch => arch-generic}/sched.h (98%) rename include/{arch => arch-generic}/serial.h (96%) rename include/{arch => arch-generic}/syscall.h (100%) rename include/{arch => arch-generic}/watchdog.h (100%) rename include/{arch/arch_include.h => config.h.in} (61%) rename lib/Makefile => init/CMakeLists.txt (50%) create mode 100644 kernel/CMakeLists.txt delete mode 100644 kernel/Makefile create mode 100644 kernel/fs/CMakeLists.txt rename kernel/{io => }/io.c (100%) delete mode 100644 kernel/io/Makefile create mode 100644 lib/CMakeLists.txt rename kernel/fs/Makefile => options.cmake (61%) diff --git a/.gitignore b/.gitignore index 27a127c..85da293 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,4 @@ -*.gch -*.o -*.elf -*.bin -*.hex -/.config +build/ # vim [._]*.s[a-v][a-z] diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index ee75c78..4d31de2 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -12,7 +12,9 @@ "cppStandard": "gnu++14", "intelliSenseMode": "gcc-arm", "includePath": [ - "./include" + "./include", + "./build/include", + "./arch/at91sam3x8e/include" ], "compilerArgs": [ "-mcpu=cortex-m3", diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5bf5417 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,96 @@ +# See the end of this file for copyright and license terms. + +cmake_minimum_required(VERSION 3.14.0) + +set(ARCH "at91sam3x8e" CACHE STRING "Target architecture") +include(arch/${ARCH}/toolchain.cmake) + +project(ardix VERSION 0.1.0 LANGUAGES C ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_EXTENSIONS ON) + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + option(DEBUG "Enable debug features" ON) +endif() + +include(options.cmake) + +find_package(Git QUIET) +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE ardix_GIT_REVISION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if (NOT "${ardix_GIT_REVISION}" STREQUAL "") + set(ardix_VERSION_SUFFIX "-${ardix_GIT_REVISION}") + endif() +endif() + +add_library(ardix INTERFACE) +set(ARDIX_INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/arch/${ARCH}/include + ${CMAKE_CURRENT_BINARY_DIR}/include +) +set(ARDIX_COMPILE_OPTIONS + -nodefaultlibs + -nostartfiles + -fno-builtin + -Wall + -Wno-sign-conversion + -Wstrict-prototypes + -Wredundant-decls + -Wnested-externs + -Wbad-function-cast + -Wshadow + -Wsign-compare + -Wunreachable-code + -Wwrite-strings + -Wconversion + -Waggregate-return + -Winline + -Wcast-align +) + +configure_file( + ${CMAKE_SOURCE_DIR}/include/config.h.in + ${CMAKE_BINARY_DIR}/include/config.h +) + +# this must be included before any other subdirectories because +# it updates ARDIX_INCLUDE_DIRS and ARDIX_COMPILE_OPTIONS +add_subdirectory(arch) + +add_subdirectory(init) +add_subdirectory(kernel) +add_subdirectory(lib) + +target_include_directories(ardix INTERFACE ${ARDIX_INCLUDE_DIRS}) +target_compile_options(ardix INTERFACE ${ARDIX_COMPILE_OPTIONS}) + +# TODO: don't use this hack lmao +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/empty.c "") +add_executable(ardix.elf ${CMAKE_CURRENT_BINARY_DIR}/empty.c) +target_link_libraries(ardix.elf PRIVATE ardix) + +add_custom_target(ardix.bin ALL DEPENDS ardix.elf) +add_custom_command( + TARGET ardix.bin + COMMAND ${CMAKE_OBJCOPY} + ARGS -O binary -R .eeprom ardix.elf ardix.bin +) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/Makefile b/Makefile deleted file mode 100644 index 7da4127..0000000 --- a/Makefile +++ /dev/null @@ -1,95 +0,0 @@ -# -# This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . -# -# Ardix is non-violent software: you may only use, redistribute, -# and/or modify it under the terms of the CNPLv6+ as found in -# the LICENSE file in the source code root directory or at -# . -# -# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent -# permitted by applicable law. See the CNPLv6+ for details. -# - -AVR_CC ?= $(shell which avr-gcc) -AVR_OBJCOPY ?= $(shell which avr-objcopy) -AVR_LD ?= $(shell which avr-ld) - -ARM_CC ?= $(shell which arm-none-eabi-gcc) -ARM_LD ?= $(shell which arm-none-eabi-ld) -ARM_OBJCOPY ?= $(shell which arm-none-eabi-objcopy) - -EXTRA_CFLAGS ?= -CFLAGS = $(EXTRA_CFLAGS) - -CFLAGS += -g -nodefaultlibs -nostartfiles -CFLAGS += -I$(PWD)/include -CFLAGS += -DARCH=$(ARCH) -CFLAGS += -fno-builtin -std=gnu11 - -EXTRA_LDFLAGS ?= -LDFLAGS = $(EXTRA_LDFLAGS) - -ifeq ($(ARCH), at91sam3x8e) - CFLAGS += -mcpu=cortex-m3 -mthumb -mabi=aapcs -march=armv7-m -masm-syntax-unified - CC = $(ARM_CC) - LD = $(ARM_LD) - OBJCOPY = $(ARM_OBJCOPY) -else - CFLAGS += -mmcu=$(ARCH) - LDFLAGS += -mmcu=$(ARCH) - CC = $(AVR_CC) - LD = $(AVR_LD) - OBJCOPY = $(AVR_OBJCOPY) -endif - -CFLAGS += -Wall \ - -Wno-sign-conversion \ - -Wstrict-prototypes \ - -Wredundant-decls \ - -Wnested-externs \ - -Wbad-function-cast \ - -Wshadow \ - -Wsign-compare \ - -Wunreachable-code \ - -Wwrite-strings \ - -Wconversion \ - -Waggregate-return \ - -Winline \ - -Wcast-align - -ifdef DEBUG - CFLAGS += -DDEBUG -endif - -ARDIX_ASM_SOURCES = -ARDIX_SOURCES = - -include arch/Makefile - -include init/Makefile -include lib/Makefile -include kernel/Makefile - -ARDIX_OBJS = $(ARDIX_SOURCES:.c=.o) -ARDIX_ASM_OBJS = $(ARDIX_ASM_SOURCES:.S=.o) - -%.o: %.S | %.c - $(CC) -c -Os $(CFLAGS) $< - -ardix.elf: $(ARDIX_ASM_OBJS) $(ARDIX_OBJS) - $(LD) $(LDFLAGS) -o $@ $^ - -ardix.hex: ardix.elf - $(OBJCOPY) -O ihex -R .eeprom $^ $@ - -ardix.bin: ardix.elf - $(OBJCOPY) -O binary -R .eeprom $^ $@ - -clean: - rm -f ardix.elf ardix.hex ardix.bin $(ARDIX_OBJS) $(ARDIX_ASM_OBJS) - -config: - ./configure - -all: ardix.hex ardix.bin diff --git a/README.md b/README.md index 4bcec26..72fb972 100644 --- a/README.md +++ b/README.md @@ -24,24 +24,21 @@ permitted by applicable law. See the CNPLv6+ for details. * `arm-gcc` * `arm-ld` * `arm-objcopy` -- GNU `make` +- CMake >= 3.14 - A programmer (`bossac` recommended) - A Unix-like shell (sorry Microsoft lackeys, you can use the Windows Subsystem for Linux for compiling but probably not for flashing) ### Configuration -Right now, you have to manually define environment variables: +Configuration is done with the standard CMake config system. +The following options are available: -- `ARM_CC`: Full path to `arm-none-eabi-gcc`. If unset, we will search for it in your PATH. -- `ARM_LD`: Full path to `arm-none-eabi-ld`. If unset, we will search for it in your PATH. -- `ARM_OBJCOPY`: Full path to `arm-none-eabi-objcopy`. - If unset, we will search for it in your PATH. -- `ARCH`: Codename for the target architecture. This is mandatory. +- `TOOLCHAIN_PATH`: Path where the compiler toolchain is located. + Defaults to `/usr/bin`. +- `ARCH`: Codename for the target architecture. The following architectures are currently supported: * `at91sam3x8e` (Arduino Due) -- `EXTRA_CFLAGS`: Any additional arguments that should be passed to the compiler. -- `EXTRA_LDFLAGS`: Any additional arguments that should be passed to the linker. ### Build @@ -49,17 +46,18 @@ To build the EEPROM image, execute the following command: ```shell # Replace with one of the target architectures from the list above -ARCH='' make ardix.bin +cmake -DARCH= -B build -S . +cmake --build build ``` -This will create the `ardix.bin` file, which can be passed to `bossac` for flashing. +This will create `ardix.bin` in the `build` directory, which can be passed to `bossac` for flashing. If you are using an Arduino DUE (at91sam3x8e), make sure to connect the USB cable to the programmer port (the one closer to the power jack). ```shell # Replace with the name of the tty device in /dev # that is connected to your Arduino -bossac -e -w -v -b -a --port= ardix.bin +bossac -e -w -v -b -a --port= build/ardix.bin ``` Please refer to `bossac --help` for more information on how to use it. diff --git a/init/Makefile b/arch/CMakeLists.txt similarity index 74% rename from init/Makefile rename to arch/CMakeLists.txt index e866ce4..ed0b6cc 100644 --- a/init/Makefile +++ b/arch/CMakeLists.txt @@ -1,6 +1,9 @@ -# +# See the end of this file for copyright and license terms. + +add_subdirectory(${ARCH}) + # This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . +# Copyright (c) 2021 Felix Kopp . # # Ardix is non-violent software: you may only use, redistribute, # and/or modify it under the terms of the CNPLv6+ as found in @@ -9,9 +12,3 @@ # # Ardix comes with ABSOLUTELY NO WARRANTY, to the extent # permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_INIT_PWD := $(PWD)/init - -ARDIX_SOURCES += \ - $(ARDIX_INIT_PWD)/main.c diff --git a/arch/Makefile b/arch/Makefile deleted file mode 100644 index 9b26489..0000000 --- a/arch/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# -# This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . -# -# Ardix is non-violent software: you may only use, redistribute, -# and/or modify it under the terms of the CNPLv6+ as found in -# the LICENSE file in the source code root directory or at -# . -# -# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent -# permitted by applicable law. See the CNPLv6+ for details. -# - -ifeq ($(ARCH), at91sam3x8e) - include arch/at91sam3x8e/Makefile -else - $(error ARCH is not set to a supported value) -endif diff --git a/arch/at91sam3x8e/CMakeLists.txt b/arch/at91sam3x8e/CMakeLists.txt new file mode 100644 index 0000000..519645d --- /dev/null +++ b/arch/at91sam3x8e/CMakeLists.txt @@ -0,0 +1,33 @@ +# See the end of this file for copyright and license terms. + +add_library(ardix_arch STATIC) +target_link_libraries(ardix INTERFACE ardix_arch) + +target_compile_options(ardix_arch PRIVATE ${ARDIX_COMPILE_OPTIONS}) +target_include_directories(ardix_arch PRIVATE ${ARDIX_INCLUDE_DIRS}) + +target_sources(ardix_arch PRIVATE + atom.c + atomic.c + entry.c + interrupt.c + irq_pend_sv.S + irq_svc.S + sched.c + serial.c + startup.c + sys.c + syscall.S + watchdog.c +) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/arch/at91sam3x8e/Makefile b/arch/at91sam3x8e/Makefile deleted file mode 100644 index 8ca3bba..0000000 --- a/arch/at91sam3x8e/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# -# This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . -# -# Ardix is non-violent software: you may only use, redistribute, -# and/or modify it under the terms of the CNPLv6+ as found in -# the LICENSE file in the source code root directory or at -# . -# -# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent -# permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_ARCH_PWD = $(PWD)/arch/at91sam3x8e - -ARDIX_SOURCES += \ - $(ARDIX_ARCH_PWD)/atom.c \ - $(ARDIX_ARCH_PWD)/atomic.c \ - $(ARDIX_ARCH_PWD)/entry.c \ - $(ARDIX_ARCH_PWD)/interrupt.c \ - $(ARDIX_ARCH_PWD)/sched.c \ - $(ARDIX_ARCH_PWD)/serial.c \ - $(ARDIX_ARCH_PWD)/startup.c \ - $(ARDIX_ARCH_PWD)/sys.c \ - $(ARDIX_ARCH_PWD)/watchdog.c - -ARDIX_ASM_SOURCES += \ - $(ARDIX_ARCH_PWD)/irq_pend_sv.S \ - $(ARDIX_ARCH_PWD)/irq_svc.S \ - $(ARDIX_ARCH_PWD)/syscall.S - -CFLAGS += \ - -DARCH_AT91SAM3X8E - -LDFLAGS += \ - -T$(ARDIX_ARCH_PWD)/config.ld \ - -T$(ARDIX_ARCH_PWD)/flash.ld diff --git a/arch/at91sam3x8e/entry.c b/arch/at91sam3x8e/entry.c index f33687b..fea7513 100644 --- a/arch/at91sam3x8e/entry.c +++ b/arch/at91sam3x8e/entry.c @@ -1,6 +1,6 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include +#include #include #include diff --git a/include/arch/at91sam3x8e/hardware.h b/arch/at91sam3x8e/include/arch/hardware.h similarity index 100% rename from include/arch/at91sam3x8e/hardware.h rename to arch/at91sam3x8e/include/arch/hardware.h diff --git a/include/arch/at91sam3x8e/interrupt.h b/arch/at91sam3x8e/include/arch/interrupt.h similarity index 100% rename from include/arch/at91sam3x8e/interrupt.h rename to arch/at91sam3x8e/include/arch/interrupt.h diff --git a/include/arch/at91sam3x8e/serial.h b/arch/at91sam3x8e/include/arch/serial.h similarity index 97% rename from include/arch/at91sam3x8e/serial.h rename to arch/at91sam3x8e/include/arch/serial.h index 29fd811..3a64974 100644 --- a/include/arch/at91sam3x8e/serial.h +++ b/arch/at91sam3x8e/include/arch/serial.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include #include diff --git a/arch/at91sam3x8e/interrupt.c b/arch/at91sam3x8e/interrupt.c index 65c21a8..f2e9917 100644 --- a/arch/at91sam3x8e/interrupt.c +++ b/arch/at91sam3x8e/interrupt.c @@ -1,7 +1,7 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include -#include +#include +#include void arch_irq_enable(enum irqno irqno) { diff --git a/arch/at91sam3x8e/sched.c b/arch/at91sam3x8e/sched.c index 9efb764..60947bb 100644 --- a/arch/at91sam3x8e/sched.c +++ b/arch/at91sam3x8e/sched.c @@ -1,8 +1,8 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include -#include -#include +#include +#include +#include #include #include diff --git a/arch/at91sam3x8e/serial.c b/arch/at91sam3x8e/serial.c index b20c1c9..ca14e9f 100644 --- a/arch/at91sam3x8e/serial.c +++ b/arch/at91sam3x8e/serial.c @@ -8,9 +8,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/arch/at91sam3x8e/startup.c b/arch/at91sam3x8e/startup.c index 686f36e..da443c0 100644 --- a/arch/at91sam3x8e/startup.c +++ b/arch/at91sam3x8e/startup.c @@ -1,7 +1,8 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include -#include +#include +#include +#include #include diff --git a/arch/at91sam3x8e/sys.c b/arch/at91sam3x8e/sys.c index 643d44d..47e53a1 100644 --- a/arch/at91sam3x8e/sys.c +++ b/arch/at91sam3x8e/sys.c @@ -1,7 +1,8 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include +#include #include +#include #include #include diff --git a/arch/at91sam3x8e/toolchain.cmake b/arch/at91sam3x8e/toolchain.cmake new file mode 100644 index 0000000..3fd9dfe --- /dev/null +++ b/arch/at91sam3x8e/toolchain.cmake @@ -0,0 +1,38 @@ +# See the end of this file for copyright and license terms. + +set(TOOLCHAIN_PATH "/usr/bin" CACHE STRING "Directory in which the toolchain binaries are located") + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_CROSSCOMPILING 1) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_AR ${TOOLCHAIN_PATH}/arm-none-eabi-ar${CMAKE_EXECUTABLE_SUFFIX}) +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/arm-none-eabi-gcc${CMAKE_EXECUTABLE_SUFFIX}) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/arm-none-eabi-gcc${CMAKE_EXECUTABLE_SUFFIX}) +set(CMAKE_LINKER ${TOOLCHAIN_PATH}/arm-none-eabi-ld${CMAKE_EXECUTABLE_SUFFIX}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH}/arm-none-eabi-objcopy${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_RANLIB ${TOOLCHAIN_PATH}/arm-none-eabi-ranlib${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_SZE ${TOOLCHAIN_PATH}/arm-none-eabi-size${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_STRIP ${TOOLCHAIN_PATH}/arm-none-eabi-strip${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") + +set(CMAKE_C_FLAGS "-Os -nodefaultlibs -nostartfiles -mcpu=cortex-m3 -mthumb -mabi=aapcs -march=armv7-m -masm-syntax-unified") +set(CMAKE_C_FLAGS_DEBUG -g) + +set(CMAKE_EXE_LINKER_FLAGS "-T${CMAKE_CURRENT_LIST_DIR}/config.ld -T${CMAKE_CURRENT_LIST_DIR}/flash.ld") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/arch/at91sam3x8e/watchdog.c b/arch/at91sam3x8e/watchdog.c index 32604d9..03dfea8 100644 --- a/arch/at91sam3x8e/watchdog.c +++ b/arch/at91sam3x8e/watchdog.c @@ -1,7 +1,7 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include -#include +#include +#include int arch_watchdog_init(void) { diff --git a/include/arch/entry.h b/include/arch-generic/entry.h similarity index 100% rename from include/arch/entry.h rename to include/arch-generic/entry.h diff --git a/include/arch/hardware.h b/include/arch-generic/hardware.h similarity index 90% rename from include/arch/hardware.h rename to include/arch-generic/hardware.h index d58abd9..940803d 100644 --- a/include/arch/hardware.h +++ b/include/arch-generic/hardware.h @@ -2,8 +2,6 @@ #pragma once -#include - /** * Block the CPU by continuously checking the same expression in an * infinite loop, until the condition is true. Useful for polling. @@ -30,13 +28,6 @@ */ void sys_init(void); -#ifndef STACK_SIZE -/** stack size per process in bytes */ -#define STACK_SIZE 2048U -#endif - -#include ARCH_INCLUDE(hardware.h) - /* * This file is part of Ardix. * Copyright (c) 2020, 2021 Felix Kopp . diff --git a/include/arch/sched.h b/include/arch-generic/sched.h similarity index 98% rename from include/arch/sched.h rename to include/arch-generic/sched.h index f0f664d..e4ad01d 100644 --- a/include/arch/sched.h +++ b/include/arch-generic/sched.h @@ -4,7 +4,6 @@ #include -#include #include struct process; /* see include/ardix/sched.h */ diff --git a/include/arch/serial.h b/include/arch-generic/serial.h similarity index 96% rename from include/arch/serial.h rename to include/arch-generic/serial.h index 4621a5a..de5b7ed 100644 --- a/include/arch/serial.h +++ b/include/arch-generic/serial.h @@ -2,8 +2,6 @@ #pragma once -#include - #include #include @@ -33,7 +31,7 @@ ssize_t arch_serial_write(struct serial_device *dev, const void *buf, size_t len */ ssize_t serial_write_dma(struct serial_device *dev, struct dmabuf *buf); -#include ARCH_INCLUDE(serial.h) +#include /* * This file is part of Ardix. diff --git a/include/arch/syscall.h b/include/arch-generic/syscall.h similarity index 100% rename from include/arch/syscall.h rename to include/arch-generic/syscall.h diff --git a/include/arch/watchdog.h b/include/arch-generic/watchdog.h similarity index 100% rename from include/arch/watchdog.h rename to include/arch-generic/watchdog.h diff --git a/include/ardix/syscall.h b/include/ardix/syscall.h index f25dbb6..4d8640c 100644 --- a/include/ardix/syscall.h +++ b/include/ardix/syscall.h @@ -2,7 +2,7 @@ #pragma once -#include +#include #include diff --git a/include/ardix/types.h b/include/ardix/types.h index b00a1f1..a4c5c86 100644 --- a/include/ardix/types.h +++ b/include/ardix/types.h @@ -2,6 +2,7 @@ #pragma once +#include #include #if CONFIG_SCHED_MAXPROC < 128 diff --git a/include/arch/arch_include.h b/include/config.h.in similarity index 61% rename from include/arch/arch_include.h rename to include/config.h.in index 005c6a9..4993039 100644 --- a/include/arch/arch_include.h +++ b/include/config.h.in @@ -2,11 +2,16 @@ #pragma once -#ifdef ARCH_AT91SAM3X8E -#define ARCH_INCLUDE(file) -#else -#error "Unsupported architecture" -#endif +#define ARDIX_VERSION_MAJOR @ardix_VERSION_MAJOR@ +#define ARDIX_VERSION_MINOR @ardix_VERSION_MINOR@ +#define ARDIX_VERSION_PATCH @ardix_VERSION_PATCH@ +#define ARDIX_VERSION "@ardix_VERSION@@ardix_VERSION_SUFFIX" + +#cmakedefine DEBUG +#cmakedefine ARCH + +#define CONFIG_STACK_SIZE @CONFIG_STACK_SIZE@ +#define CONFIG_SCHED_MAXPROC @CONFIG_SCHED_MAXPROC@ /* * This file is part of Ardix. diff --git a/lib/Makefile b/init/CMakeLists.txt similarity index 50% rename from lib/Makefile rename to init/CMakeLists.txt index a2965e4..7cbd4eb 100644 --- a/lib/Makefile +++ b/init/CMakeLists.txt @@ -1,6 +1,17 @@ -# +# See the end of this file for copyright and license terms. + +add_library(ardix_init STATIC) +target_link_libraries(ardix INTERFACE ardix_init) + +target_compile_options(ardix_init PRIVATE ${ARDIX_COMPILE_OPTIONS}) +target_include_directories(ardix_init PRIVATE ${ARDIX_INCLUDE_DIRS}) + +target_sources(ardix_init PRIVATE + main.c +) + # This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . +# Copyright (c) 2021 Felix Kopp . # # Ardix is non-violent software: you may only use, redistribute, # and/or modify it under the terms of the CNPLv6+ as found in @@ -9,14 +20,3 @@ # # Ardix comes with ABSOLUTELY NO WARRANTY, to the extent # permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_LIB_PWD := $(PWD)/lib - -ARDIX_SOURCES += \ - $(ARDIX_LIB_PWD)/ctype.c \ - $(ARDIX_LIB_PWD)/errno.c \ - $(ARDIX_LIB_PWD)/list.c \ - $(ARDIX_LIB_PWD)/malloc.c \ - $(ARDIX_LIB_PWD)/string.c \ - $(ARDIX_LIB_PWD)/unistd.c diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt new file mode 100644 index 0000000..708a37a --- /dev/null +++ b/kernel/CMakeLists.txt @@ -0,0 +1,31 @@ +# See the end of this file for copyright and license terms. + +add_library(ardix_kernel STATIC) +target_link_libraries(ardix INTERFACE ardix_kernel) + +target_compile_options(ardix_kernel PRIVATE ${ARDIX_COMPILE_OPTIONS}) +target_include_directories(ardix_kernel PRIVATE ${ARDIX_INCLUDE_DIRS}) + +target_sources(ardix_kernel PRIVATE + device.c + dma.c + io.c + kent.c + printk.c + ringbuf.c + sched.c + serial.c + syscall.c + userspace.c +) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/kernel/Makefile b/kernel/Makefile deleted file mode 100644 index fbdeff9..0000000 --- a/kernel/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# -# This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . -# -# Ardix is non-violent software: you may only use, redistribute, -# and/or modify it under the terms of the CNPLv6+ as found in -# the LICENSE file in the source code root directory or at -# . -# -# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent -# permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_KERNEL_PWD = $(PWD)/kernel - -include $(ARDIX_KERNEL_PWD)/fs/Makefile -include $(ARDIX_KERNEL_PWD)/io/Makefile - -ARDIX_SOURCES += \ - $(ARDIX_KERNEL_PWD)/device.c \ - $(ARDIX_KERNEL_PWD)/dma.c \ - $(ARDIX_KERNEL_PWD)/kent.c \ - $(ARDIX_KERNEL_PWD)/printk.c \ - $(ARDIX_KERNEL_PWD)/ringbuf.c \ - $(ARDIX_KERNEL_PWD)/sched.c \ - $(ARDIX_KERNEL_PWD)/serial.c \ - $(ARDIX_KERNEL_PWD)/syscall.c \ - $(ARDIX_KERNEL_PWD)/userspace.c diff --git a/kernel/fs/CMakeLists.txt b/kernel/fs/CMakeLists.txt new file mode 100644 index 0000000..1c4bd72 --- /dev/null +++ b/kernel/fs/CMakeLists.txt @@ -0,0 +1,23 @@ +# See the end of this file for copyright and license terms. + +add_library(ardix_kernel_fs STATIC) +target_link_libraries(ardix_kernel PUBLIC ardix_kernel_fs) + +target_compile_options(ardix_kernel_fs PRIVATE ${ARDIX_COMPILE_OPTIONS}) +target_include_directories(ardix_kernel_fs PRIVATE ${ARDIX_INCLUDE_DIRS}) + +target_sources(ardix_kernel_fs PRIVATE + read.c + write.c +) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/kernel/io/io.c b/kernel/io.c similarity index 100% rename from kernel/io/io.c rename to kernel/io.c diff --git a/kernel/io/Makefile b/kernel/io/Makefile deleted file mode 100644 index 5ea8e2d..0000000 --- a/kernel/io/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# -# This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . -# -# Ardix is non-violent software: you may only use, redistribute, -# and/or modify it under the terms of the CNPLv6+ as found in -# the LICENSE file in the source code root directory or at -# . -# -# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent -# permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_KERNEL_IO_PWD = $(ARDIX_KERNEL_PWD)/io - -ARDIX_SOURCES += \ - $(ARDIX_KERNEL_IO_PWD)/io.c diff --git a/kernel/sched.c b/kernel/sched.c index 52296fb..48b1448 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1,7 +1,7 @@ /* See the end of this file for copyright, license, and warranty information. */ -#include -#include +#include +#include #include #include diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..531bc5a --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,27 @@ +# See the end of this file for copyright and license terms. + +add_library(ardix_lib STATIC) +target_link_libraries(ardix INTERFACE ardix_lib) + +target_compile_options(ardix_lib PRIVATE ${ARDIX_COMPILE_OPTIONS}) +target_include_directories(ardix_lib PRIVATE ${ARDIX_INCLUDE_DIRS}) + +target_sources(ardix_lib PRIVATE + ctype.c + errno.c + list.c + malloc.c + string.c + unistd.c +) + +# This file is part of Ardix. +# Copyright (c) 2021 Felix Kopp . +# +# Ardix is non-violent software: you may only use, redistribute, +# and/or modify it under the terms of the CNPLv6+ as found in +# the LICENSE file in the source code root directory or at +# . +# +# Ardix comes with ABSOLUTELY NO WARRANTY, to the extent +# permitted by applicable law. See the CNPLv6+ for details. diff --git a/kernel/fs/Makefile b/options.cmake similarity index 61% rename from kernel/fs/Makefile rename to options.cmake index 99897b0..fe8454d 100644 --- a/kernel/fs/Makefile +++ b/options.cmake @@ -1,6 +1,10 @@ -# +# See the end of this file for copyright and license terms. + +set(CONFIG_STACK_SIZE 2048 CACHE STRING "Stack size in bytes") +set(CONFIG_SCHED_MAXPROC 8 CACHE STRING "Maximum number of processes") + # This file is part of Ardix. -# Copyright (c) 2020, 2021 Felix Kopp . +# Copyright (c) 2021 Felix Kopp . # # Ardix is non-violent software: you may only use, redistribute, # and/or modify it under the terms of the CNPLv6+ as found in @@ -9,10 +13,3 @@ # # Ardix comes with ABSOLUTELY NO WARRANTY, to the extent # permitted by applicable law. See the CNPLv6+ for details. -# - -ARDIX_KERNEL_FS_PWD = $(ARDIX_KERNEL_PWD)/fs - -ARDIX_SOURCES += \ - $(ARDIX_KERNEL_FS_PWD)/read.c \ - $(ARDIX_KERNEL_FS_PWD)/write.c