diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e79227f..41efb66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: key: toolchain-${{ matrix.arch }} - name: Build toolchain ${{ matrix.arch }} - run: ARCH=${{ matrix.arch }} ./scripts/build_toolchain.sh + run: ARCH=${{ matrix.arch }} ./tools/build_toolchain.sh - name: Build Fukuro ${{ matrix.arch }} run: ARCH=${{ matrix.arch }} make diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 46dc3b0..eb68a70 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -26,11 +26,18 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 + run: | + sudo apt-get update + sudo apt-get install build-essential libcmocka-dev - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} + - name: Build + run: | + make test + - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.gitignore b/.gitignore index 58af6b9..156045e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,30 @@ node_modules/ toolchain/ fukuro.iso *~ -test *.gcda *.gcno -docs/ \ No newline at end of file +docs/html +*.img + +.config +.config.mk +config.h +*.old +test.exe + +*.in +/aclocal.m4 +*.sub +*.guess +/configure +/install-sh +Makefile +/tmp +/build +build.mk +/build-aux/ar-lib +/build-aux/compile +/build-aux/depcomp +/build-aux/install-sh +/build-aux/missing +*.cache \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 65a53f8..0000000 --- a/Makefile +++ /dev/null @@ -1,95 +0,0 @@ -.DEFAULT_GOAL = all - -# Global config -ARCH ?= i686 - -ifeq ($(TOOLCHAIN), llvm) -CC = clang -target $(ARCH)-elf -AS = $(CC) -LD = ld.lld -OBJCOPY = llvm-objcopy -else -CC = $(ARCH)-elf-gcc -AS = $(CC) -LD = $(ARCH)-elf-ld -OBJCOPY = $(ARCH)-elf-objcopy -endif - -RM = rm -rf -SPARSE = sparse -ifeq ($(C),) - SPARSE := : -endif - -VERSION = $$(cat VERSION) -COMMIT = $$(git rev-parse --short HEAD) - -CFLAGS = -ansi -pedantic -pedantic-errors -Wall -Werror -Wextra \ - -ffreestanding -fno-builtin -nostdlib -O2 \ - -Iarch/$(ARCH)/include -Iarch -Ilibk/include \ - -DVERSION="\"$(VERSION)\"" -DCOMMIT="\"$(COMMIT)\"" \ - -Wno-variadic-macros -ASFLAGS = -LDFLAGS = -T arch/$(ARCH)/linker.ld -nostdlib - -KERNEL = kernel.elf - -# import arch specific build config -ifneq "$(wildcard arch/$(ARCH)/)" "" - include arch/$(ARCH)/build.mk -else - $(error "$(ARCH) is not supported by Fukuro") -endif - -include kernel/build.mk -include libk/build.mk - -TARGET ?= $(KERNEL) - -OBJS = $(addprefix kernel/, $(KERN_C_SRCS:.c=.o)) \ - $(addprefix arch/$(ARCH)/, $(ARCH_ASM_SRCS:.s=.s.o)) \ - $(addprefix arch/$(ARCH)/, $(ARCH_C_SRCS:.c=.o)) \ - $(addprefix libk/, $(LIBK_C_SRCS:.c=.o)) - -OBJS_TEST = $(addprefix libk/, $(LIBK_C_SRCS:.c=.o)) \ - $(addprefix libk/, $(LIBK_C_TESTS:.c=.o)) - -test: CFLAGS = -Wall -Werror -Wextra -fno-builtin \ - -Iarch/$(ARCH)/include -Iarch -Ilibk/include \ - --coverage -test: LDFLAGS = -lcmocka --coverage -test: CC = gcc - -all: $(TARGET) - -test: $(OBJS_TEST) - $(CC) -o $@ $^ $(LDFLAGS) - ./$@ - -$(KERNEL): $(OBJS) - $(LD) $(LDFLAGS) -o $@ $^ - -%.s.o: %.S - $(AS) $(ASFLAGS) -o $@ $< - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - @ $(SPARSE) $(CFLAGS) -c -o $@ $< - -clean: - $(RM) $(OBJS) - $(RM) $(OBJS_TEST) - $(RM) $(OBJS_TEST:.o=.gcda) - $(RM) $(OBJS_TEST:.o=.gcno) - -fclean: clean - $(RM) $(KERNEL) - $(RM) $(TARGET) - $(RM) test - -re: fclean all - -format: - find . -type f -name "*.[h|c]" -exec ./scripts/format.sh {} \; - -.PHONY: all clean fclean re qemu format test diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..5fc7e39 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = lib sys srv diff --git a/VERSION b/VERSION deleted file mode 100644 index afaf360..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.0.0 \ No newline at end of file diff --git a/arch/generic/stivale2.h b/arch/generic/stivale2.h deleted file mode 100644 index 04aa710..0000000 --- a/arch/generic/stivale2.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _GENERIC_STIVALE2_H_ -# define _GENERIC_STIVALE2_H_ 1 - -struct stivale2_header -{ - uint64_t entry_point; - uint64_t stack; - uint64_t flags; - uint64_t tags; -} __attribute__((packed)); - -struct stivale2_struct -{ - char bootloader_brand[64]; - char bootloader_version[64]; - - uint64_t tags; -} __attribute__((packed)); - -#endif /* !_GENERIC_STIVALE2_H_ */ diff --git a/arch/i686/boot.s b/arch/i686/boot.s deleted file mode 100644 index 12d0732..0000000 --- a/arch/i686/boot.s +++ /dev/null @@ -1,2 +0,0 @@ - -arch/i686/boot.S diff --git a/build-aux/git-version b/build-aux/git-version new file mode 100755 index 0000000..5f02625 --- /dev/null +++ b/build-aux/git-version @@ -0,0 +1,20 @@ +#!/bin/sh + +v=`git describe --abbrev=4 --match='v[0-9]*' HEAD 2>/dev/null` + +if [ ! -n "$v" ] +then + v="0.0" +fi + +c=`git rev-parse --short HEAD` + +v="${v}-${c}" + +s=`git status` +if [ -n "$s" ] +then + v="${v}-dirty" +fi + +echo "$v" | tr -d '\012' \ No newline at end of file diff --git a/codecov.yml b/codecov.yml index e6a6834..b52d0c4 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,2 @@ ignore: - - "**/tests" + - "test" diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index 3347cb9..0000000 --- a/commitlint.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {extends: ['@commitlint/config-conventional']}; diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..def43ea --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,10 @@ +-ansi +-pedantic +-pedantic-errors +-Wall +-Werror +-Wextra +-fno-builtin +-Wno-variadic-macros +-Dinline=__inline__ +-Isrc/lib diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..f5eb799 --- /dev/null +++ b/configure.ac @@ -0,0 +1,97 @@ +m4_define([fukuro_VERSION], + m4_esyscmd([build-aux/git-version])) +AC_INIT([Fukuro], + m4_defn([fukuro_VERSION]), + [https://github.com/d0p1s4m4/Fukuro/issues]) +AC_COPYRIGHT([Copyright (C) 2023 d0p1]) + +CFLAGS="-ffreestanding -nostdlib -fno-builtin" + +AC_CONFIG_AUX_DIR([build-aux]) + +AM_INIT_AUTOMAKE([foreign subdir-objects]) + +dnl overide default AC_LANG_PROGRAM(C) macro +m4_ifdef([AC_LANG_PROGRAM(c)], m4_undefine[AC_LANG_PROGRAM(c)]) +m4_define([AC_LANG_PROGRAM(C)], +[$1 + +int +_start (void) +{ +$2 + ; + return 0; +}]) + +AC_CANONICAL_HOST + +AS_CASE([$host_cpu], + [i?86], [ + systype=i686 + ], + [x86_64], [systype=amd64], + [systype=$host_cpu] +) +AC_SUBST([systype]) + +m4_include([sys/configfrag.ac]) + +AS_IF([! test -d "$srcdir/sys/$systype"], + [AC_MSG_ERROR(["$host_cpu isn't supported by Fukuro"])]) + +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([Makefile lib/Makefile srv/Makefile sys/Makefile]) + +AC_LANG([C]) +save_cross_compiling=$cross_compiling +cross_compiling=yes +AM_PROG_AS +cross_compiling=$save_cross_compiling +AC_PROG_CC +AC_PROG_CPP +AC_PROG_RANLIB +AC_PROG_LN_S +AC_PROG_MKDIR_P +AC_PROG_CC_C_O +AM_PROG_AR + +AC_CHECK_TOOL([STRIP], [strip]) +AC_CHECK_TOOL([OBJCOPY], [objcopy]) +AC_CHECK_PROG([GZIP], [gzip], [gzip]) +AC_CHECK_PROG([QEMU], [qemu-system-$host_cpu], [qemu-system-$host_cpu]) +AC_CHECK_PROG([PYTHON3], [python3], [python3]) +AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen]) + +AC_C_CONST +AC_C_INLINE +AC_C_VOLATILE +AC_C_BIGENDIAN +AC_CHECK_HEADERS([stdarg.h]) +AC_C_STRINGIZE + +AC_CHECK_TYPE(uintptr_t) +AC_TYPE_SIZE_T + +AC_CONFIG_LINKS(["sys/machine":"$srcdir/sys/$systype"]) + +AC_ARG_ENABLE([ncpus], + AS_HELP_STRING([--enable-ncpus=N], []), + [ncpu=$enable_ncpus] + [ncpu=1]) +AC_DEFINE_UNQUOTED([NCPUS], [$ncpus], [number of CPUs]) + +m4_include([srv/configfrag.ac]) + +AC_OUTPUT +AC_MSG_RESULT([ + Fukurō version: $PACKAGE_STRING + Architecture: $host_cpu + + C Compiler: $CC + Asm Compiler: $CCAS + + CFLAGS: $CFLAGS + CCASFLAGS: $CCASFLAG + LDFLAGS: $LDFLAGS +]) diff --git a/docs/credits.md b/docs/credits.md new file mode 100644 index 0000000..34276d6 --- /dev/null +++ b/docs/credits.md @@ -0,0 +1,44 @@ +# Credits + +Fukurō takes inspirations and/or reuse code from the following projects: + +## BRUTAL + +Striking modernist shapes and bold use of modern C are the hallmarks of BRUTAL. Inspired by brutalist design BRUTAL combines the ideals of UNIX from the 1970s with modern technology and engineering. + +URL: + +``` +MIT License + +Copyright (c) 2021-2022 The brutal operating system contributors +``` + +## cute-engineewing + +A group of hackers who design minimalist software. + +URL: + +``` +BSD 3-Clause License + +Copyright (c) 2021, cute-engineewing +Copyright (c) 2021, The µnix Contributors +``` + +## Minix 3 + +Minix (from mini-Unix) is a Unix-like operating system. + +URL: + +``` +BSD 3-Clause License + +Copyright (c) 1987,1997,2001 Prentice Hall +``` + +## Albert Hofmann + +The first known person to synthesize, ingest, and learn of the psychedelic effects of lysergic acid diethylamide (LSD). diff --git a/docs/layout.md b/docs/layout.md new file mode 100644 index 0000000..c88a697 --- /dev/null +++ b/docs/layout.md @@ -0,0 +1,26 @@ +# Source layout + +- `docs/` Documentation +- `make/` Makefiles helper + - `aarch64/` + - `arm/` + - `x86/` + - `32/` + - `64/` +- `src/` + - `kernel/` + - `arch/` + - `aarch64/` + - `arm/` + - `x86/` + - `32/` + - `64/` + - `lib/` + - `minic/` + - `fukuro/` + - `server/` + - `net/` + - `rtl8139/` +- `test/` +- `thirdparty/` Sources code from external source +- `tools/` Scripts used in order to build Fukurō diff --git a/kernel/build.mk b/kernel/build.mk deleted file mode 100644 index e86aac8..0000000 --- a/kernel/build.mk +++ /dev/null @@ -1 +0,0 @@ -KERN_C_SRCS = $(addprefix src/, main.c) diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..adec5ae --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,4 @@ +noinst_DATA = crt0.o + +crt0.o: minilibc/@systype@/crt0.S + $(CC) -c $(AM_CPPFLAGS) $(CFLAGS) -o $@ $^ diff --git a/lib/minilibc/amd64/crt0.S b/lib/minilibc/amd64/crt0.S new file mode 100644 index 0000000..cacc832 --- /dev/null +++ b/lib/minilibc/amd64/crt0.S @@ -0,0 +1,24 @@ + .section .text + .align 8 + + .extern __bss_begin + .extern __bss_end + .extern __minilibc_main + + .globl _start +_start: + xorq %rbp, %rbp + + /* clear bss */ + xorq %rax, %rax + movq $__bss_begin, %rdi + movq $__bss_end, %rcx + subq %rdi, %rcx + cld + rep + stosb + + movq %rsp, %rdi + call __minilibc_main + + hlt diff --git a/lib/minilibc/amd64/linker.ld b/lib/minilibc/amd64/linker.ld new file mode 100644 index 0000000..2fbceee --- /dev/null +++ b/lib/minilibc/amd64/linker.ld @@ -0,0 +1,25 @@ +ENTRY(_start) + +SECTIONS { + . = 4M; + + .text : ALIGN(4K) { + *(.text); + } + + .rodata : ALIGN(4K) { + *(.rodata); + } + + .data : ALIGN(4K) { + *(.data); + } + + .bss : ALIGN(4K) { + *(COMMON); + *(.bss); + } + + PROVIDE(__bss_begin = ADDR(.bss)); + PROVIDE(__bss_end = ADDR(.bss) + SIZEOF(.bss)); +} diff --git a/lib/minilibc/arm/crt0.S b/lib/minilibc/arm/crt0.S new file mode 100644 index 0000000..c24e67d --- /dev/null +++ b/lib/minilibc/arm/crt0.S @@ -0,0 +1,5 @@ + .section ".text" + + .globl _start +_start: + b main diff --git a/lib/minilibc/i686/crt0.S b/lib/minilibc/i686/crt0.S new file mode 100644 index 0000000..80af139 --- /dev/null +++ b/lib/minilibc/i686/crt0.S @@ -0,0 +1,24 @@ + .section ".text" + .align 4 + + .extern __bss_begin + .extern __bss_end + .extern __minilibc_main + + .globl _start +_start: + xorl %ebp, %ebp + + xorl %eax, %eax + movl $__bss_begin, %edi + movl $__bss_end, %ecx + subl %edi, %ecx + cld + rep + stosb + + pushl %ebp + + call __minilibc_main + + hlt diff --git a/lib/minilibc/minilibc.c b/lib/minilibc/minilibc.c new file mode 100644 index 0000000..280463d --- /dev/null +++ b/lib/minilibc/minilibc.c @@ -0,0 +1,21 @@ +/* + * This file is part of Fukurō. + * + * Fukurō is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Fukurō is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Fukurō. If not, see . + */ + +void +__minilibc_main(void) +{ +} diff --git a/lib/minilibc/riscv/crt0.S b/lib/minilibc/riscv/crt0.S new file mode 100644 index 0000000..7a79065 --- /dev/null +++ b/lib/minilibc/riscv/crt0.S @@ -0,0 +1,38 @@ +/* + * This file is part of Fukurō. + * + * Fukurō is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Fukurō is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Fukurō. If not, see . + */ + .section ".text" + + .extern __stack_top + .extern __bss_begin + .extern __bss_end + .extern __minilibc_main + + .globl _start +_start: + la sp, __stack_top + + la t0, __bss_begin + la t1, __bss_end + + bltu t1, t0, 2f +1: + sw x0, (t0) + addi t0, t0, 4 + bltu t0, t1, 1b +2: + + call __minilibc_main diff --git a/lib/minilibc/riscv/linker.ld b/lib/minilibc/riscv/linker.ld new file mode 100644 index 0000000..fcea189 --- /dev/null +++ b/lib/minilibc/riscv/linker.ld @@ -0,0 +1,28 @@ +ENTRY(_start) + +SECTIONS { + . = 0x1000000; + + .text :{ + *(.text .text.*); + } + + .rodata : ALIGN(4) { + *(.rodata .rodata.*); + } + + .data : ALIGN(4) { + *(.data .data.*); + } + + .bss : ALIGN(4) { + *(.bss .bss.* .sbss .sbss.*); + + . = ALIGN(4); + . += 64 * 1024; + PROVIDE(__stack_top = .); + } + + PROVIDE(__bss_begin = ADDR(.bss)); + PROVIDE(__bss_end = ADDR(.bss) + SIZEOF(.bss)); +} diff --git a/lib/minilibc/string.h b/lib/minilibc/string.h new file mode 100644 index 0000000..012047c --- /dev/null +++ b/lib/minilibc/string.h @@ -0,0 +1,9 @@ +#ifndef FUKURO_MINILIBC_H +# define FUKURO_MINILIBC_H 1 + +# include + +void *memset(void *dest, int c, size_t count); +size_t strlen(const char *str); + +#endif /* !FUKURO_MINILIBC_H */ diff --git a/libk/build.mk b/libk/build.mk deleted file mode 100644 index b65430a..0000000 --- a/libk/build.mk +++ /dev/null @@ -1,7 +0,0 @@ -LIBK_C_SRCS = $(addprefix src/, itoa.c strlen.c strrev.c memset.c logger.c) - -LIBK_C_TESTS = $(addprefix tests/, test.c \ - strlen_test.c \ - strrev_test.c \ - itoa_test.c \ - memset_test.c) diff --git a/m4/asm.m4 b/m4/asm.m4 new file mode 100644 index 0000000..3632f2c --- /dev/null +++ b/m4/asm.m4 @@ -0,0 +1,5 @@ +AC_DEFUN([FK_ASM_INLINE], [ + AC_LANG_PUSH([C]) + AC_MSG_CHECKING(for inline assembly) + AC_LANG_POP([C]) +]) diff --git a/package.json b/package.json deleted file mode 100644 index bac748f..0000000 --- a/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "fukuro", - "version": "1.0.0", - "description": "", - "dependencies": {}, - "devDependencies": { - "@commitlint/cli": "^9.1.2", - "@commitlint/config-conventional": "^10.0.0", - "commitizen": "^4.1.5", - "cz-conventional-changelog": "^3.2.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/d0p1s4m4/Fukuro.git" - }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } - }, - "private": true -} diff --git a/src/kernel/arch/Kconfig b/src/kernel/arch/Kconfig new file mode 100644 index 0000000..adcbfa6 --- /dev/null +++ b/src/kernel/arch/Kconfig @@ -0,0 +1,4 @@ + +rsource "aarch64/Kconfig" +rsource "arm/Kconfig" +rsource "x86/Kconfig" \ No newline at end of file diff --git a/src/kernel/arch/aarch64/Kconfig b/src/kernel/arch/aarch64/Kconfig new file mode 100644 index 0000000..f82e31a --- /dev/null +++ b/src/kernel/arch/aarch64/Kconfig @@ -0,0 +1,8 @@ +menu "AArch64 Architecture" + depends on AARCH64 + + config ARCH + string + default "aarch64" + +endmenu diff --git a/arch/aarch64/arch.c b/src/kernel/arch/aarch64/arch.c similarity index 98% rename from arch/aarch64/arch.c rename to src/kernel/arch/aarch64/arch.c index d282e6f..0244f42 100644 --- a/arch/aarch64/arch.c +++ b/src/kernel/arch/aarch64/arch.c @@ -25,7 +25,7 @@ uint32_t g_mmio_base; static void detect_rpi_board(void) { - uint32_t value; + uint64_t value; __asm__ volatile ("mrs %0, midr_el1":"=r" (value)); diff --git a/arch/aarch64/boot.S b/src/kernel/arch/aarch64/boot.S similarity index 100% rename from arch/aarch64/boot.S rename to src/kernel/arch/aarch64/boot.S diff --git a/arch/aarch64/build.mk b/src/kernel/arch/aarch64/build.mk similarity index 65% rename from arch/aarch64/build.mk rename to src/kernel/arch/aarch64/build.mk index a4b98af..4fbe360 100644 --- a/arch/aarch64/build.mk +++ b/src/kernel/arch/aarch64/build.mk @@ -1,14 +1,13 @@ # overwrite main makefile config CFLAGS += -mgeneral-regs-only -ASFLAGS += -c $(CFLAGS) ARCH_ASM_SRCS = boot.s utils.s ARCH_C_SRCS = arch.c serial.c -TARGET = kernel8.img +TARGET := kernel8.img $(TARGET): $(KERNEL) $(OBJCOPY) $^ -O binary $@ qemu: $(TARGET) - qemu-system-aarch64 -M raspi3 -serial stdio -kernel $^ + qemu-system-aarch64 -M raspi3b -serial stdio -kernel $^ diff --git a/arch/aarch64/include/machine/arch.h b/src/kernel/arch/aarch64/include/machine/arch.h similarity index 100% rename from arch/aarch64/include/machine/arch.h rename to src/kernel/arch/aarch64/include/machine/arch.h diff --git a/arch/aarch64/linker.ld b/src/kernel/arch/aarch64/linker.ld similarity index 100% rename from arch/aarch64/linker.ld rename to src/kernel/arch/aarch64/linker.ld diff --git a/arch/aarch64/rpi.h b/src/kernel/arch/aarch64/rpi.h similarity index 100% rename from arch/aarch64/rpi.h rename to src/kernel/arch/aarch64/rpi.h diff --git a/arch/aarch64/serial.c b/src/kernel/arch/aarch64/serial.c similarity index 100% rename from arch/aarch64/serial.c rename to src/kernel/arch/aarch64/serial.c diff --git a/arch/aarch64/serial.h b/src/kernel/arch/aarch64/serial.h similarity index 100% rename from arch/aarch64/serial.h rename to src/kernel/arch/aarch64/serial.h diff --git a/arch/aarch64/utils.S b/src/kernel/arch/aarch64/utils.S similarity index 100% rename from arch/aarch64/utils.S rename to src/kernel/arch/aarch64/utils.S diff --git a/src/kernel/arch/arm/Kconfig b/src/kernel/arch/arm/Kconfig new file mode 100644 index 0000000..e69de29 diff --git a/arch/arm/arch.c b/src/kernel/arch/arm/arch.c similarity index 100% rename from arch/arm/arch.c rename to src/kernel/arch/arm/arch.c diff --git a/arch/arm/boot.S b/src/kernel/arch/arm/boot.S similarity index 100% rename from arch/arm/boot.S rename to src/kernel/arch/arm/boot.S diff --git a/arch/arm/build.mk b/src/kernel/arch/arm/build.mk similarity index 100% rename from arch/arm/build.mk rename to src/kernel/arch/arm/build.mk diff --git a/arch/arm/include/machine/arch.h b/src/kernel/arch/arm/include/machine/arch.h similarity index 100% rename from arch/arm/include/machine/arch.h rename to src/kernel/arch/arm/include/machine/arch.h diff --git a/arch/arm/linker.ld b/src/kernel/arch/arm/linker.ld similarity index 100% rename from arch/arm/linker.ld rename to src/kernel/arch/arm/linker.ld diff --git a/arch/generic/arch.h b/src/kernel/arch/generic/arch.h similarity index 100% rename from arch/generic/arch.h rename to src/kernel/arch/generic/arch.h diff --git a/arch/i686/arch.c b/src/kernel/arch/x86/32/arch.c similarity index 100% rename from arch/i686/arch.c rename to src/kernel/arch/x86/32/arch.c diff --git a/arch/i686/boot.S b/src/kernel/arch/x86/32/boot.S similarity index 89% rename from arch/i686/boot.S rename to src/kernel/arch/x86/32/boot.S index 49c43a1..604054e 100644 --- a/arch/i686/boot.S +++ b/src/kernel/arch/x86/32/boot.S @@ -49,17 +49,6 @@ multiboot2_header: dd 8 .end: - ;; -------------------------------------------------------------------- - ;; Stivale 2 - ;; -------------------------------------------------------------------- -section .stivale2hdr -align 4 - extern boot_stivale2 - dq boot_stivale2 - dq stack_top - dq 0 - dq 0 - ;; -------------------------------------------------------------------- ;; Stack ;; -------------------------------------------------------------------- diff --git a/arch/i686/build.mk b/src/kernel/arch/x86/32/build.mk similarity index 100% rename from arch/i686/build.mk rename to src/kernel/arch/x86/32/build.mk diff --git a/arch/i686/cpuid.c b/src/kernel/arch/x86/32/cpuid.c similarity index 100% rename from arch/i686/cpuid.c rename to src/kernel/arch/x86/32/cpuid.c diff --git a/arch/i686/cpuid.h b/src/kernel/arch/x86/32/cpuid.h similarity index 100% rename from arch/i686/cpuid.h rename to src/kernel/arch/x86/32/cpuid.h diff --git a/arch/i686/gdt.S b/src/kernel/arch/x86/32/gdt.S similarity index 100% rename from arch/i686/gdt.S rename to src/kernel/arch/x86/32/gdt.S diff --git a/arch/i686/gdt.c b/src/kernel/arch/x86/32/gdt.c similarity index 100% rename from arch/i686/gdt.c rename to src/kernel/arch/x86/32/gdt.c diff --git a/arch/i686/gdt.h b/src/kernel/arch/x86/32/gdt.h similarity index 100% rename from arch/i686/gdt.h rename to src/kernel/arch/x86/32/gdt.h diff --git a/arch/i686/idt.S b/src/kernel/arch/x86/32/idt.S similarity index 100% rename from arch/i686/idt.S rename to src/kernel/arch/x86/32/idt.S diff --git a/arch/i686/idt.c b/src/kernel/arch/x86/32/idt.c similarity index 100% rename from arch/i686/idt.c rename to src/kernel/arch/x86/32/idt.c diff --git a/arch/i686/idt.h b/src/kernel/arch/x86/32/idt.h similarity index 100% rename from arch/i686/idt.h rename to src/kernel/arch/x86/32/idt.h diff --git a/arch/i686/include/machine/arch.h b/src/kernel/arch/x86/32/include/machine/arch.h similarity index 100% rename from arch/i686/include/machine/arch.h rename to src/kernel/arch/x86/32/include/machine/arch.h diff --git a/arch/i686/isr.S b/src/kernel/arch/x86/32/isr.S similarity index 100% rename from arch/i686/isr.S rename to src/kernel/arch/x86/32/isr.S diff --git a/arch/i686/isr.c b/src/kernel/arch/x86/32/isr.c similarity index 100% rename from arch/i686/isr.c rename to src/kernel/arch/x86/32/isr.c diff --git a/arch/i686/isr.h b/src/kernel/arch/x86/32/isr.h similarity index 100% rename from arch/i686/isr.h rename to src/kernel/arch/x86/32/isr.h diff --git a/arch/i686/linker.ld b/src/kernel/arch/x86/32/linker.ld similarity index 100% rename from arch/i686/linker.ld rename to src/kernel/arch/x86/32/linker.ld diff --git a/arch/i686/pic.c b/src/kernel/arch/x86/32/pic.c similarity index 100% rename from arch/i686/pic.c rename to src/kernel/arch/x86/32/pic.c diff --git a/arch/i686/pic.h b/src/kernel/arch/x86/32/pic.h similarity index 100% rename from arch/i686/pic.h rename to src/kernel/arch/x86/32/pic.h diff --git a/arch/x86_64/arch.c b/src/kernel/arch/x86/64/arch.c similarity index 100% rename from arch/x86_64/arch.c rename to src/kernel/arch/x86/64/arch.c diff --git a/arch/x86_64/build.mk b/src/kernel/arch/x86/64/build.mk similarity index 100% rename from arch/x86_64/build.mk rename to src/kernel/arch/x86/64/build.mk diff --git a/arch/x86_64/include/machine/arch.h b/src/kernel/arch/x86/64/include/machine/arch.h similarity index 100% rename from arch/x86_64/include/machine/arch.h rename to src/kernel/arch/x86/64/include/machine/arch.h diff --git a/arch/x86_64/linker.ld b/src/kernel/arch/x86/64/linker.ld similarity index 100% rename from arch/x86_64/linker.ld rename to src/kernel/arch/x86/64/linker.ld diff --git a/src/kernel/arch/x86/Kconfig b/src/kernel/arch/x86/Kconfig new file mode 100644 index 0000000..34886de --- /dev/null +++ b/src/kernel/arch/x86/Kconfig @@ -0,0 +1,22 @@ +menu "x86 architecture" + depends on X86 + + config ARCH + string + default "x86" + + config 64BIT + bool + prompt "64 Bit" + default n + + config SMP + bool + prompt "SMP" + default n + + config PAE + bool + prompt "PAE" + default n +endmenu diff --git a/arch/x86/build.mk b/src/kernel/arch/x86/build.mk similarity index 100% rename from arch/x86/build.mk rename to src/kernel/arch/x86/build.mk diff --git a/arch/x86/greeting.c b/src/kernel/arch/x86/greeting.c similarity index 100% rename from arch/x86/greeting.c rename to src/kernel/arch/x86/greeting.c diff --git a/arch/x86/greeting.h b/src/kernel/arch/x86/greeting.h similarity index 100% rename from arch/x86/greeting.h rename to src/kernel/arch/x86/greeting.h diff --git a/arch/x86/serial.c b/src/kernel/arch/x86/serial.c similarity index 100% rename from arch/x86/serial.c rename to src/kernel/arch/x86/serial.c diff --git a/arch/x86/serial.h b/src/kernel/arch/x86/serial.h similarity index 100% rename from arch/x86/serial.h rename to src/kernel/arch/x86/serial.h diff --git a/arch/x86/vga.c b/src/kernel/arch/x86/vga.c similarity index 100% rename from arch/x86/vga.c rename to src/kernel/arch/x86/vga.c diff --git a/arch/x86/vga.h b/src/kernel/arch/x86/vga.h similarity index 100% rename from arch/x86/vga.h rename to src/kernel/arch/x86/vga.h diff --git a/src/kernel/build.mk b/src/kernel/build.mk new file mode 100644 index 0000000..35b788f --- /dev/null +++ b/src/kernel/build.mk @@ -0,0 +1,16 @@ +KERNEL_SRCS = main.c + +KERNEL_OBJS = $(addprefix $(KERNEL_BUILDDIR)/, $(KERNEL_SRCS:.c=.o)) + +TARGET = fukuro.elf + +kernel8.img: fukuro.elf + $(TARGET_OBJCOPY) $< -O binary $@ + +fukuro.elf: $(KERNEL_OBJS) $(LIB_MINIC_KERNEL_OBJS) + $(TARGET_CC) -o $@ $^ $(KERNEL_LDFLAGS) + +$(KERNEL_BUILDDIR)/%.o: src/kernel/%.c + @ mkdir -p $(dir $@) + $(TARGET_CC) -o $@ -c $< $(KERNEL_CFLAGS) + diff --git a/kernel/src/main.c b/src/kernel/main.c similarity index 100% rename from kernel/src/main.c rename to src/kernel/main.c diff --git a/src/lib/build.mk b/src/lib/build.mk new file mode 100644 index 0000000..7d5c189 --- /dev/null +++ b/src/lib/build.mk @@ -0,0 +1,4 @@ +# vim: set tabstop=4:shiftwidth=4:noexpandtab + +include src/lib/minic/build.mk +include src/lib/fukuro/build.mk \ No newline at end of file diff --git a/src/lib/fukuro/build.mk b/src/lib/fukuro/build.mk new file mode 100644 index 0000000..20e3694 --- /dev/null +++ b/src/lib/fukuro/build.mk @@ -0,0 +1,7 @@ +# vim: set tabstop=4:shiftwidth=4:noexpandtab + +LIB_FUKURO_SRCS = logger.c + +LIB_FUKURO_OBJS = $(addprefix lib/fukuro/, $(LIB_FUKURO_SRCS:.c=.o)) + +GARBADGE += LIB_FUKURO_OBJS diff --git a/libk/src/logger.c b/src/lib/fukuro/logger.c similarity index 95% rename from libk/src/logger.c rename to src/lib/fukuro/logger.c index 7862de0..20b7044 100644 --- a/libk/src/logger.c +++ b/src/lib/fukuro/logger.c @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include static const char *LOG_LEVEL_STR[] = { "[*]", "\033[32m[+]\033[0m", "\033[33m[-]\033[0m", "\033[31m[!]\033[0m" @@ -27,7 +27,7 @@ static const char *LOG_LEVEL_STR[] = { static void debug_print_int(int number, int base) { - char buff[6]; /* 99 999 */ + char buff[20]; itoa(number, buff, base); debug_puts(buff); diff --git a/libk/include/kern/logger.h b/src/lib/fukuro/logger.h similarity index 92% rename from libk/include/kern/logger.h rename to src/lib/fukuro/logger.h index 45c8f97..1253c3b 100644 --- a/libk/include/kern/logger.h +++ b/src/lib/fukuro/logger.h @@ -15,8 +15,8 @@ * along with Fukurō. If not, see . */ -#ifndef _KERN_LOGGER_H_ -# define _KERN_LOGGER_H_ 1 +#ifndef _FUKURO_LOGGER_H_ +# define _FUKURO_LOGGER_H_ 1 enum log_level { INFO, @@ -30,7 +30,7 @@ enum log_level { # define LOG(level, ...) __log(level, __FILE__, __LINE__, __VA_ARGS__); # else # define LOG(level, msg, ...) -# endif /* !NDEBUG */ +# endif /* !NDEBUG */ void __log(int, const char *, uint16_t, const char *, ...); diff --git a/src/lib/minic/build.mk b/src/lib/minic/build.mk new file mode 100644 index 0000000..6bcb376 --- /dev/null +++ b/src/lib/minic/build.mk @@ -0,0 +1,18 @@ +# vim: set tabstop=4:shiftwidth=4:noexpandtab + +LIB_MINIC_SRCS = itoa.c \ + strlen.c \ + strrev.c \ + memset.c + +LIB_MINIC_KERNEL_OBJS = $(addprefix $(KERNEL_BUILDDIR)/lib/minic/, $(LIB_MINIC_SRCS:.c=.o)) +LIB_MINIC_TEST_OBJS = $(addprefix $(TEST_BUILDDIR)/lib/minic/, $(LIB_MINIC_SRCS:.c=.o)) + +$(TEST_BUILDDIR)/lib/minic/%.o: src/lib/minic/%.c + @ mkdir -p $(dir $@) + $(CC) -o $@ -c $< $(TESTS_CFLAGS) + +$(KERNEL_BUILDDIR)/lib/minic/%.o: src/lib/minic/%.c + @ mkdir -p $(dir $@) + $(TARGET_CC) -o $@ -c $< $(KERNEL_CFLAGS) + diff --git a/libk/src/itoa.c b/src/lib/minic/itoa.c similarity index 97% rename from libk/src/itoa.c rename to src/lib/minic/itoa.c index f57bc93..b3ae83d 100644 --- a/libk/src/itoa.c +++ b/src/lib/minic/itoa.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include char * itoa(int number, char *buffer, int base) diff --git a/libk/src/memset.c b/src/lib/minic/memset.c similarity index 97% rename from libk/src/memset.c rename to src/lib/minic/memset.c index f0cae88..84b8f08 100644 --- a/libk/src/memset.c +++ b/src/lib/minic/memset.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include void * memset(void *dest, int value, unsigned int length) diff --git a/libk/include/kern/string.h b/src/lib/minic/string.h similarity index 90% rename from libk/include/kern/string.h rename to src/lib/minic/string.h index 34800b6..60f737d 100644 --- a/libk/include/kern/string.h +++ b/src/lib/minic/string.h @@ -15,8 +15,8 @@ * along with Fukurō. If not, see . */ -#ifndef _KERN_STRING_H_ -# define _KERN_STRING_H_ 1 +#ifndef _MINIC_STRING_H_ +# define _MINIC_STRING_H_ 1 char *itoa(int, char *, int); char *strrev(char *); @@ -24,4 +24,4 @@ int strlen(const char *); void *memset(void *, int, unsigned int); void bzero(void *, unsigned int); -#endif /* !_KERN_STRING_H_ */ +#endif /* !_MINIC_STRING_H_ */ diff --git a/libk/src/strlen.c b/src/lib/minic/strlen.c similarity index 96% rename from libk/src/strlen.c rename to src/lib/minic/strlen.c index 487a64a..76c4751 100644 --- a/libk/src/strlen.c +++ b/src/lib/minic/strlen.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include int strlen(const char *str) diff --git a/libk/src/strrev.c b/src/lib/minic/strrev.c similarity index 97% rename from libk/src/strrev.c rename to src/lib/minic/strrev.c index 7ed7813..02e3be2 100644 --- a/libk/src/strrev.c +++ b/src/lib/minic/strrev.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include char * strrev(char *str) diff --git a/srv/Makefile.am b/srv/Makefile.am new file mode 100644 index 0000000..2db0d8e --- /dev/null +++ b/srv/Makefile.am @@ -0,0 +1,9 @@ +exec_serverdir = \ + $(exec_prefix)/boot/srv +exec_server_PROGRAMS = + +LDADD = ../lib/crt0.o + +if ENABLE_FDOS +include fdos-src/Makefrag.am +endif diff --git a/srv/configfrag.ac b/srv/configfrag.ac new file mode 100644 index 0000000..e54ac16 --- /dev/null +++ b/srv/configfrag.ac @@ -0,0 +1,3 @@ +AC_ARG_ENABLE([fdos], + AS_HELP_STRING([--enable-fdos], [Build Fukuro DOS])) +AM_CONDITIONAL([ENABLE_FDOS], [test x"$enable_fdos" = xyes]) diff --git a/srv/fdos-src/Makefrag.am b/srv/fdos-src/Makefrag.am new file mode 100644 index 0000000..819c728 --- /dev/null +++ b/srv/fdos-src/Makefrag.am @@ -0,0 +1,4 @@ +fdos_SOURCES = \ + fdos-src/main.c + +exec_server_PROGRAMS += fdos \ No newline at end of file diff --git a/srv/fdos-src/main.c b/srv/fdos-src/main.c new file mode 100644 index 0000000..2603a70 --- /dev/null +++ b/srv/fdos-src/main.c @@ -0,0 +1,8 @@ + +int +main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + return (0); +} diff --git a/sys/Makefile.am b/sys/Makefile.am new file mode 100644 index 0000000..aacd905 --- /dev/null +++ b/sys/Makefile.am @@ -0,0 +1,30 @@ +fukuro_SOURCES = + +AM_LDFLAGS = -nostdlib -T$(srcdir)/$(systype)/linker.ld + +if HOST_aarch64 +include aarch64/Makefrag.am +endif + +if HOST_amd64 +include amd64/Makefrag.am +endif + +if HOST_arm +include arm/Makefrag.am +endif + +if HOST_i686 +include i686/Makefrag.am +endif + +if HOST_riscv +include riscv/Makefrag.am +endif + +fukuro_SOURCES += main.c + +exec_bootdir = \ + $(exec_prefix)/boot +exec_boot_PROGRAMS = \ + fukuro \ No newline at end of file diff --git a/sys/aarch64/Makefrag.am b/sys/aarch64/Makefrag.am new file mode 100644 index 0000000..e69de29 diff --git a/sys/amd64/Makefrag.am b/sys/amd64/Makefrag.am new file mode 100644 index 0000000..e69de29 diff --git a/sys/arm/Makefrag.am b/sys/arm/Makefrag.am new file mode 100644 index 0000000..1de782d --- /dev/null +++ b/sys/arm/Makefrag.am @@ -0,0 +1,2 @@ +fukuro_SOURCES += \ + arm/boot.S diff --git a/sys/arm/boot.S b/sys/arm/boot.S new file mode 100644 index 0000000..3e6e26f --- /dev/null +++ b/sys/arm/boot.S @@ -0,0 +1,24 @@ + .section ".text.boot" + + .extern __bss_begin + .extern __bss_end + .extern kmain + + .globl _entry +_entry: + + mov r0, #0 + ldr r1, =(__bss_begin) + ldr r2, =(__bss_end) + +1: + strt r0, [r1, #0] + add r1, #4 + cmp r2, r1 + bgt 1b + + bl kmain + nop + +hang: + b hang diff --git a/sys/arm/linker.ld b/sys/arm/linker.ld new file mode 100644 index 0000000..3af9af1 --- /dev/null +++ b/sys/arm/linker.ld @@ -0,0 +1,26 @@ +ENTRY(_entry) + +SECTIONS +{ + . = 0x8000; + + .text : ALIGN(4K) { + KEEP(*(.text.boot)) + *(.text) + } + + .rodata : ALIGN(4K) { + *(.rodata) + } + + .data : ALIGN(4K) { + *(.data) + } + + .bss : ALIGN(4K) { + *(.bss) + } + + PROVIDE(__bss_begin = ADDR(.bss)); + PROVIDE(__bss_end = ADDR(.bss) + SIZEOF(.bss)); +} \ No newline at end of file diff --git a/sys/configfrag.ac b/sys/configfrag.ac new file mode 100644 index 0000000..dbf7049 --- /dev/null +++ b/sys/configfrag.ac @@ -0,0 +1,5 @@ +AM_CONDITIONAL([HOST_aarch64], [test "$systype" = "aarch64"]) +AM_CONDITIONAL([HOST_amd64], [test "$systype" = "amd64"]) +AM_CONDITIONAL([HOST_arm], [test "$systype" = "arm"]) +AM_CONDITIONAL([HOST_i686], [test "$systype" = "i686"]) +AM_CONDITIONAL([HOST_riscv], [test "$systype" = "riscv"]) diff --git a/sys/i686/Makefrag.am b/sys/i686/Makefrag.am new file mode 100644 index 0000000..e69de29 diff --git a/sys/main.c b/sys/main.c new file mode 100644 index 0000000..3cdd278 --- /dev/null +++ b/sys/main.c @@ -0,0 +1,21 @@ +/* + * This file is part of Fukurō. + * + * Fukurō is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Fukurō is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Fukurō. If not, see . + */ + +void +kmain(void) +{ +} diff --git a/sys/riscv/Makefrag.am b/sys/riscv/Makefrag.am new file mode 100644 index 0000000..67163c5 --- /dev/null +++ b/sys/riscv/Makefrag.am @@ -0,0 +1,4 @@ +fukuro_SOURCES += \ + riscv/boot.S \ + riscv/trap.c \ + riscv/vector.S \ No newline at end of file diff --git a/sys/riscv/asm.h b/sys/riscv/asm.h new file mode 100644 index 0000000..819ab81 --- /dev/null +++ b/sys/riscv/asm.h @@ -0,0 +1,45 @@ +#ifndef FUKURO_SYS_RISCV_ASM_H +# define FUKURO_SYS_RISCV_ASM_H 1 + +# ifndef __ASSEMBLY__ + +# include + +typedef struct __attribute__((packed)) +{ + uint32_t ra; + uint32_t sp; + uint32_t gp; + uint32_t tp; + uint32_t t0; + uint32_t t1; + uint32_t t2; + uint32_t s0; + uint32_t s1; + uint32_t a0; + uint32_t a1; + uint32_t a2; + uint32_t a3; + uint32_t a4; + uint32_t a5; + uint32_t a6; + uint32_t a7; + uint32_t s2; + uint32_t s3; + uint32_t s4; + uint32_t s5; + uint32_t s6; + uint32_t s7; + uint32_t s8; + uint32_t s9; + uint32_t s10; + uint32_t s11; + uint32_t t3; + uint32_t t4; + uint32_t t5; + uint32_t t9; +} TrapFrame; + +# endif /* __ASSEMBLY__ */ + +#endif /* !FUKURO_SYS_RISCV_ASM_H */ diff --git a/sys/riscv/boot.S b/sys/riscv/boot.S new file mode 100644 index 0000000..d64b13d --- /dev/null +++ b/sys/riscv/boot.S @@ -0,0 +1,42 @@ +/* + * This file is part of Fukurō. + * + * Fukurō is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Fukurō is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Fukurō. If not, see . + */ + + .section ".text.boot" + + .extern __stack_top + .extern __bss_begin + .extern __bss_end + .extern kmain + + .globl _entry + +_entry: + la sp, __stack_top + + la t0, __bss_begin + la t1, __bss_end + + bltu t1, t0, 2f +1: + sw x0, (t0) + addi t0, t0, 4 + bltu t0, t1, 1b +2: + call kmain + +hang: + j hang diff --git a/sys/riscv/linker.ld b/sys/riscv/linker.ld new file mode 100644 index 0000000..d36515c --- /dev/null +++ b/sys/riscv/linker.ld @@ -0,0 +1,31 @@ +ENTRY(_entry) + +SECTIONS { + . = 0x80200000; + + .text :{ + KEEP(*(.text.boos)); + *(.text .text.*); + } + + .rodata : ALIGN(4) { + *(.rodata .text.*); + } + + .data : ALIGN(4) { + *(.data .data.*); + } + + .bss : ALIGN(4) { + *(.bss .bss.*); + *(COMMON); + } + + PROVIDE(__bss_begin = ADDR(.bss)); + PROVIDE(__bss_end = ADDR(.bss) + SIZEOF(.bss)); + + .stack (NOLOAD) : ALIGN(4) { + . += 0x4000; + PROVIDE(__stack_top = .); + } +} diff --git a/sys/riscv/trap.c b/sys/riscv/trap.c new file mode 100644 index 0000000..0136380 --- /dev/null +++ b/sys/riscv/trap.c @@ -0,0 +1,7 @@ +#include + +void +kernel_trap(TrapFrame *frame) +{ + (void)frame; +} diff --git a/sys/riscv/vector.S b/sys/riscv/vector.S new file mode 100644 index 0000000..9686c24 --- /dev/null +++ b/sys/riscv/vector.S @@ -0,0 +1,78 @@ + .section ".text" + .align 4 + + .extern kernel_trap + + .globl kernel_vec +kernel_vec: + addi sp, sp, -4 * 31 + + sw ra, 0(sp) + sw sp, 4 * 1(sp) + sw gp, 4 * 2(sp) + sw tp, 4 * 3(sp) + sw t0, 4 * 5(sp) + sw t1, 4 * 6(sp) + sw t2, 4 * 7(sp) + sw s0, 4 * 8(sp) + sw s1, 4 * 9(sp) + sw a0, 4 * 10(sp) + sw a1, 4 * 11(sp) + sw a2, 4 * 12(sp) + sw a3, 4 * 13(sp) + sw a4, 4 * 14(sp) + sw a5, 4 * 15(sp) + sw a6, 4 * 16(sp) + sw a7, 4 * 17(sp) + sw s2, 4 * 18(sp) + sw s3, 4 * 19(sp) + sw s4, 4 * 20(sp) + sw s5, 4 * 21(sp) + sw s6, 4 * 22(sp) + sw s7, 4 * 23(sp) + sw s8, 4 * 24(sp) + sw s9, 4 * 25(sp) + sw s10, 4 * 26(sp) + sw s11, 4 * 27(sp) + sw t3, 4 * 28(sp) + sw t4, 4 * 29(sp) + sw t5, 4 * 30(sp) + sw t9, 4 * 31(sp) + + call kernel_trap + + lw ra, 0(sp) + lw sp, 4 * 1(sp) + lw gp, 4 * 2(sp) + lw tp, 4 * 3(sp) + lw t0, 4 * 5(sp) + lw t1, 4 * 6(sp) + lw t2, 4 * 7(sp) + lw s0, 4 * 8(sp) + lw s1, 4 * 9(sp) + lw a0, 4 * 10(sp) + lw a1, 4 * 11(sp) + lw a2, 4 * 12(sp) + lw a3, 4 * 13(sp) + lw a4, 4 * 14(sp) + lw a5, 4 * 15(sp) + lw a6, 4 * 16(sp) + lw a7, 4 * 17(sp) + lw s2, 4 * 18(sp) + lw s3, 4 * 19(sp) + lw s4, 4 * 20(sp) + lw s5, 4 * 21(sp) + lw s6, 4 * 22(sp) + lw s7, 4 * 23(sp) + lw s8, 4 * 24(sp) + lw s9, 4 * 25(sp) + lw s10, 4 * 26(sp) + lw s11, 4 * 27(sp) + lw t3, 4 * 28(sp) + lw t4, 4 * 29(sp) + lw t5, 4 * 30(sp) + lw t9, 4 * 31(sp) + + addi sp, sp, 4 * 31 + + sret diff --git a/test/Kconfig b/test/Kconfig new file mode 100644 index 0000000..bd2abcb --- /dev/null +++ b/test/Kconfig @@ -0,0 +1,7 @@ +menu "Test" + +config WITH_COVERAGE + bool "With code coverage" + default y + +endmenu diff --git a/test/build.mk b/test/build.mk new file mode 100644 index 0000000..57e4406 --- /dev/null +++ b/test/build.mk @@ -0,0 +1,19 @@ +# vim: set tabstop=4:shiftwidth=4:noexpandtab + +TESTS_SRCS = itoa_test.c \ + memset_test.c \ + strlen_test.c \ + strrev_test.c \ + test.c + +TESTS_OBJS = $(addprefix $(TEST_BUILDDIR)/, $(TESTS_SRCS:.c=.o)) + +.PHONY: test +test: $(TESTS_OBJS) $(LIB_MINIC_TEST_OBJS) + $(CC) -o test.exe $^ $(TESTS_LDFLAGS) + @ ./test.exe + +$(TEST_BUILDDIR)/%.o: test/%.c + @ mkdir -p $(dir $@) + $(CC) -o $@ -c $< $(TESTS_CFLAGS) + diff --git a/libk/tests/itoa_test.c b/test/itoa_test.c similarity index 98% rename from libk/tests/itoa_test.c rename to test/itoa_test.c index 836b794..a97e94c 100644 --- a/libk/tests/itoa_test.c +++ b/test/itoa_test.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include #include #include diff --git a/libk/tests/memset_test.c b/test/memset_test.c similarity index 97% rename from libk/tests/memset_test.c rename to test/memset_test.c index 6b3061d..27dc788 100644 --- a/libk/tests/memset_test.c +++ b/test/memset_test.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include #include #include diff --git a/libk/tests/strlen_test.c b/test/strlen_test.c similarity index 97% rename from libk/tests/strlen_test.c rename to test/strlen_test.c index 45fb942..355f016 100644 --- a/libk/tests/strlen_test.c +++ b/test/strlen_test.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include #include #include diff --git a/libk/tests/strrev_test.c b/test/strrev_test.c similarity index 97% rename from libk/tests/strrev_test.c rename to test/strrev_test.c index 9fe6891..fdd2b13 100644 --- a/libk/tests/strrev_test.c +++ b/test/strrev_test.c @@ -15,7 +15,7 @@ * along with Fukurō. If not, see . */ -#include +#include #include #include diff --git a/libk/tests/test.c b/test/test.c similarity index 100% rename from libk/tests/test.c rename to test/test.c diff --git a/tools/build.mk b/tools/build.mk new file mode 100644 index 0000000..570e5c7 --- /dev/null +++ b/tools/build.mk @@ -0,0 +1,4 @@ +# vim: set tabstop=4:shiftwidth=4:noexpandtab + +CONFIG = $(addprefix $(TOOLSDIR)/, config.py) + diff --git a/scripts/build_toolchain.sh b/tools/build_toolchain.sh similarity index 98% rename from scripts/build_toolchain.sh rename to tools/build_toolchain.sh index 3b12058..5fabd16 100755 --- a/scripts/build_toolchain.sh +++ b/tools/build_toolchain.sh @@ -12,7 +12,7 @@ if [ -z ${BINUTILS_VERSION+x} ]; then BINUTILS_VERSION="2.35" fi -PREFIX="$(pwd)/toolchain" +PREFIX="$(pwd)/.toolchain" # XXX: quick fix if [ "$ARCH" = "arm" ]; then TARGET="$ARCH-none-eabi" diff --git a/tools/config.py b/tools/config.py new file mode 100755 index 0000000..e91486e --- /dev/null +++ b/tools/config.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + +# BSD 3-Clause License +# +# Copyright (c) 2021, The µnix Contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import sys +import kconfiglib +import menuconfig +import argparse + +kconfig = None +try: + kconfig = kconfiglib.Kconfig("Kconfig") +except kconfiglib.KconfigError as e: + print(e) + sys.exit(-1) + +def generate_header(dest): + kconfig.load_config('.config') + kconfig.write_autoconf( + dest, '#ifndef _FUKURO_CONFIG_H\n' + '#define _FUKURO_CONFIG_H\n\n') + # a bit hacky but there is no other way and I really hate '#pragma once' + with open(dest, 'a') as f: + f.write('\n#endif /* !_FUKURO_CONFIG_H */\n') + + +def generate_make(dest): + kconfig.load_config('.config') + kconfig.write_config(dest) + + +def defconfig(): + kconfig.write_config() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--genheader', action='store', default=None) + parser.add_argument('--genmake', action='store', default=None) + parser.add_argument('--menuconfig', action='store_true') + parser.add_argument('--defconfig', action='store_true') + args = parser.parse_args() + + if args.genheader is not None: + generate_header(args.genheader) + + if args.genmake is not None: + generate_make(args.genmake) + + if args.menuconfig: + menuconfig.menuconfig(kconfig) + + if args.defconfig: + defconfig() + diff --git a/scripts/format.sh b/tools/format.sh similarity index 100% rename from scripts/format.sh rename to tools/format.sh diff --git a/scripts/gen_iso.sh b/tools/gen_iso.sh similarity index 100% rename from scripts/gen_iso.sh rename to tools/gen_iso.sh