Xtensa support
Matheus Catarino
matheus-catarino at hotmail.com
Sun Apr 14 16:04:54 UTC 2024
On Sunday, 14 April 2024 at 07:25:07 UTC, Witold Baryluk wrote:
> On Friday, 12 April 2024 at 23:16:30 UTC, Matheus Catarino
> wrote:
>> I've recently seen support for different target architectures
>> on https://explore.dgnu.org .
>> What is the status of Xtensa and xtensa-gnu support? Does it
>> support both xtensa ABIs (call0 and windowed)?
>>
>> Currently there is a need to fork espressif/LLVM when using
>> ldc2. Is there a need to fork espressif crosstool-ng?
>
> It works. I successfully run some code with it with gdc few
> years ago. But it is quite a work to map either reimplement all
> the APIs in D from scratch, but it can be done as everything is
> reasonably well documented. I only had some basic stuff like
> GPIO, very little of timers and uart. So no networking
> (possibly, but I had other things to do) or other stuff.
>
>
> As of xtensa ABIs I have no idea. I didn't use espressif
> libraries. Should be possible tho.
Espressif/LLVM have xtensa-ABI (windowed) partial support, but
GCC [upstream and fork] have both xtensa-ABI (call0 & windowed)
```bash
./gcc/esp32s3-gdc/bin/xtensa-esp32s3-elf-gdc --help=target
The following options are target specific:
-mabi=call0 Use call0 ABI.
-mabi=windowed Use windowed registers ABI.
-malways-memw Always emit a MEMW before a
load and after a store operation. Used to debug
memory coherency issues.
-mauto-litpools Relax literals in assembler and
place them automatically in the text section.
-mconst16 Use CONST16 instruction to load
constants.
-mdisable-hardware-atomics Call built-in functions for
atomic operations instead of using hardware atomic
instructions. This option can
be used if atomic operations on some memory
regions need to be emulated in
software.
-mdynconfig= Directory or path to dynconfig
library.
-mextra-l32r-costs= Set extra memory access cost
for L32R instruction, in clock-cycle units.
-mfix-esp32-psram-cache-issue Work around a PSRAM cache
issue in the ESP32 ECO1 chips.
-mfix-esp32-psram-cache-strategy= Specify a psram cache fix
strategy.
-mforce-no-pic Disable position-independent
code (PIC) for use in OS kernel code.
-mfused-madd Same as -ffp-contract=fast (or,
in negated form, -ffp-contract=off). Uses of
this option are diagnosed.
-mlongcalls Use indirect CALLXn
instructions for large programs.
-mlra Use LRA instead of reload
(transitional).
-mno-serialize-volatile Do not serialize volatile
memory references with MEMW instructions.
-mtarget-align Automatically align branch
targets to reduce branch penalties.
-mtext-section-literals Intersperse literal pools with
code in the text section.
Psram cache fix strategies (for use with
-mfix-esp32-psram-cache-strategy= option):
dupldst memw nops
```
src: https://github.com/espressif/gcc
src: https://github.com/espressif/crosstool-ng
- **Note:** replace `--enable-languages=c,c++` to
`--enable-languages=c,d` or add `d` after `c++`.
```bash
$>
/root/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/xtensa-esp-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/root/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/xtensa-esp-elf-gcc
COLLECT_LTO_WRAPPER=/root/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../libexec/gcc/xtensa-esp-elf/13.2.0/lto-wrapper
Target: xtensa-esp-elf
Configured with:
/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/gcc/configure
--build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=xtensa-esp-elf
--prefix=/builds/idf/crosstool-NG/builds/xtensa-esp-elf
--exec_prefix=/builds/idf/crosstool-NG/builds/xtensa-esp-elf
--with-local-prefix=/builds/idf/crosstool-NG/builds/xtensa-esp-elf/xtensa-esp-elf --with-headers=/builds/idf/crosstool-NG/builds/xtensa-esp-elf/xtensa-esp-elf/include --with-newlib --enable-threads=no --disable-shared --with-pkgversion='crosstool-NG esp-13.2.0_20230928' --disable-__cxa_atexit --enable-cxx-flags=-ffunction-sections --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libstdcxx-verbose --with-gmp=/builds/idf/crosstool-NG/.build/xtensa-esp-elf/buildtools --with-mpfr=/builds/idf/crosstool-NG/.build/xtensa-esp-elf/buildtools --with-mpc=/builds/idf/crosstool-NG/.build/xtensa-esp-elf/buildtools --with-isl=/builds/idf/crosstool-NG/.build/xtensa-esp-elf/buildtools --enable-lto --enable-target-optspace --without-long-double-128 --disable-nls --enable-multiarch --enable-languages=c,c++ --disable-libstdcxx-verbose --enable-threads=posix --enable-gcov-custom-rtio --enable-libstdcxx-time=yes
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (crosstool-NG esp-13.2.0_20230928)
```
## Result
```bash
./gcc/esp32s3-gdc/bin/xtensa-esp32s3-elf-gdc -v
Using built-in specs.
COLLECT_GCC=./gcc/esp32s3-gdc/bin/xtensa-esp32s3-elf-gdc
COLLECT_LTO_WRAPPER=/home/kassane/gcc/esp32s3-gdc/bin/../libexec/gcc/xtensa-esp32s3-elf/13.2.0/lto-wrapper
Target: xtensa-esp32s3-elf
Configured with: ./configure --target=xtensa-esp32s3-elf
--enable-languages=c,d,lto
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (GCC)
```
More information about the D.gnu
mailing list