From b1a281434816eccca8523b75f9ed8ebfadce9967 Mon Sep 17 00:00:00 2001 From: Maxim Logaev Date: Mon, 18 Nov 2024 13:04:06 +0300 Subject: [PATCH] toolchain: Added basic support for KolibriOS Signed-off-by: Maxim Logaev --- .gitignore | 4 ++ build-toolchain.sh | 38 ++++++++++ scripts/end-recipe | 32 +++++++++ scripts/start-recipe | 17 +++++ toolchain/binutils/bfd/config.bfd | 5 ++ toolchain/binutils/binutils/configure | 4 +- toolchain/binutils/config.sub | 6 +- toolchain/binutils/gas/configure.tgt | 1 + toolchain/binutils/kos-recipe.sh | 38 ++++++++++ toolchain/binutils/ld/configure.tgt | 3 + toolchain/gcc/config.sub | 6 +- toolchain/gcc/fixincludes/mkfixinc.sh | 1 + toolchain/gcc/gcc/config.gcc | 23 ++++++ toolchain/gcc/gcc/config/i386/cygming.h | 8 ++- toolchain/gcc/gcc/config/i386/kolibrios.h | 77 +++++++++++++++++++++ toolchain/gcc/gcc/config/i386/kolibrios.opt | 51 ++++++++++++++ toolchain/gcc/gcc/configure | 2 +- toolchain/gcc/kos-recipe.sh | 51 ++++++++++++++ toolchain/gcc/libgcc/config.host | 3 + 19 files changed, 364 insertions(+), 6 deletions(-) create mode 100755 build-toolchain.sh create mode 100644 scripts/end-recipe create mode 100644 scripts/start-recipe create mode 100755 toolchain/binutils/kos-recipe.sh create mode 100644 toolchain/gcc/gcc/config/i386/kolibrios.h create mode 100644 toolchain/gcc/gcc/config/i386/kolibrios.opt create mode 100755 toolchain/gcc/kos-recipe.sh diff --git a/.gitignore b/.gitignore index 259148fa18..68ae0dbca0 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ *.exe *.out *.app + +# Build dirs +toolchain/binutils/build +toolchain/gcc/build diff --git a/build-toolchain.sh b/build-toolchain.sh new file mode 100755 index 0000000000..25fa79c248 --- /dev/null +++ b/build-toolchain.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Copyright (C) KolibriOS-NG team 2024. All rights reserved +# Distributed under terms of the GNU General Public License + +source scripts/start-recipe + +ROOT_DIR="$PWD" +PATH=$PATH:"$SDK_TOOLCHAIN_DIR/bin" + +declare -a DIRS=( + "toolchain/binutils" + "toolchain/gcc" +) + +BUILD() +{ + for dir in "${DIRS[@]}" ; do + cd "$ROOT_DIR/$dir" + ./kos-recipe.sh + done +} + +INSTALL() +{ + :; + # "For root recipes, installation is performed in BUILD" +} + +CLEAN() +{ + for dir in "${DIRS[@]}" ; do + cd "$ROOT_DIR/$dir" + ./kos-recipe.sh --clean + done +} + +source scripts/end-recipe \ No newline at end of file diff --git a/scripts/end-recipe b/scripts/end-recipe new file mode 100644 index 0000000000..25da55bbc1 --- /dev/null +++ b/scripts/end-recipe @@ -0,0 +1,32 @@ +# Copyright (C) KolibriOS-NG team 2024. All rights reserved +# Distributed under terms of the GNU General Public License + +show_help() +{ +cat << EOF +usage: $0 [OPTION] +Options: + --build run recipe build + --install run recipe install (stub for root scripts) + --clean remove build artifacts + --help show this help + +Running without parameters is equivalent to running: +'--build' and '--install' + +Warning: Run the script only from the directory where it is located! +EOF +} + +if [[ $# -eq 0 ]]; then + BUILD + INSTALL +else + case $1 in + "--build" ) BUILD ;; + "--install" ) INSTALL ;; + "--clean" ) CLEAN ;; + "--help" ) show_help ;; + *) fatal "Unknown argument!" + esac +fi diff --git a/scripts/start-recipe b/scripts/start-recipe new file mode 100644 index 0000000000..a3df528a1b --- /dev/null +++ b/scripts/start-recipe @@ -0,0 +1,17 @@ +set -eu + +TARGET=i586-kolibrios +SDK_TOOLCHAIN_DIR=/opt/kolibrios-sdk/toolchain +SDK_SYSROOT_DIR=/opt/kolibrios-sdk/sysroot +NUM_JOBS=8 + +msg() +{ + echo -e "\e[32m$1\e[0m" +} + +fatal() +{ + echo -e "\e[31m$1\e[0m" + exit 1 +} diff --git a/toolchain/binutils/bfd/config.bfd b/toolchain/binutils/bfd/config.bfd index bdee53957c..8f3b678743 100644 --- a/toolchain/binutils/bfd/config.bfd +++ b/toolchain/binutils/bfd/config.bfd @@ -778,6 +778,11 @@ case "${targ}" in targ_selvecs="i386_pe_vec i386_pe_big_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec" targ_underscore=yes ;; + i[3-7]86-*-kolibrios*) + targ_defvec=i386_pe_vec + targ_selvecs="i386_pe_vec i386_pei_vec" + targ_underscore=yes + ;; i[3-7]86-*-vxworks*) targ_defvec=i386_elf32_vxworks_vec targ_underscore=yes diff --git a/toolchain/binutils/binutils/configure b/toolchain/binutils/binutils/configure index e0bf7f1e88..539381e8c6 100755 --- a/toolchain/binutils/binutils/configure +++ b/toolchain/binutils/binutils/configure @@ -14626,7 +14626,7 @@ do BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)' BUILD_DLLWRAP='$(DLLWRAP_PROG)$(EXEEXT)' ;; - i[3-7]86-*-interix) + i[3-7]86-*-interix | i[3-7]86-*-kolibrios*) BUILD_DLLTOOL='$(DLLTOOL_PROG)' if test -z "$DLLTOOL_DEFAULT"; then DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386" @@ -14685,7 +14685,7 @@ do powerpc*-*-aix* | rs6000-*-aix*) od_vectors="$od_vectors objdump_private_desc_xcoff" ;; - *-*-pe* | *-*-cygwin* | *-*-mingw*) + *-*-pe* | *-*-cygwin* | *-*-mingw* | *-*-kolibrios*) od_vectors="$od_vectors objdump_private_desc_pe" ;; *-*-darwin*) diff --git a/toolchain/binutils/config.sub b/toolchain/binutils/config.sub index f6ede1d0dc..f17deaf0ee 100755 --- a/toolchain/binutils/config.sub +++ b/toolchain/binutils/config.sub @@ -399,6 +399,10 @@ case $1 in basic_machine=arm-unknown basic_os=mingw32ce ;; + kolibrios) + basic_machine=i586-pc + basic_os=kolibrios + ;; monitor) basic_machine=m68k-rom68k basic_os=coff @@ -1758,7 +1762,7 @@ case $os in | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ - | fiwix* | mlibc* ) + | fiwix* | mlibc* | kolibrios*) ;; # This one is extra strict with allowed versions sco3.2v2 | sco3.2v[4-9]* | sco5v6*) diff --git a/toolchain/binutils/gas/configure.tgt b/toolchain/binutils/gas/configure.tgt index 3429f850d0..7fb9ced70a 100644 --- a/toolchain/binutils/gas/configure.tgt +++ b/toolchain/binutils/gas/configure.tgt @@ -250,6 +250,7 @@ case ${generic_target} in i386-*-msdos*) fmt=aout ;; i386-*-moss*) fmt=elf ;; i386-*-pe) fmt=coff em=pe ;; + i386-*-kolibrios*) fmt=coff em=pe ;; i386-*-cygwin*) case ${cpu} in x86_64*) fmt=coff em=pep ;; diff --git a/toolchain/binutils/kos-recipe.sh b/toolchain/binutils/kos-recipe.sh new file mode 100755 index 0000000000..3bdb95920f --- /dev/null +++ b/toolchain/binutils/kos-recipe.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +source ../../scripts/start-recipe + +BUILD() +{ + mkdir -p build + cd build + ../configure --target=$TARGET \ + --prefix="$SDK_TOOLCHAIN_DIR" \ + --with-sysroot="$SDK_SYSROOT_DIR" \ + --disable-werror \ + --disable-nls \ + --disable-intl \ + --disable-sim \ + --disable-gdb \ + --enable-shared + + make -j$NUM_JOBS + msg "Binutils build successful!" + cd .. +} + +INSTALL() +{ + cd build + make install-strip + msg "Binutils install successful!" + cd .. +} + +CLEAN() +{ + rm -rf build + msg "Binutils build artifacts removed!" +} + +source ../../scripts/end-recipe diff --git a/toolchain/binutils/ld/configure.tgt b/toolchain/binutils/ld/configure.tgt index c62b9581d9..633ac2ff90 100644 --- a/toolchain/binutils/ld/configure.tgt +++ b/toolchain/binutils/ld/configure.tgt @@ -430,6 +430,9 @@ i[3-7]86-*-cygwin*) targ_emul=i386pe ; i[3-7]86-*-mingw32*) targ_emul=i386pe ; targ_extra_ofiles="deffilep.o pdb.o pe-dll.o" ;; +i[3-7]86-*-kolibrios*) targ_emul=i386pe ; + targ_extra_ofiles="deffilep.o pe-dll.o" + ;; i[3-7]86-*-interix*) targ_emul=i386pe_posix; targ_extra_ofiles="deffilep.o pe-dll.o" ;; diff --git a/toolchain/gcc/config.sub b/toolchain/gcc/config.sub index 38f3d037a7..894a6de7fe 100755 --- a/toolchain/gcc/config.sub +++ b/toolchain/gcc/config.sub @@ -395,6 +395,10 @@ case $1 in basic_machine=i686-pc basic_os=mingw32 ;; + kolibrios) + basic_machine=i586-pc + basic_os=kolibrios + ;; mingw32ce) basic_machine=arm-unknown basic_os=mingw32ce @@ -1749,7 +1753,7 @@ case $os in | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ - | fiwix* ) + | fiwix* | kolibrios*) ;; # This one is extra strict with allowed versions sco3.2v2 | sco3.2v[4-9]* | sco5v6*) diff --git a/toolchain/gcc/fixincludes/mkfixinc.sh b/toolchain/gcc/fixincludes/mkfixinc.sh index df90720b71..fd6a2d7722 100755 --- a/toolchain/gcc/fixincludes/mkfixinc.sh +++ b/toolchain/gcc/fixincludes/mkfixinc.sh @@ -13,6 +13,7 @@ target=fixinc.sh case $machine in i?86-*-cygwin* | \ i?86-*-mingw32* | \ + i?86-*-kolibrios* | \ x86_64-*-mingw32* | \ powerpc-*-eabisim* | \ powerpc-*-eabi* | \ diff --git a/toolchain/gcc/gcc/config.gcc b/toolchain/gcc/gcc/config.gcc index 648b3dc211..9200e7ba39 100644 --- a/toolchain/gcc/gcc/config.gcc +++ b/toolchain/gcc/gcc/config.gcc @@ -2102,6 +2102,29 @@ i[34567]86-*-cygwin*) default_use_cxa_atexit=yes use_gcc_stdint=wrap ;; +i[34567]86-*-kolibrios*) + tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/cygming.h i386/kolibrios.h i386/mingw-stdint.h" + tm_defines="${tm_defines} TARGET_KOLIBRIOS=1" + c_target_objs="${c_target_objs} winnt-c.o" + cxx_target_objs="${cxx_target_objs} winnt-c.o" + d_target_objs="${d_target_objs} winnt-d.o" + tmake_file="${tmake_file} t-winnt i386/t-cygming t-slibgcc" + native_system_header_dir=/include + target_gtfiles="$target_gtfiles \$(srcdir)/config/i386/winnt.cc" + extra_options="${extra_options} i386/kolibrios.opt" + extra_objs="${extra_objs} winnt.o winnt-stubs.o" + cxx_target_objs="${cxx_target_objs} winnt-cxx.o" + target_has_targetcm="yes" + target_has_targetdm="yes" + gas=yes + gnu_ld=yes + default_use_cxa_atexit=yes + use_gcc_stdint=wrap + if test x$enable_threads = xyes; then + # Not supported yet! + thread_file='posix' + fi +;; x86_64-*-cygwin*) need_64bit_isa=yes tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/cygming.h i386/cygwin.h i386/cygwin-w64.h i386/cygwin-stdint.h" diff --git a/toolchain/gcc/gcc/config/i386/cygming.h b/toolchain/gcc/gcc/config/i386/cygming.h index d539f8d069..4b825aa344 100644 --- a/toolchain/gcc/gcc/config/i386/cygming.h +++ b/toolchain/gcc/gcc/config/i386/cygming.h @@ -124,6 +124,12 @@ along with GCC; see the file COPYING3. If not see #define TARGET_EXECUTABLE_SUFFIX ".exe" +#ifdef TARGET_KOLIBRIOS + #define CYGMING_BUILTIN_ASSERT builtin_assert ("system=kolibrios"); +#else + #define CYGMING_BUILTIN_ASSERT builtin_assert ("system=winnt"); +#endif + #define TARGET_OS_CPP_BUILTINS() \ do \ { \ @@ -131,7 +137,7 @@ along with GCC; see the file COPYING3. If not see builtin_define ("_X86_=1"); \ if (TARGET_SEH) \ builtin_define ("__SEH__"); \ - builtin_assert ("system=winnt"); \ + CYGMING_BUILTIN_ASSERT \ builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ builtin_define ("__fastcall=__attribute__((__fastcall__))"); \ builtin_define ("__thiscall=__attribute__((__thiscall__))"); \ diff --git a/toolchain/gcc/gcc/config/i386/kolibrios.h b/toolchain/gcc/gcc/config/i386/kolibrios.h new file mode 100644 index 0000000000..e372aa83ca --- /dev/null +++ b/toolchain/gcc/gcc/config/i386/kolibrios.h @@ -0,0 +1,77 @@ +/* Operating system specific defines to be used when targeting + GCC for KolibriOS + Copyright (C) 1997-2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC 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, or (at your option) +any later version. + +GCC 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 GCC; see the file COPYING3. If not see +. + +Copyright (C) KolibriOS team 2024. All rights reserved. +Distributed under terms of the GNU General Public License */ + +/* Additional predefined macros. */ +#define EXTRA_OS_CPP_BUILTINS() \ + do \ + { \ + builtin_define ("__KOS__"); \ + builtin_define ("__KOLIBRIOS__"); \ + builtin_define ("_KOLIBRI"); \ + builtin_define ("KOLIBRI"); \ + } \ + while (0) + +/* Always link libgcc */ +#undef LIBGCC_SPEC +#define LIBGCC_SPEC "-lgcc" + +#undef REAL_LIBGCC_SPEC +#define REAL_LIBGCC_SPEC LIBGCC_SPEC + +/* For KolibriOS applications always link libc.a */ +#undef LIB_SPEC +#define LIB_SPEC "%{!shared: %{!mdll: -Tkos-app.lds}} -lc" + +#define LINK_SPEC "%{mwindows:--subsystem windows} \ + %{mconsole:--subsystem console} \ + %{shared: %{mdll: %eshared and mdll are not compatible}} \ + %{shared: --shared} %{mdll: --dll} \ + %{shared|mdll: --image-base=0} \ + %{!shared: %{!mdll: -Bstatic --image-base=0}} --file-alignment=16 --section-alignment=16" + +/* Stub! Start file not used. */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "" + +/* Stub! End file not used. */ +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "" + +/* Running objcopy for KolibriOS applications */ +#undef POST_LINK_SPEC +#define POST_LINK_SPEC "%{!shared: %{!mdll: i586-kolibrios-objcopy -Obinary %{o*:%*} %{!o*:a.exe} }}" + +/* Native header directory */ +#undef NATIVE_SYSTEM_HEADER_DIR +#define NATIVE_SYSTEM_HEADER_DIR "/include" + +/* Don't use ".exe" suffix by default for KolibriOS */ +#undef TARGET_EXECUTABLE_SUFFIX +#define TARGET_EXECUTABLE_SUFFIX "" + +/* Stub! "-pthread" is not supported for KolibriOS. */ +#undef GOMP_SELF_SPECS +#define GOMP_SELF_SPECS "" +#undef GTM_SELF_SPECS +#define GTM_SELF_SPECS "" diff --git a/toolchain/gcc/gcc/config/i386/kolibrios.opt b/toolchain/gcc/gcc/config/i386/kolibrios.opt new file mode 100644 index 0000000000..af6e91d650 --- /dev/null +++ b/toolchain/gcc/gcc/config/i386/kolibrios.opt @@ -0,0 +1,51 @@ +; KolibriOS-specific options (For MinGW compatibility). + +; Copyright (C) 2005-2023 Free Software Foundation, Inc. +; +; This file is part of GCC. +; +; GCC 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, or (at your option) any later +; version. +; +; GCC 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 GCC; see the file COPYING3. If not see +; . +; +; Copyright (C) KolibriOS team 2024. All rights reserved. +; Distributed under terms of the GNU General Public License + +mconsole +Target RejectNegative +Create console application. + +mdll +Target RejectNegative +Generate code for a DLL. + +mnop-fun-dllimport +Target Var(TARGET_NOP_FUN_DLLIMPORT) +Ignore dllimport for functions. + +mwindows +Target +Create GUI application. + +mpe-aligned-commons +Target Var(use_pe_aligned_common) Init(HAVE_GAS_ALIGNED_COMM) +Use the GNU extension to the PE format for aligned common data. + +posix +Driver + +fwritable-relocated-rdata +Common Var(flag_writable_rel_rdata) Init(0) +Put relocated read-only data into .data section. + +; Retain blank line above diff --git a/toolchain/gcc/gcc/configure b/toolchain/gcc/gcc/configure index c7b26d1927..54b593effc 100755 --- a/toolchain/gcc/gcc/configure +++ b/toolchain/gcc/gcc/configure @@ -13012,7 +13012,7 @@ case ${enable_threads} in target_thread_file='single' ;; aix | dce | lynx | mipssde | posix | rtems | \ - single | tpf | vxworks | win32 | mcf) + single | tpf | vxworks | win32 | mcf | kolibrios) target_thread_file=${enable_threads} ;; *) diff --git a/toolchain/gcc/kos-recipe.sh b/toolchain/gcc/kos-recipe.sh new file mode 100755 index 0000000000..64221c60ae --- /dev/null +++ b/toolchain/gcc/kos-recipe.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Copyright (C) KolibriOS-NG team 2024. All rights reserved +# Distributed under terms of the GNU General Public License + +source ../../scripts/start-recipe + +BUILD() +{ + mkdir -p "$SDK_SYSROOT_DIR" + cp -af ../../libraries/newlib/newlib/libc/include/. "$SDK_SYSROOT_DIR/include" + msg "Newlib headers install successful!" + + mkdir -p build + cd build + + ../configure --target=$TARGET \ + --prefix="$SDK_TOOLCHAIN_DIR" \ + --with-sysroot="$SDK_SYSROOT_DIR" \ + --disable-nls \ + --enable-shared \ + --enable-languages=c + + make -j$NUM_JOBS all-gcc + msg "GCC build successful!" + + make -j$NUM_JOBS all-target-libgcc + msg "Libgcc build successful!" + + cd .. +} + +INSTALL() +{ + cd build + make install-strip-gcc + msg "GCC install successful!" + + make install-target-libgcc + msg "Libgcc install successful!" + + cd .. +} + +CLEAN() +{ + rm -rf build + msg "GCC build artifacts removed!" +} + +source ../../scripts/end-recipe diff --git a/toolchain/gcc/libgcc/config.host b/toolchain/gcc/libgcc/config.host index 9d7212028d..f6007e475a 100644 --- a/toolchain/gcc/libgcc/config.host +++ b/toolchain/gcc/libgcc/config.host @@ -837,6 +837,9 @@ x86_64-*-cygwin*) # FIXME - dj - t-chkstk used to be in here, need a 64-bit version of that tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-cygwin t-crtfm t-dfprules i386/t-chkstk" ;; +i[34567]86-*-kolibrios*) + tmake_file="${tmake_file} i386/t-chkstk + esac i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" if test x$enable_vtable_verify = xyes; then