diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69454099..ddc9beec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,33 +16,33 @@ env: TEST_DIR: "${{ github.workspace }}/tests" jobs: - test: - runs-on: ubuntu-latest + # test: + # runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 + # steps: + # - uses: actions/checkout@v6 - - name: Install dependencies - run: sudo apt-get install -y build-essential gcc-multilib g++-multilib + # - name: Install dependencies + # run: sudo apt-get install -y build-essential gcc-multilib g++-multilib - - name: Install gcovr - run: pip install gcovr + # - name: Install gcovr + # run: pip install gcovr - - name: Setup project - run: cmake -S ${TEST_DIR} -B ${BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug + # - name: Setup project + # run: cmake -S ${TEST_DIR} -B ${BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug - - name: Build - run: cmake --build ${BUILD_DIR} + # - name: Build + # run: cmake --build ${BUILD_DIR} - # TODO reenable testing once arch. is stable again - # - name: Test - # working-directory: build - # run: ctest -V + # # TODO reenable testing once arch. is stable again + # # - name: Test + # # working-directory: build + # # run: ctest -V - # TODO re-enable this once coverage is complete - # - name: Test with Coverage - # working-directory: build - # run: cmake --build ${BUILD_DIR} --target os_test_coverage + # # TODO re-enable this once coverage is complete + # # - name: Test with Coverage + # # working-directory: build + # # run: cmake --build ${BUILD_DIR} --target os_test_coverage lint: runs-on: ubuntu-latest @@ -69,7 +69,9 @@ jobs: with: dry-run: ${{ github.ref != 'refs/heads/main' }} - needs: [test, lint] + needs: + # - test + - lint permissions: contents: write @@ -78,7 +80,10 @@ jobs: runs-on: ubuntu-latest if: always() - needs: [test, lint, increment_version] + needs: + # - test + - lint + - increment_version timeout-minutes: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5711e275..d1c548d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15..3.20) -set(CPU_ARCH i386) - +set(CROSS_ARCH i386-elf) +set(CROSS_GCC_VERSION 12.2.0) set(CROSS_PREFIX "$ENV{HOME}/.local/opt/cross") set(CMAKE_TOOLCHAIN_FILE cmake/toolchain.cmake) diff --git a/cmake/targets.cmake b/cmake/targets.cmake index 13949178..b7548f54 100644 --- a/cmake/targets.cmake +++ b/cmake/targets.cmake @@ -29,7 +29,7 @@ function(cross_target_binary target) ${TARGET_LINK_FILES} --end-group -nostdlib - "-L${CROSS_PREFIX}/lib/gcc/i386-elf/12.2.0" + "-L${CROSS_PREFIX}/lib/gcc/${CROSS_ARCH}/${CROSS_GCC_VERSION}" -lgcc DEPENDS ${target} ${TARGET_LINK_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/link.ld) @@ -44,7 +44,7 @@ function(cross_target_binary target) ${TARGET_LINK_FILES} --end-group -nostdlib - "-L${CROSS_PREFIX}/lib/gcc/i386-elf/12.2.0" + "-L${CROSS_PREFIX}/lib/gcc/${CROSS_ARCH}/${CROSS_GCC_VERSION}" -lgcc DEPENDS ${target} ${TARGET_LINK_FILES}) diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake index 8fb458f9..f8e5e070 100644 --- a/cmake/toolchain.cmake +++ b/cmake/toolchain.cmake @@ -1,20 +1,22 @@ # set(CMAKE_SYSTEM_NAME Generic-ELF) set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR i386-elf) -set(CMAKE_SYSTEM_VERSION 12.2.0) +set(CMAKE_SYSTEM_PROCESSOR ${CROSS_ARCH}) +# TODO: does this do anything? +#set(CMAKE_SYSTEM_VERSION 12.2.0) +set(CMAKE_SYSTEM_VERSION ${CROSS_GCC_VERSION}) # set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf) -set(CMAKE_C_COMPILER ${CROSS_PREFIX}/bin/i386-elf-gcc) +set(CMAKE_C_COMPILER ${CROSS_PREFIX}/bin/${CROSS_ARCH}-gcc) set(CMAKE_C_FLAGS "-g -Werror -ffreestanding") set(CMAKE_C_COMPILER_WORKS 1) -set(CMAKE_CXX_COMPILER ${CROSS_PREFIX}/bin/i386-elf-g++) +set(CMAKE_CXX_COMPILER ${CROSS_PREFIX}/bin/${CROSS_ARCH}-g++) set(CMAKE_CXX_FLAGS "-g -Werror -ffreestanding") set(CMAKE_CXX_COMPILER_WORKS 1) -set(CMAKE_AR "${CROSS_PREFIX}/bin/i386-elf-ar" CACHE FILEPATH "" FORCE) +set(CMAKE_AR "${CROSS_PREFIX}/bin/${CROSS_ARCH}-ar" CACHE FILEPATH "" FORCE) -set(CMAKE_LINKER "${CROSS_PREFIX}/bin/i386-elf-ld") +set(CMAKE_LINKER "${CROSS_PREFIX}/bin/${CROSS_ARCH}-ld") set(CMAKE_LINKER_FLAGS "HELLO WORLD") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) diff --git a/install_cross.sh b/install_cross.sh index 2dde837e..6c416545 100755 --- a/install_cross.sh +++ b/install_cross.sh @@ -2,45 +2,61 @@ set -e -CROSS_PREFIX=${CROSS_PREFIX:-${HOME}/.local/opt/cross} FORCE_DOWNLOAD=${FORCE_DOWNLOAD:-} -CROSS_ARCH=i386-elf -CROSS_BUILD=${PWD}/cross-build/${CROSS_ARCH} - # Make parallel -J="" +J=${J:-} # J="-j" # J="-j128" -export PREFIX=${CROSS_PREFIX} -export TARGET=i386-elf -export PATH=${CROSS_PREFIX}/bin:$PATH - -BINUTILS_VERSION=2.40 -BINUTILS_URL="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.xz" +export PREFIX=${PREFIX:-"$HOME/.local/opt/cross"} +export TARGET=${TARGET:-i386-elf} +export PATH="${PREFIX}/bin:$PATH" -GCC_VERSION=12.2.0 -GCC_URL="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz" +BINUTILS_VERSION=${BINUTILS_VERSION:-"2.40"} +GCC_VERSION=${GCC_VERSION:-"12.2.0"} +GDB_VERSION=${GDB_VERSION:-"11.1"} -GDB_VERSION=11.1 -GDB_URL="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz" +CROSS_BUILD=${PWD}/cross-build COLOR_GREEN="\033[0;32m" COLOR_BLUE="\033[0;34m" COLOR_WHITE="\033[1;37m" COLOR_RESET="\033[0m" - -echo_section() { - echo -e "${COLOR_BLUE}:: ${COLOR_WHITE}$*${COLOR_RESET}" -} - -echo_task() { - echo -e "${COLOR_GREEN}==> ${COLOR_WHITE}$*${COLOR_RESET}" -} - -echo_step() { - echo -e " ${COLOR_BLUE} -> ${COLOR_RESET}$*" +echo_section() { echo -e "${COLOR_BLUE}:: ${COLOR_WHITE}$*${COLOR_RESET}"; } +echo_task() { echo -e "${COLOR_GREEN}==> ${COLOR_WHITE}$*${COLOR_RESET}"; } +echo_step() { echo -e " ${COLOR_BLUE} -> ${COLOR_RESET}$*"; } + +echo_section Building with Configuration + +echo PREFIX=${PREFIX} +echo TARGET=${TARGET} +echo J=${J} +echo FORCE_DOWNLOAD=${FORCE_DOWNLOAD} +echo BINUTILS_VERSION=${BINUTILS_VERSION} +echo GCC_VERSION=${GCC_VERSION} +echo GDB_VERSION=${GDB_VERSION} +echo CROSS_BUILD=${CROSS_BUILD} + +install_dependencies() { + echo_section "Installing dependencies" + + echo_step "Updating package cache" + sudo apt-get update >/dev/null + + echo_step "Installing dependencies" + sudo apt-get install -y \ + build-essential \ + wget \ + gcc \ + xz-utils \ + bison \ + flex \ + libgmp3-dev \ + libgmp-dev \ + libmpfr-dev \ + texinfo \ + >/dev/null } download_and_extract() { @@ -50,39 +66,43 @@ download_and_extract() { echo_task Fetch ${name} from ${url} + cd "${CROSS_BUILD}" + if [ ! -e ${name} ] || [ ! -z ${FORCE_DOWNLOAD} ]; then echo_step "Downloading ${url}" wget -O ${name} ${url} + else + echo_step "Archive ${name} already exists" fi - if [ ! -e ${1} ] || [ ! -z ${FORCE_DOWNLOAD} ] || [ -z ${FORCE_EXTRACT} ]; then + if [ ! -e ${1} ] || [ ! -z ${FORCE_DOWNLOAD} ]; then echo_step "Extracting ${name}" tar -xf ${name} + else + echo_step "Source directory ${1} already exists" fi } install_binutils() { local name build_dir name=binutils-${BINUTILS_VERSION} - build_dir=i386-${name}-build + build_dir=build-${TARGET} echo_section "Build & Install ${name}" - download_and_extract ${name} ${BINUTILS_URL} - - cd ${name} + cd "${CROSS_BUILD}/${name}" echo_task "Creating build dir ${build_dir}" # Create temporary build dir - mkdir -p ${build_dir} - cd ${build_dir} + mkdir -p "${build_dir}" + cd "${build_dir}" echo_task Configure project ../configure \ - --prefix="${CROSS_PREFIX}" \ - --target=i386-elf \ + --prefix="${PREFIX}" \ + --target=${TARGET} \ --with-sysroot \ --disable-nls \ --disable-werror \ @@ -107,113 +127,111 @@ install_binutils() { echo_task "Finished ${name}" } -install_gcc() { +install_gdb() { local name build_dir - name=gcc-${GCC_VERSION} - build_dir=i386-${name}-build + name=gdb-${GDB_VERSION} + build_dir=build-${TARGET} echo_section "Build & Install ${name}" - download_and_extract ${name} ${GCC_URL} + download_and_extract ${name} ${GDB_URL} cd ${name} - echo_task Installing project dependencies - - ./contrib/download_prerequisites - echo_task "Creating build dir ${build_dir}" # Create temporary build dir - mkdir -p ${build_dir} - cd ${build_dir} + mkdir -p "${build_dir}" + cd "${build_dir}" echo_task Configure project ../configure \ - --prefix="$PREFIX" \ - --target=i386-elf \ - --disable-nls \ - --disable-werror \ - --disable-multilib \ - --without-headers \ - --enable-languages=c,c++ + --target=${TARGET} \ + --prefix="${PREFIX}" echo_task Building... # Build - make all-gcc - make all-target-libgcc + make ${J} echo_task Installing... # Package - make ${J} install-gcc - make ${J} install-target-libgcc + make install echo_task "Finished ${name}" } -install_gdb() { +install_gcc() { local name build_dir - name=gdb-${GDB_VERSION} - build_dir=i386-${name}-build + name=gcc-${GCC_VERSION} + build_dir=build-${TARGET} echo_section "Build & Install ${name}" - download_and_extract ${name} ${GDB_URL} + cd "${CROSS_BUILD}/${name}" - cd ${name} + echo_task Installing project dependencies + + ./contrib/download_prerequisites echo_task "Creating build dir ${build_dir}" # Create temporary build dir - mkdir -p ${build_dir} - cd ${build_dir} + mkdir -p "${build_dir}" + cd "${build_dir}" echo_task Configure project ../configure \ - --target=i386-elf \ - --prefix="$PREFIX" \ - --program-prefix=i386-elf- + --prefix="${PREFIX}" \ + --target=${TARGET} \ + --disable-nls \ + --disable-werror \ + --disable-multilib \ + --without-headers \ + --enable-languages=c,c++ echo_task Building... # Build - make ${J} + make all-gcc ${J} + make all-target-libgcc ${J} echo_task Installing... # Package - make install + make install-gcc + make install-target-libgcc echo_task "Finished ${name}" } START_TIME=${SECONDS} +install_dependencies + echo_section "Create directories" -echo_step "Create cross target install prefix ${CROSS_PREFIX}" -mkdir -p ${CROSS_PREFIX} +echo_step "Create cross target install prefix ${PREFIX}" +mkdir -p ${PREFIX} echo_step "Create cross target build directory ${CROSS_BUILD}" mkdir -p ${CROSS_BUILD} echo '*' > ${CROSS_BUILD}/.gitignore +echo_step "Enter cross target build directory ${CROSS_BUILD}" cd ${CROSS_BUILD} -echo_section "Installing dependencies..." - -echo_step "Updating package cache" -sudo apt-get update >/dev/null +echo_section "Downloading Source" -echo_step "Installing dependencies" -sudo apt-get install -y wget gcc xz-utils texinfo libgmp-dev >/dev/null +download_and_extract binutils-${BINUTILS_VERSION} "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz" +download_and_extract gdb-${GDB_VERSION} "https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz" +download_and_extract gcc-${GCC_VERSION} "https://ftp.gnu.org/gnu/gcc/gcc-16.1.0/gcc-${GCC_VERSION}.tar.xz" -# install_binutils -# install_gdb +install_binutils +install_gdb install_gcc ELAPSED=$((SECONDS - START_TIME)) diff --git a/src/cpu/CMakeLists.txt b/src/cpu/CMakeLists.txt index 2e08f4f5..ac7b9420 100644 --- a/src/cpu/CMakeLists.txt +++ b/src/cpu/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET cpu) -add_subdirectory(${CPU_ARCH}) # defined in root CMakeLists.txt +add_subdirectory(${CROSS_ARCH}) # defined in root CMakeLists.txt target_link_libraries(${TARGET} libc util kernel) target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/src/cpu/i386/CMakeLists.txt b/src/cpu/i386-elf/CMakeLists.txt similarity index 100% rename from src/cpu/i386/CMakeLists.txt rename to src/cpu/i386-elf/CMakeLists.txt diff --git a/src/cpu/i386/src/cpu.asm b/src/cpu/i386-elf/src/cpu.asm similarity index 100% rename from src/cpu/i386/src/cpu.asm rename to src/cpu/i386-elf/src/cpu.asm diff --git a/src/cpu/i386/src/gdt.c b/src/cpu/i386-elf/src/gdt.c similarity index 100% rename from src/cpu/i386/src/gdt.c rename to src/cpu/i386-elf/src/gdt.c diff --git a/src/cpu/i386/src/idt.c b/src/cpu/i386-elf/src/idt.c similarity index 100% rename from src/cpu/i386/src/idt.c rename to src/cpu/i386-elf/src/idt.c diff --git a/src/cpu/i386/src/interrupt.asm b/src/cpu/i386-elf/src/interrupt.asm similarity index 100% rename from src/cpu/i386/src/interrupt.asm rename to src/cpu/i386-elf/src/interrupt.asm diff --git a/src/cpu/i386/src/isr.c b/src/cpu/i386-elf/src/isr.c similarity index 100% rename from src/cpu/i386/src/isr.c rename to src/cpu/i386-elf/src/isr.c diff --git a/src/cpu/i386/src/mmu.c b/src/cpu/i386-elf/src/mmu.c similarity index 100% rename from src/cpu/i386/src/mmu.c rename to src/cpu/i386-elf/src/mmu.c diff --git a/src/cpu/i386/src/paging.asm b/src/cpu/i386-elf/src/paging.asm similarity index 100% rename from src/cpu/i386/src/paging.asm rename to src/cpu/i386-elf/src/paging.asm diff --git a/src/cpu/i386/src/ports.asm b/src/cpu/i386-elf/src/ports.asm similarity index 100% rename from src/cpu/i386/src/ports.asm rename to src/cpu/i386-elf/src/ports.asm diff --git a/src/cpu/i386/src/tss.c b/src/cpu/i386-elf/src/tss.c similarity index 100% rename from src/cpu/i386/src/tss.c rename to src/cpu/i386-elf/src/tss.c diff --git a/tests/src/cpu/CMakeLists.txt b/tests/src/cpu/CMakeLists.txt index 8e88efdd..35b396b2 100644 --- a/tests/src/cpu/CMakeLists.txt +++ b/tests/src/cpu/CMakeLists.txt @@ -1,11 +1,11 @@ unit_test( TARGET test_mmu TEST_FILES test_mmu.cpp - TARGET_FILES cpu/i386/src/mmu.c + TARGET_FILES cpu/i386-elf/src/mmu.c ) unit_test( TARGET test_gdt TEST_FILES test_gdt.cpp - TARGET_FILES cpu/i386/src/gdt.c + TARGET_FILES cpu/i386-elf/src/gdt.c )