diff options
-rw-r--r-- | .circleci/config.yml | 2 | ||||
-rw-r--r-- | .github/workflows/build-macos.yml | 2 | ||||
-rw-r--r-- | .github/workflows/linux.yml | 7 | ||||
-rw-r--r-- | .github/workflows/windows.yml | 2 | ||||
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | builder/builtins.go | 12 | ||||
-rw-r--r-- | builder/picolibc.go | 2 | ||||
-rw-r--r-- | src/runtime/arch_avr.go | 36 | ||||
-rw-r--r-- | targets/arduino-mega1280.json | 2 | ||||
-rw-r--r-- | targets/arduino-mega2560.json | 2 | ||||
-rw-r--r-- | targets/arduino-nano.json | 4 | ||||
-rw-r--r-- | targets/arduino.json | 4 | ||||
-rw-r--r-- | targets/atmega1280.json | 3 | ||||
-rw-r--r-- | targets/atmega1284p.json | 5 | ||||
-rw-r--r-- | targets/atmega2560.json | 3 | ||||
-rw-r--r-- | targets/atmega328p.json | 3 | ||||
-rw-r--r-- | targets/attiny85.json | 3 | ||||
-rw-r--r-- | targets/avr.json | 5 | ||||
-rw-r--r-- | targets/avr.ld | 4 | ||||
-rw-r--r-- | targets/digispark.json | 4 | ||||
-rwxr-xr-x | tools/gen-device-avr/gen-device-avr.go | 6 |
22 files changed, 74 insertions, 41 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index b8f8f4068..7a7e17d5a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,8 +63,6 @@ commands: clang-<<parameters.llvm>> \ libclang-<<parameters.llvm>>-dev \ lld-<<parameters.llvm>> \ - gcc-avr \ - avr-libc \ cmake \ ninja-build - hack-ninja-jobs diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 680958094..0359a9f31 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -93,7 +93,7 @@ jobs: path: build/tinygo.darwin-amd64.tar.gz - name: Smoke tests shell: bash - run: make smoketest TINYGO=$(PWD)/build/tinygo AVR=0 + run: make smoketest TINYGO=$(PWD)/build/tinygo test-macos-homebrew: name: homebrew-install runs-on: macos-latest diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 8a5a1c28d..7ead14904 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -133,11 +133,6 @@ jobs: mkdir -p ~/lib tar -C ~/lib -xf tinygo.linux-amd64.tar.gz ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo - - name: Install apt dependencies - run: | - sudo apt-get install --no-install-recommends \ - gcc-avr \ - avr-libc - run: make tinygo-test-wasi-fast - run: make smoketest assert-test-linux: @@ -158,8 +153,6 @@ jobs: qemu-system-arm \ qemu-system-riscv32 \ qemu-user \ - gcc-avr \ - avr-libc \ simavr \ ninja-build - name: Install Go diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 0aa3357eb..6e493d89a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -125,7 +125,7 @@ jobs: run: 7z x release.zip -r - name: Smoke tests shell: bash - run: make smoketest TINYGO=$(PWD)/build/tinygo/bin/tinygo AVR=0 + run: make smoketest TINYGO=$(PWD)/build/tinygo/bin/tinygo stdlib-test-windows: runs-on: windows-2022 diff --git a/Dockerfile b/Dockerfile index 10061c6ff..2de6f7310 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.19 AS tinygo-llvm RUN apt-get update && \ - apt-get install -y apt-utils make cmake clang-11 binutils-avr gcc-avr avr-libc ninja-build + apt-get install -y apt-utils make cmake clang-11 ninja-build COPY ./Makefile /tinygo/Makefile @@ -674,7 +674,6 @@ ifneq ($(STM32), 0) $(TINYGO) build -size short -o test.hex -target=swan examples/blinky1 @$(MD5SUM) test.hex endif -ifneq ($(AVR), 0) $(TINYGO) build -size short -o test.hex -target=atmega1284p examples/serial @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=arduino examples/blinky1 @@ -693,7 +692,6 @@ ifneq ($(AVR), 0) @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=digispark -gc=leaking examples/blinky1 @$(MD5SUM) test.hex -endif ifneq ($(XTENSA), 0) $(TINYGO) build -size short -o test.bin -target=esp32-mini32 examples/blinky1 @$(MD5SUM) test.bin diff --git a/builder/builtins.go b/builder/builtins.go index f35816148..a1066b671 100644 --- a/builder/builtins.go +++ b/builder/builtins.go @@ -162,6 +162,15 @@ var aeabiBuiltins = []string{ "udivmodsi4.c", } +var avrBuiltins = []string{ + "avr/divmodhi4.S", + "avr/divmodqi4.S", + "avr/mulhi3.S", + "avr/mulqi3.S", + "avr/udivmodhi4.S", + "avr/udivmodqi4.S", +} + // CompilerRT is a library with symbols required by programs compiled with LLVM. // These symbols are for operations that cannot be emitted with a single // instruction or a short sequence of instructions for that target. @@ -186,6 +195,9 @@ var CompilerRT = Library{ if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { builtins = append(builtins, aeabiBuiltins...) } + if strings.HasPrefix(target, "avr") { + builtins = append(builtins, avrBuiltins...) + } return builtins, nil }, } diff --git a/builder/picolibc.go b/builder/picolibc.go index d64ed48b7..1b7c748be 100644 --- a/builder/picolibc.go +++ b/builder/picolibc.go @@ -78,7 +78,7 @@ var picolibcSources = []string{ "libc/tinystdio/fputc.c", "libc/tinystdio/fputs.c", "libc/tinystdio/fread.c", - "libc/tinystdio/freopen.c", + //"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369 "libc/tinystdio/fscanf.c", "libc/tinystdio/fseek.c", "libc/tinystdio/fseeko.c", diff --git a/src/runtime/arch_avr.go b/src/runtime/arch_avr.go index a9388ce91..9df90fcc0 100644 --- a/src/runtime/arch_avr.go +++ b/src/runtime/arch_avr.go @@ -37,3 +37,39 @@ func procPin() { func procUnpin() { interrupt.Restore(procPinnedMask) } + +// The following functions are workarounds for things missing in compiler-rt. +// They will likely need special assembly implementations. + +//export __mulsi3 +func __mulsi3(a, b uint32) uint32 { + var r uint32 + for a != 0 { + if a&1 != 0 { + r += b + } + a >>= 1 + b <<= 1 + } + return r +} + +//export __divsi3 +func __divsi3(a, b int32) int32 + +//export __udivsi3 +func __udivsi3(a, b uint32) uint32 + +//export __divmodsi4 +func __divmodsi4(a, b int32) uint64 { + d := __divsi3(a, b) + rem := a - (d * b) + return uint64(uint32(d)) | uint64(uint32(rem))<<32 +} + +//export __udivmodsi4 +func __udivmodsi4(a, b uint32) uint64 { + d := __udivsi3(a, b) + rem := a - (d * b) + return uint64(d) | uint64(rem)<<32 +} diff --git a/targets/arduino-mega1280.json b/targets/arduino-mega1280.json index cb1ad4bf3..d289297f1 100644 --- a/targets/arduino-mega1280.json +++ b/targets/arduino-mega1280.json @@ -2,7 +2,7 @@ "inherits": ["atmega1280"], "build-tags": ["arduino_mega1280"], "ldflags": [ - "-Wl,--defsym=_bootloader_size=4096" + "--defsym=_bootloader_size=4096" ], "flash-command":"avrdude -c arduino -b 57600 -p atmega1280 -P {port} -U flash:w:{hex}:i -v -D" } diff --git a/targets/arduino-mega2560.json b/targets/arduino-mega2560.json index b1e550daf..afbd75546 100644 --- a/targets/arduino-mega2560.json +++ b/targets/arduino-mega2560.json @@ -2,7 +2,7 @@ "inherits": ["atmega2560"], "build-tags": ["arduino_mega2560"], "ldflags": [ - "-Wl,--defsym=_bootloader_size=8192" + "--defsym=_bootloader_size=8192" ], "flash-command":"avrdude -c wiring -b 115200 -p atmega2560 -P {port} -U flash:w:{hex}:i -v -D" } diff --git a/targets/arduino-nano.json b/targets/arduino-nano.json index 548e87b18..65dd6c2d9 100644 --- a/targets/arduino-nano.json +++ b/targets/arduino-nano.json @@ -2,8 +2,8 @@ "inherits": ["atmega328p"], "build-tags": ["arduino_nano"], "ldflags": [ - "-Wl,--defsym=_bootloader_size=512", - "-Wl,--defsym=_stack_size=512" + "--defsym=_bootloader_size=512", + "--defsym=_stack_size=512" ], "flash-command": "avrdude -c arduino -p atmega328p -b 57600 -P {port} -U flash:w:{hex}:i", "emulator": "simavr -m atmega328p -f 16000000 {}" diff --git a/targets/arduino.json b/targets/arduino.json index 28c9fb672..b5bd97758 100644 --- a/targets/arduino.json +++ b/targets/arduino.json @@ -2,8 +2,8 @@ "inherits": ["atmega328p"], "build-tags": ["arduino"], "ldflags": [ - "-Wl,--defsym=_bootloader_size=512", - "-Wl,--defsym=_stack_size=512" + "--defsym=_bootloader_size=512", + "--defsym=_stack_size=512" ], "flash-command": "avrdude -c arduino -p atmega328p -P {port} -U flash:w:{hex}:i", "serial-port": ["2341:0043", "2341:0001", "2a03:0043", "2341:0243"], diff --git a/targets/atmega1280.json b/targets/atmega1280.json index bf2e8c8bc..34e78f41d 100644 --- a/targets/atmega1280.json +++ b/targets/atmega1280.json @@ -4,8 +4,7 @@ "build-tags": ["atmega1280", "atmega"], "serial": "uart", "ldflags": [ - "-mmcu=avr51", - "-Wl,--defsym=_stack_size=512" + "--defsym=_stack_size=512" ], "linkerscript": "src/device/avr/atmega1280.ld", "extra-files": [ diff --git a/targets/atmega1284p.json b/targets/atmega1284p.json index d78d6a2a9..501fb58d1 100644 --- a/targets/atmega1284p.json +++ b/targets/atmega1284p.json @@ -4,9 +4,8 @@ "build-tags": ["atmega1284p", "atmega"], "serial": "uart", "ldflags": [ - "-mmcu=avr51", - "-Wl,--defsym=_bootloader_size=0", - "-Wl,--defsym=_stack_size=512" + "--defsym=_bootloader_size=0", + "--defsym=_stack_size=512" ], "linkerscript": "src/device/avr/atmega1284p.ld", "extra-files": [ diff --git a/targets/atmega2560.json b/targets/atmega2560.json index d3b37418e..a00179ef9 100644 --- a/targets/atmega2560.json +++ b/targets/atmega2560.json @@ -4,8 +4,7 @@ "build-tags": ["atmega2560", "atmega"], "serial": "uart", "ldflags": [ - "-mmcu=avr6", - "-Wl,--defsym=_stack_size=512" + "--defsym=_stack_size=512" ], "linkerscript": "src/device/avr/atmega2560.ld", "extra-files": [ diff --git a/targets/atmega328p.json b/targets/atmega328p.json index 6a763b727..d4098d4b8 100644 --- a/targets/atmega328p.json +++ b/targets/atmega328p.json @@ -3,9 +3,6 @@ "cpu": "atmega328p", "build-tags": ["atmega328p", "atmega", "avr5"], "serial": "uart", - "ldflags": [ - "-mmcu=avr5" - ], "linkerscript": "src/device/avr/atmega328p.ld", "extra-files": [ "targets/avr.S", diff --git a/targets/attiny85.json b/targets/attiny85.json index f28f4f84d..3fb111147 100644 --- a/targets/attiny85.json +++ b/targets/attiny85.json @@ -5,9 +5,6 @@ "cflags": [ "-D__AVR_ARCH__=25" ], - "ldflags": [ - "-mmcu=avr25" - ], "linkerscript": "src/device/avr/attiny85.ld", "extra-files": [ "targets/avr.S", diff --git a/targets/avr.json b/targets/avr.json index 3bffe6534..587a3e565 100644 --- a/targets/avr.json +++ b/targets/avr.json @@ -4,16 +4,17 @@ "goos": "linux", "goarch": "arm", "gc": "conservative", - "linker": "avr-gcc", + "linker": "ld.lld", "scheduler": "none", "rtlib": "compiler-rt", + "libc": "picolibc", "default-stack-size": 256, "cflags": [ "-Werror" ], "ldflags": [ "-T", "targets/avr.ld", - "-Wl,--gc-sections" + "--gc-sections" ], "extra-files": [ "src/internal/task/task_stack_avr.S", diff --git a/targets/avr.ld b/targets/avr.ld index 720465ca4..a3460c136 100644 --- a/targets/avr.ld +++ b/targets/avr.ld @@ -5,6 +5,8 @@ MEMORY RAM (xrw) : ORIGIN = 0x800000 + __ram_start, LENGTH = __ram_size } +ENTRY(__vector_RESET) + SECTIONS { .text : @@ -12,9 +14,11 @@ SECTIONS KEEP(*(.vectors)) KEEP(*(.text.__vector_RESET)) KEEP(*(.text.main)) /* main must follow the reset handler */ + *(.text) *(.text.*) *(.progmem) *(.progmem.*) + . = ALIGN(16); /* needed with ld.lld for some reasoon */ } .stack (NOLOAD) : diff --git a/targets/digispark.json b/targets/digispark.json index ad9b1550c..b2a29d673 100644 --- a/targets/digispark.json +++ b/targets/digispark.json @@ -2,8 +2,8 @@ "inherits": ["attiny85"], "build-tags": ["digispark"], "ldflags": [ - "-Wl,--defsym=_bootloader_size=2180", - "-Wl,--defsym=_stack_size=128" + "--defsym=_bootloader_size=2180", + "--defsym=_stack_size=128" ], "flash-command": "micronucleus --run {hex}", "emulator": "simavr -m attiny85 -f 16000000 {}" diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go index cdcf91121..1e841b954 100755 --- a/tools/gen-device-avr/gen-device-avr.go +++ b/tools/gen-device-avr/gen-device-avr.go @@ -60,7 +60,7 @@ type Device struct { // AddressSpace is the Go version of an XML element like the following: // -// <address-space endianness="little" name="data" id="data" start="0x0000" size="0x0900"> +// <address-space endianness="little" name="data" id="data" start="0x0000" size="0x0900"> // // It describes one address space in an AVR microcontroller. One address space // may have multiple memory segments. @@ -71,7 +71,7 @@ type AddressSpace struct { // MemorySegment is the Go version of an XML element like the following: // -// <memory-segment name="IRAM" start="0x0100" size="0x0800" type="ram" external="false"/> +// <memory-segment name="IRAM" start="0x0100" size="0x0800" type="ram" external="false"/> // // It describes a single contiguous area of memory in a particular address space // (see AddressSpace). @@ -432,7 +432,7 @@ __vector_default: .endm ; The interrupt vector of this device. Must be placed at address 0 by the linker. -.section .vectors +.section .vectors, "a", %progbits .global __vectors `)) err = t.Execute(out, device.metadata) |