https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99435

            Bug ID: 99435
           Summary: avr: incorrect I/O address ranges for some cores
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at nothien dot uber.space
  Target Milestone: ---

The `io' and `io_low' attributes incorrectly report out-of-range addresses when
compiling for the ATmega32u4 (-mmcu=atmega32u4), on all GCC versions.

In particular, on this core, the 'low' I/O address space (within which the
instructions sbi, cbi, sbis, sbic, etc. can be used, in addition to memory
reads/writes) is from 0x20 to 0x5F (inclusive; 64 bytes), and the 'high' I/O
address space (which can only be accessed only using memory reads/writes) is
from 0x60 to 0xFF (inclusive; 160 bytes).

The datasheet for the ATmega32u4 (and the ATmega16u4), which discusses these
ranges (see section 5), can be found at
<http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf>.

Compiling, for example, the following (with `avr-gcc -Wall -Wextra -Wpedantic
-Werror -mmcu=atmega32u4`):

    volatile uint8_t io_pllcsr __attribute__((io_low (0x49)));

will fail with the error: "‘io_low’ attribute address out of range", although
this is a perfectly valid low I/O address on this platform.

This error occurs because currently GCC assumes that the low I/O address space
is from 0x20 to 0x3F and that the high I/O address space is from 0x40 to 0x5F. 
These limits are hardcoded into the `low_io_address_operand',
`high_io_address_operand', and `io_address_operand' predicates, defined at
`gcc/config/avr/predicates.md'.

This should be corrected by moving these values into the avr_arch structure,
where they can be varied by platform.  I will send in a patch for this shortly.

Reply via email to