From 0f52c02435b9861b9e7c4d46c2d8705408ea8aeb Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 20 Apr 2023 23:16:17 +0200 Subject: [PATCH] feature (build system): setup a build system --- .gitignore | 2 ++ CMakeLists.txt | 25 ++++++++++++++++++++++ build.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/asm/syscall.asm | 18 ++++++++++++++++ src/libc.c | 1 + 5 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100755 build.sh create mode 100644 src/asm/syscall.asm create mode 100644 src/libc.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ccba53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cmake-build-debug +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7ad14b4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.00) +project(libc) +set(C 99) + +set(CMAKE_NASM_COMPILE_OBJECT "nasm -o ") + + +add_library(libc) +add_library(libc_asm OBJECT) +target_include_directories(libc PRIVATE inc) +file(GLOB_RECURSE libc_src_c "src/**/*.c") +file(GLOB_RECURSE libc_inc "inc/**/*.h") +file(GLOB_RECURSE libc_src_asm "src/**/*.asm") + + +target_compile_options(libc PRIVATE "-g -fno-stack-protector -fno-stack-check -ffreestanding -m64 -march=x86-64 -mabi=sysv") +target_link_options(libc PRIVATE "-Bsymbolic -nostdlib -shared -fno-stack-protector") + +enable_language(ASM_NASM) +set(CAN_USE_ASSEMBLER TRUE) +set_target_properties(libc PROPERTIES PREFIX "") +set_target_properties(libc PROPERTIES SUFFIX ".so") + +target_sources(libc_asm PRIVATE ${libc_src_asm}) +target_sources(libc PRIVATE ${libc_src_c} ${libc_inc} $) \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..c526dd2 --- /dev/null +++ b/build.sh @@ -0,0 +1,52 @@ +#!/usr/bin/bash + +# This file is part of noxos and licensed under the MIT open source license + +set -e + +workspace_setup() { + echo " --> Setting up workspace" + mkdir -pv build + mkdir -pv build/cmake + echo "" +} + +check_toolchain() { + echo " --> Checking Toolchain" + hash gcc + echo " |--> found gcc" + hash ld + echo " |--> found ld" + hash nasm + echo " |--> found nasm" + hash cmake + echo " |--> found cmake" + + echo " --> All checks passed" +} + + +libc_build() { + echo " --> Building the noxos standard library" + cd build/cmake + cmake -S ../.. -B . + make + cd ../.. + echo "" +} + + +echo "!=====[ NoxOS libc build script ]=====!" + +case $1 in + "check") + check_toolchain + ;; + *) + workspace_setup + libc_build + ;; +esac + +echo "!=====[ Finished ]=====!" + diff --git a/src/asm/syscall.asm b/src/asm/syscall.asm new file mode 100644 index 0000000..ea15ccc --- /dev/null +++ b/src/asm/syscall.asm @@ -0,0 +1,18 @@ +; This file is part of noxos and licensed under the MIT open source license + +syscall_perform: + ; set the interrupt ID + mov rax, rdi + + ; set the arguments + mov rdi, rsi + mov rsi, rdx + mov rdx, rcx + mov rcx, r8 + + int 0x80 + + ; the return value is already set in RAX + + ret +GLOBAL syscall_perform \ No newline at end of file diff --git a/src/libc.c b/src/libc.c new file mode 100644 index 0000000..b92bff6 --- /dev/null +++ b/src/libc.c @@ -0,0 +1 @@ +// This file is part of noxos and licensed under the MIT open source license