aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-04-14 17:55:07 +0200
committerAyke van Laethem <[email protected]>2020-06-27 01:22:31 +0200
commitce0abac5a3f4373fe944ba6ff5fe38c68bb65e29 (patch)
treef9c649ca01b4db703db5e597519e00300097edda
parent43d7f48de4cd82ba810690b806a78b0d690fc29d (diff)
downloadtinygo-avr-compiler-rt.tar.gz
tinygo-avr-compiler-rt.zip
avr: use compiler-rtavr-compiler-rt
-rw-r--r--builder/builtins.go10
-rw-r--r--builder/library.go3
-rw-r--r--src/internal/task/task_stack_avr.go2
-rw-r--r--targets/arduino.json4
-rw-r--r--targets/atmega1284p.json5
-rw-r--r--targets/atmega328p.json2
-rw-r--r--targets/avr.S24
-rw-r--r--targets/avr.json13
-rw-r--r--targets/avr.ld13
-rwxr-xr-xtools/gen-device-avr/gen-device-avr.go2
10 files changed, 60 insertions, 18 deletions
diff --git a/builder/builtins.go b/builder/builtins.go
index ed159e7ed..a1500b826 100644
--- a/builder/builtins.go
+++ b/builder/builtins.go
@@ -16,8 +16,10 @@ var genericBuiltins = []string{
"addvsi3.c",
"addvti3.c",
"apple_versioning.c",
+ "ashlsi3.c",
"ashldi3.c",
"ashlti3.c",
+ "ashrsi3.c",
"ashrdi3.c",
"ashrti3.c",
"bswapdi2.c",
@@ -72,7 +74,9 @@ var genericBuiltins = []string{
"floatunsisf.c",
"floatuntidf.c",
"floatuntisf.c",
- //"int_util.c",
+ "fp_mode.c",
+ "int_util.c",
+ "lshrsi3.c",
"lshrdi3.c",
"lshrti3.c",
"moddi3.c",
@@ -86,6 +90,7 @@ var genericBuiltins = []string{
"muloti4.c",
"mulsc3.c",
"mulsf3.c",
+ "mulsi3.c",
"multi3.c",
"multf3.c",
"mulvdi3.c",
@@ -108,6 +113,7 @@ var genericBuiltins = []string{
"powidf2.c",
"powisf2.c",
"powitf2.c",
+ "powixf2.c",
"subdf3.c",
"subsf3.c",
"subvdi3.c",
@@ -159,7 +165,7 @@ var aeabiBuiltins = []string{
var CompilerRT = Library{
name: "compiler-rt",
cflags: func() []string { return []string{"-Werror", "-Wall", "-std=c11", "-nostdlibinc"} },
- sourceDir: "lib/compiler-rt/lib/builtins",
+ sourceDir: "llvm-project.master/compiler-rt/lib/builtins",
sources: func(target string) []string {
builtins := append([]string{}, genericBuiltins...) // copy genericBuiltins
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
diff --git a/builder/library.go b/builder/library.go
index 7bb506c76..3016eef86 100644
--- a/builder/library.go
+++ b/builder/library.go
@@ -74,6 +74,9 @@ func (l *Library) Load(target string) (path string, err error) {
if strings.HasPrefix(target, "riscv32-") {
args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128")
}
+ if strings.HasPrefix(target, "avr-") {
+ args = append(args, "-mdouble=64", "-mmcu=atmega1284p")
+ }
// Compile all sources.
var objs []string
diff --git a/src/internal/task/task_stack_avr.go b/src/internal/task/task_stack_avr.go
index cbd5a9888..fb142a8b8 100644
--- a/src/internal/task/task_stack_avr.go
+++ b/src/internal/task/task_stack_avr.go
@@ -4,7 +4,7 @@ package task
import "unsafe"
-const stackSize = 256
+const stackSize = 1024
// calleeSavedRegs is the list of registers that must be saved and restored when
// switching between tasks. Also see scheduler_avr.S that relies on the
diff --git a/targets/arduino.json b/targets/arduino.json
index fbbca7a8f..3e1023988 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"
}
diff --git a/targets/atmega1284p.json b/targets/atmega1284p.json
index ef4239426..fec2d4189 100644
--- a/targets/atmega1284p.json
+++ b/targets/atmega1284p.json
@@ -7,9 +7,8 @@
"-mmcu=atmega1284p"
],
"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/atmega328p.json b/targets/atmega328p.json
index 64aefc98a..e4e0431c5 100644
--- a/targets/atmega328p.json
+++ b/targets/atmega328p.json
@@ -7,7 +7,7 @@
"-mmcu=atmega328p"
],
"ldflags": [
- "-mmcu=avr5"
+ "-mavr5"
],
"linkerscript": "src/device/avr/atmega328p.ld",
"extra-files": [
diff --git a/targets/avr.S b/targets/avr.S
index c5881c820..47be1fdd3 100644
--- a/targets/avr.S
+++ b/targets/avr.S
@@ -2,6 +2,30 @@
; in Go.
; The reset vector is device-specific and is generated by tools/gen-device-avr.py.
+#ifndef xl
+#define xl r26
+#endif
+
+#ifndef xh
+#define xh r27
+#endif
+
+#ifndef yl
+#define yl r28
+#endif
+
+#ifndef yh
+#define yh r29
+#endif
+
+#ifndef zl
+#define zl r30
+#endif
+
+#ifndef zh
+#define zh r31
+#endif
+
; Startup code
.section .text.__vector_RESET
.global __vector_RESET
diff --git a/targets/avr.json b/targets/avr.json
index b7f87ca42..459fae32f 100644
--- a/targets/avr.json
+++ b/targets/avr.json
@@ -2,16 +2,21 @@
"build-tags": ["avr", "baremetal", "linux", "arm"],
"goos": "linux",
"goarch": "arm",
- "compiler": "avr-gcc",
+ "compiler": "clang",
"gc": "conservative",
- "linker": "avr-gcc",
+ "linker": "llvm-build.master/bin/ld.lld",
"scheduler": "none",
+ "rtlib": "compiler-rt",
+ "libc": "picolibc",
"cflags": [
- "-gdwarf-4"
+ "--target=avr-atmel-none",
+ "-g",
+ "-Werror",
+ "-Qunused-arguments"
],
"ldflags": [
"-T", "targets/avr.ld",
- "-Wl,--gc-sections"
+ "--gc-sections"
],
"extra-files": [
"src/runtime/scheduler_avr.S"
diff --git a/targets/avr.ld b/targets/avr.ld
index a7c2d90cf..246e327b8 100644
--- a/targets/avr.ld
+++ b/targets/avr.ld
@@ -5,17 +5,22 @@ MEMORY
RAM (xrw) : ORIGIN = 0x800000 + __ram_start, LENGTH = __ram_size
}
+ENTRY(main)
+
SECTIONS
{
- .text :
+ .text : ALIGN(2)
{
KEEP(*(.vectors))
KEEP(*(.text.__vector_RESET))
KEEP(*(.text.main)) /* main must follow the reset handler */
+ *(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
- }
+ *(.progmem.data)
+ . = ALIGN(16); /* required because of lld (not sure why) */
+ } > FLASH_TEXT
.stack (NOLOAD) :
{
@@ -29,7 +34,7 @@ SECTIONS
{
_sdata = .; /* used by startup code */
*(.data)
- *(.data*)
+ *(.data.*)
_edata = .; /* used by startup code */
} >RAM AT>FLASH_TEXT
@@ -37,7 +42,7 @@ SECTIONS
{
_sbss = .; /* used by startup code */
*(.bss)
- *(.bss*)
+ *(.bss.*)
*(COMMON)
_ebss = .; /* used by startup code */
} >RAM
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go
index 9b9c627ae..97e4bea59 100755
--- a/tools/gen-device-avr/gen-device-avr.go
+++ b/tools/gen-device-avr/gen-device-avr.go
@@ -407,7 +407,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)