diff --git a/CMakeLists.txt b/CMakeLists.txt index b14ad4b8..23c53e13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,5 +16,9 @@ set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64) set(CMAKE_FIND_ROOT_PATH ${LUNA_ROOT}/toolchain/x86-64-luna) +set(ARCH $ENV{ARCH}) + +message(STATUS "Configuring Luna for ${ARCH}") + add_subdirectory(luna) add_subdirectory(kernel) \ No newline at end of file diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 304f59a5..0db461df 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -6,7 +6,7 @@ set(SOURCES src/arch/Serial.cpp ) -# x86-64 specific +if("${ARCH}" MATCHES "x86_64") set(SOURCES ${SOURCES} src/arch/x86_64/IO.cpp @@ -14,17 +14,26 @@ set(SOURCES src/arch/x86_64/MMU.cpp src/arch/x86_64/CPU.cpp ) +endif() -# x86-64 specific +set(ASM_SOURCES) + +if("${ARCH}" MATCHES "x86_64") set(ASM_SOURCES + ${ASM_SOURCES} src/arch/x86_64/CPU.asm ) add_library(moon-asm STATIC ${ASM_SOURCES}) +endif() add_executable(moon ${SOURCES}) -target_link_libraries(moon moon-asm luna-freestanding) +if("${ARCH}" MATCHES "x86_64") +target_link_libraries(moon moon-asm) +endif() + +target_link_libraries(moon luna-freestanding) target_compile_definitions(moon PRIVATE IN_MOON) @@ -38,14 +47,16 @@ target_compile_options(moon PRIVATE -fno-rtti -ffreestanding -fno-exceptions) target_compile_options(moon PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) target_compile_options(moon PRIVATE -nostdlib -mcmodel=kernel) -# x86-64 specific +if("${ARCH}" MATCHES "x86_64") target_compile_options(moon PRIVATE -mno-red-zone) target_compile_options(moon PRIVATE -mno-80387 -mno-mmx -mno-sse -mno-sse2) +endif() target_link_options(moon PRIVATE -lgcc -Wl,--build-id=none -z max-page-size=0x1000 -mcmodel=kernel) -# x86-64 specific +if("${ARCH}" MATCHES "x86_64") target_link_options(moon PRIVATE -mno-red-zone) +endif() set_target_properties(moon PROPERTIES CXX_STANDARD 20) diff --git a/luna/CMakeLists.txt b/luna/CMakeLists.txt index 54f2f78d..7481c08b 100644 --- a/luna/CMakeLists.txt +++ b/luna/CMakeLists.txt @@ -19,9 +19,10 @@ target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-e target_compile_options(luna-freestanding PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel) -# x86-64 specific +if("${ARCH}" MATCHES "x86_64") target_compile_options(luna-freestanding PRIVATE -mno-red-zone) target_compile_options(luna-freestanding PRIVATE -mno-80387 -mno-mmx -mno-sse -mno-sse2) +endif() target_include_directories(luna-freestanding PUBLIC ${LUNA_ROOT}/luna) set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20) diff --git a/tools/build-iso.sh b/tools/build-iso.sh index ac9c3c6e..168b75ac 100755 --- a/tools/build-iso.sh +++ b/tools/build-iso.sh @@ -9,12 +9,9 @@ tools/setup.sh #tools/install-headers.sh -mkdir -p build -if [ "$USE_NINJA" = "1" ] -then -cmake -S . -B build -G Ninja -fi -cmake --build build -cmake --install build +mkdir -p $BUILD_DIR +cmake -S . -B $BUILD_DIR -G "$CMAKE_GEN" +cmake --build $BUILD_DIR +cmake --install $BUILD_DIR mkbootimg luna.json Luna.iso \ No newline at end of file diff --git a/tools/build.sh b/tools/build.sh index b5855836..ee07e209 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -9,9 +9,6 @@ tools/setup.sh #tools/install-headers.sh -mkdir -p build -if [ "$USE_NINJA" = "1" ] -then -cmake -S . -B build -G Ninja -fi -cmake --build build \ No newline at end of file +mkdir -p $BUILD_DIR +cmake -S . -B $BUILD_DIR -G "$CMAKE_GEN" +cmake --build $BUILD_DIR \ No newline at end of file diff --git a/tools/clean.sh b/tools/clean.sh index e005b12c..6d9139c6 100755 --- a/tools/clean.sh +++ b/tools/clean.sh @@ -3,6 +3,6 @@ set -e source $(dirname $0)/env.sh -cd $LUNA_ROOT +cd $BUILD_DIR -make clean \ No newline at end of file +$BUILD clean \ No newline at end of file diff --git a/tools/debug.sh b/tools/debug.sh index ad05afad..9623df96 100755 --- a/tools/debug.sh +++ b/tools/debug.sh @@ -3,4 +3,4 @@ set -e source $(dirname $0)/env.sh -qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -d int,cpu_reset -s $@ \ No newline at end of file +qemu-system-$ARCH -cdrom Luna.iso -smp 1 -m 256M -serial stdio -d int,cpu_reset -s $@ \ No newline at end of file diff --git a/tools/env.sh b/tools/env.sh index 6d99f72b..7b21c968 100755 --- a/tools/env.sh +++ b/tools/env.sh @@ -3,4 +3,17 @@ export LUNA_ROOT=${LUNA_ROOT:-$(realpath $(dirname $0)/..)} export LUNA_BASE=${LUNA_BASE:-$LUNA_ROOT/base} export PATH=$LUNA_ROOT/toolchain/x86-64-luna/bin:$LUNA_ROOT/toolchain/dist:$PATH -[ -f "$LUNA_ROOT/env-local.sh" ] && source $LUNA_ROOT/env-local.sh \ No newline at end of file +[ -f "$LUNA_ROOT/env-local.sh" ] && source $LUNA_ROOT/env-local.sh + +export ARCH=${ARCH:-x86_64} + +if [ "$USE_NINJA" = "1" ] +then +export BUILD=ninja +export CMAKE_GEN=Ninja +else +export BUILD=make +export CMAKE_GEN="Unix Makefiles" +fi + +export BUILD_DIR=$LUNA_ROOT/build/$BUILD-$ARCH \ No newline at end of file diff --git a/tools/fast-run.sh b/tools/fast-run.sh index 1d9f21c3..49f43dd9 100755 --- a/tools/fast-run.sh +++ b/tools/fast-run.sh @@ -5,4 +5,4 @@ source $(dirname $0)/env.sh cd $LUNA_ROOT -qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm $@ \ No newline at end of file +qemu-system-$ARCH -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm $@ \ No newline at end of file diff --git a/tools/install-built-ports.sh b/tools/install-built-ports.sh deleted file mode 100755 index 8e21fbc4..00000000 --- a/tools/install-built-ports.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -set -e - -source $(dirname $0)/env.sh - -cd $LUNA_ROOT/ports - -unset_vars() -{ - unset pkgname - unset pkgver - unset pkgurl - unset pkgmode - unset setupdir - unset builddir - unset installdir - unset srcdir - unset port_unpack - unset port_patch - unset port_configure - unset port_build - unset port_install - unset port_uninstall - unset islib -} - -if ! [ -f ./ports.list ] -then - echo "No ports built." - exit 0 -fi - -install_port() -{ - unset_vars - cd $LUNA_ROOT/ports - export DESTDIR=${DESTDIR:-"$LUNA_ROOT/initrd"} - export portdir=$PWD/$1 - export workdir=$portdir/workdir - source $portdir/package.sh - if ! [ "$islib" = "1" ] - then - echo "installing port: $pkgname version $pkgver" - mkdir -p $installdir - cd $installdir - port_install | filter-lines $pkgname "install" - fi -} - -while read package; do - install_port $package -done < ./ports.list diff --git a/tools/install.sh b/tools/install.sh index 99247915..73a507f6 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -5,4 +5,4 @@ source $(dirname $0)/env.sh cd $LUNA_ROOT -cmake --install build \ No newline at end of file +cmake --install $BUILD_DIR \ No newline at end of file diff --git a/tools/rebuild-iso.sh b/tools/rebuild-iso.sh index fb38d5b3..8537e980 100755 --- a/tools/rebuild-iso.sh +++ b/tools/rebuild-iso.sh @@ -7,11 +7,12 @@ cd $LUNA_ROOT tools/setup.sh -make clean +cd $BUILD_DIR +$BUILD clean +cd - -tools/install-headers.sh - -make -j$(nproc) -make install +cmake -S . -B $BUILD_DIR -G "$CMAKE_GEN" +cmake --build $BUILD_DIR +cmake --install $BUILD_DIR mkbootimg luna.json Luna.iso \ No newline at end of file diff --git a/tools/rebuild.sh b/tools/rebuild.sh index ee3649b0..cff4de9a 100755 --- a/tools/rebuild.sh +++ b/tools/rebuild.sh @@ -7,8 +7,9 @@ cd $LUNA_ROOT tools/setup.sh -tools/install-headers.sh +cd $BUILD_DIR +$BUILD clean +cd - -make clean - -make -j$(nproc) \ No newline at end of file +cmake -S . -B $BUILD_DIR -G "$CMAKE_GEN" +cmake --build $BUILD_DIR \ No newline at end of file diff --git a/tools/sync-libc.sh b/tools/sync-libc.sh deleted file mode 100755 index cf6df110..00000000 --- a/tools/sync-libc.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e -source $(dirname $0)/env.sh - -cd $LUNA_ROOT - -tools/install-headers.sh - -cd libs/ - -$LUNA_ROOT/tools/buildstep.sh libc build -$LUNA_ROOT/tools/buildstep.sh libc install \ No newline at end of file