[AVR] Cannot build RTL for avrtiny because of CPUAVR_HAS_ADIW
Building the RTL for avrtiny subarch fails when assembling system.s:
~/fpc/gitlab-cc/rtl/embedded$ /home/christo/fpc/gitlab-cc/compiler/ppcrossavr -Cpavrtiny -Ur -Tembedded -Pavr -XPavr-embedded- -Ur -Xs -O2 -n -Fi../inc -Fi../avr -FE. -FU/home/christo/fpc/gitlab-cc/rtl/units/avr-embedded -davr -dRELEASE -XP/home/christo/gdb/avr-gcc-11.1.0-x64-linux/bin/avr- -Us -Sg system.pp @system.cfg | more
/home/christo/fpc/gitlab-cc/rtl/units/avr-embedded/system.s: Assembler messages:
/home/christo/fpc/gitlab-cc/rtl/units/avr-embedded/system.s:338: Error: illegal opcode sbiw for mcu avrtiny
/home/christo/fpc/gitlab-cc/rtl/units/avr-embedded/system.s:343: Error: illegal opcode sbiw for mcu avrtiny
This is probably because the ADIW/SBIW instructions are not supported by this subarch, or at least not by all the controllers in the family (the datasheets for the older attiny 4/5/9/10/20/40 do not list ADIW/SBIW as supported).
I also tested just the ADIW/SBIW instructions in a simple test program in MPLAB-X 5.50 with up to date device packs using both the XC8 compiler and the bin tools shipped with avr-gcc-11.1.0:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
asm volatile("adiw r26,1\n\t"::);
asm volatile("sbiw r26,1\n\t"::);
}
Resulting error:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/christo/MPLABXProjects/testadiw/testadiw.X'
make -f nbproject/Makefile-default.mk dist/default/production/testadiw.X.production.hex
make[2]: Entering directory '/home/christo/MPLABXProjects/testadiw/testadiw.X'
"/home/christo/gdb/avr-gcc-11.1.0-x64-linux/bin/avr-gcc" -mmcu=attiny102 -I "/home/christo/.mchp_packs/Microchip/ATtiny_DFP/2.7.128/include" -B "/home/christo/.mchp_packs/Microchip/ATtiny_DFP/2.7.128/gcc/dev/attiny102" -x c -c -D__ATtiny102__ -funsigned-char -funsigned-bitfields -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -MD -MP -MF "build/default/production/main.o.d" -MT "build/default/production/main.o.d" -MT build/default/production/main.o -o build/default/production/main.o main.c -DXPRJ_default=default
make[2]: Leaving directory '/home/christo/MPLABXProjects/testadiw/testadiw.X'
make[1]: Leaving directory '/home/christo/MPLABXProjects/testadiw/testadiw.X'
/tmp/cc356jxv.s: Assembler messages:
/tmp/cc356jxv.s:19: Error: illegal opcode sbiw for mcu avrtiny
/tmp/cc356jxv.s:23: Error: illegal opcode cbi for mcu avrtiny
make[2]: *** [nbproject/Makefile-default.mk:124: build/default/production/main.o] Error 1
make[1]: *** [nbproject/Makefile-default.mk:95: .build-conf] Error 2
make: *** [nbproject/Makefile-impl.mk:39: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 194ms)
Removing the CPUAVR_HAS_ADIW flag for cpu_avrtiny allows compilation to proceed.