From d262af06a642cc8c740b369ca3d173a1b272fb3f Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Mon, 20 Nov 2023 02:50:12 +0100 Subject: [PATCH] reworking runtime, updating project structure. --- CMakeLists.txt | 9 ++++++--- LICENSE | 2 +- include/CMakeLists.txt | 3 +++ include/based/CMakeLists.txt | 2 ++ src/based/CMakeLists.txt | 1 + src/cli/CMakeLists.txt | 4 ++-- src/runtime/CMakeLists.txt | 2 +- src/runtime/rtinternal.h | 4 ++-- src/runtime/runtime.c | 2 +- src/runtime/system/unix/crt.S | 8 ++++++-- src/runtime/system/unix/unixrt.c | 4 ++-- tests/CMakeLists.txt | 3 +++ tests/HelloWorld/CMakeLists.txt | 5 +++++ tests/HelloWorld/main.c | 9 +++++++++ 14 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 include/CMakeLists.txt create mode 100644 include/based/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/HelloWorld/CMakeLists.txt create mode 100644 tests/HelloWorld/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33a2b9b..41bb90a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,10 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJ_DEB_BUILD_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJ_DEB_BUILD_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJ_DEB_BUILD_DIR}/bin) +add_subdirectory(src) +add_subdirectory(include) +add_subdirectory(tests) + if (DOCUMENTATION) -add_subdirectory(doc) -endif(DOCUMENTATION) -add_subdirectory(src) \ No newline at end of file + add_subdirectory(doc) +endif(DOCUMENTATION) \ No newline at end of file diff --git a/LICENSE b/LICENSE index f73edbb..e1fd273 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Max +Copyright (c) 2023 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..dea8318 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,3 @@ +# Public include + +add_subdirectory(based) \ No newline at end of file diff --git a/include/based/CMakeLists.txt b/include/based/CMakeLists.txt new file mode 100644 index 0000000..7c6a618 --- /dev/null +++ b/include/based/CMakeLists.txt @@ -0,0 +1,2 @@ +# Public based include + diff --git a/src/based/CMakeLists.txt b/src/based/CMakeLists.txt index 4989986..e6fb62b 100755 --- a/src/based/CMakeLists.txt +++ b/src/based/CMakeLists.txt @@ -3,6 +3,7 @@ add_library(based SHARED "base.c") target_compile_features(based PRIVATE c_std_99) +target_link_libraries(based PUBLIC runtime) target_include_directories(based PUBLIC diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index c997610..4659da6 100755 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,5 +1,5 @@ # cli project -add_executable(basedcli "main.c") +add_executable(bcli "main.c") -target_link_libraries(basedcli runtime) \ No newline at end of file +target_link_libraries(bcli PUBLIC based) \ No newline at end of file diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 0e6e4db..9038b01 100755 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -4,7 +4,7 @@ add_library(runtime STATIC "rtinternal.h" "runtime.c") -target_link_libraries(runtime PUBLIC based) +#target_link_libraries(runtime PUBLIC based) target_include_directories(runtime PUBLIC diff --git a/src/runtime/rtinternal.h b/src/runtime/rtinternal.h index 010f733..44c9b0b 100755 --- a/src/runtime/rtinternal.h +++ b/src/runtime/rtinternal.h @@ -1,3 +1,3 @@ -#include "base.h" +//#include "base.h" -extern int main(int argc, BYTE** argv, BYTE** envp); +extern int main(int argc, char** argv, char** envp); diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 39912b8..e2b2d49 100755 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -5,5 +5,5 @@ int rt_bootstrap(void) // Bootstraping => based. // Invoke main. // Return exit code to caller. - return 420; + return 0; } \ No newline at end of file diff --git a/src/runtime/system/unix/crt.S b/src/runtime/system/unix/crt.S index 77109ab..634fbf1 100755 --- a/src/runtime/system/unix/crt.S +++ b/src/runtime/system/unix/crt.S @@ -9,9 +9,13 @@ _start: xor %rbp, %rbp // Clear stack frame pointer - mov (%rsp), %rdi // Movq argc to rdi + mov (%rsp), %rdi // Mov argc to rdi lea 0x8(%rsp), %rsi // Get the argv address lea 16(%rsp,%rdi,8), %rdx // Get the envp address - call rt_unix_start // Start c function + //call rt_unix_start // Start c function + // Use exit_group syscall + movq $231, %rax + movq $0, %rdi + syscall hlt // Halt if the lib or app does not call the exit function. \ No newline at end of file diff --git a/src/runtime/system/unix/unixrt.c b/src/runtime/system/unix/unixrt.c index b75485f..90351f8 100755 --- a/src/runtime/system/unix/unixrt.c +++ b/src/runtime/system/unix/unixrt.c @@ -1,6 +1,6 @@ -#include "base.h" +//#include "base.h" -void rt_unix_start(int argc, BYTE** argv, BYTE** envp) +void rt_unix_start(int argc, char** argv, char** envp) { //TODO: Callback => main & syscall to exit group } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..382b37e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +# CMakeLists test directory + +add_subdirectory(HelloWorld) \ No newline at end of file diff --git a/tests/HelloWorld/CMakeLists.txt b/tests/HelloWorld/CMakeLists.txt new file mode 100644 index 0000000..d4a0f60 --- /dev/null +++ b/tests/HelloWorld/CMakeLists.txt @@ -0,0 +1,5 @@ +# Hello World! test + +add_executable(hello "main.c") + +target_link_libraries(hello PUBLIC based) \ No newline at end of file diff --git a/tests/HelloWorld/main.c b/tests/HelloWorld/main.c new file mode 100644 index 0000000..7b28c7d --- /dev/null +++ b/tests/HelloWorld/main.c @@ -0,0 +1,9 @@ +// +// Created by max on 20-11-23. +// + +int main() +{ + //TODO: Print hello world! + return 0; +} \ No newline at end of file