[riot-notifications] [RIOT-OS/RIOT] WIP, POC: Add LLVM support for AVR (#16924)

Marian Buschsieweke notifications at github.com
Thu Sep 30 17:05:47 CEST 2021


### Contribution description

This PR is working towards adding LLVM support for the AVR platform.

***WARNING:*** This is work in progress and not in a shape in which it makes sense to start a code review.

I needed to add some workarounds for features of the avrlibc that do not compile with clang. One big pain point is that clang verifies constraints of inline assembly before eliminating dead branches, while GCC does it the other way round. E.g. something like

```C
static inline __attribute__((always_inline)) uint8_t get_foo(void)
{
    uint8_t dest;
    if (FOO < 64) {
         __asm__(
            "in r0,%[foo] \r\n"
            : [dest] "=r"(dest)
            : [foo] "I"(foo)
        );
    }
    else {
        dest = *_SFR_MEM_ADDR(FOO);
    }
    return dest;
}
```

will fail to compile for `FOO >= 64` with LLVM, despite the inline assembly never being executed in that case. The header in `<avr/wdt.h>` uses this a lot, so I provided versions of `wdt_enable()` etc. inline - I'm not sure if those will work on al AT(X)mega MCUs supported by RIOT, though.

Another issue with LLVM is that commonly used helpers like `__tmp_reg__`, `__SREG__`, `__SP_L__`, `__SP_H__` are not available. For now, I replaced them with magic numbers / register names.

### Testing procedure

`$ make BOARD=atmega328p TOOLCHAIN=llvm -C examples/hello-world` compiles and links, but cannot be flashed.

### Issues/PRs references

Depends on:

- [ ] https://github.com/RIOT-OS/RIOT/pull/16919
- [ ] https://github.com/RIOT-OS/RIOT/pull/16920
- [ ] https://github.com/RIOT-OS/RIOT/pull/16790
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/16924

-- Commit Summary --

  * <a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/e89930da5eb0267199aa0863eb3eec7a36c762e7">cpu/avr8_common: Fix link with binutils > 2.35.2</a>
  * <a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/da20c3c01eb6aa060506e8019c45b5f138c003f2">cpu/{atxmega,atmega_common}: fix invalid use of PSTR()</a>
  * <a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/e975f85e17a6864967ec5bd2809dc4d5ce2e8cdd">core/rmutex: use atomic utils</a>
  * <a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/f2f2e74dcefa670c4c1e1beeade67f8b8d663991">cpu/avr8_common: Add support for LLVM</a>

-- File Changes --

    M core/include/rmutex.h (9)
    M core/rmutex.c (15)
    M cpu/atmega1281/Makefile.include (2)
    M cpu/atmega1284p/Makefile.include (2)
    M cpu/atmega128rfa1/Makefile.include (2)
    M cpu/atmega2560/Makefile.include (2)
    M cpu/atmega256rfr2/Makefile.include (2)
    M cpu/atmega328p/Makefile.include (2)
    M cpu/atmega32u4/Makefile.include (2)
    M cpu/atmega_common/atmega_cpu.c (6)
    M cpu/atmega_common/include/atmega_gpio.h (2)
    M cpu/atmega_common/periph/gpio.c (2)
    M cpu/atmega_common/periph/pm.c (2)
    M cpu/atmega_common/periph/rtt.c (1)
    M cpu/atmega_common/periph/timer.c (1)
    M cpu/atmega_common/periph/wdt.c (1)
    M cpu/atxmega/Makefile.include (6)
    M cpu/atxmega/atxmega_cpu.c (6)
    M cpu/atxmega/periph/gpio.c (1)
    M cpu/atxmega/periph/timer.c (2)
    M cpu/avr8_common/Makefile.include (1)
    M cpu/avr8_common/avr8_cpu.c (3)
    M cpu/avr8_common/include/cpu.h (101)
    M cpu/avr8_common/include/irq_arch.h (6)
    A cpu/avr8_common/ldscripts/avr51.ld (27)
    A cpu/avr8_common/ldscripts/avr6.ld (27)
    A cpu/avr8_common/ldscripts/avr_common.ld (255)
    A cpu/avr8_common/ldscripts/avrxmega6.ld (27)
    A cpu/avr8_common/ldscripts/avrxmega7.ld (27)
    D cpu/avr8_common/ldscripts/xfa.ld (16)
    M cpu/avr8_common/startup.c (2)
    M cpu/avr8_common/thread_arch.c (206)
    M makefiles/arch/avr8.inc.mk (10)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/16924.patch
https://github.com/RIOT-OS/RIOT/pull/16924.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16924
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210930/4d1203df/attachment.htm>


More information about the notifications mailing list