aboutsummaryrefslogtreecommitdiffhomepage
path: root/targets
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-09-13 00:59:39 +0200
committerAyke van Laethem <[email protected]>2018-09-13 00:59:39 +0200
commit76e77917d80b389e5901bf834bdf62e262279e92 (patch)
treeb687bbe828c260cd33991c4f78aceb964ef7ae3f /targets
parente389d38decfd637585ce43774ba0a052ad1b8f59 (diff)
downloadtinygo-76e77917d80b389e5901bf834bdf62e262279e92.tar.gz
tinygo-76e77917d80b389e5901bf834bdf62e262279e92.zip
targets: move target-specific files to this directory
Diffstat (limited to 'targets')
-rw-r--r--targets/arduino.json2
-rw-r--r--targets/arm.ld82
-rw-r--r--targets/avr.S62
-rw-r--r--targets/avr.ld43
-rw-r--r--targets/pca10040.json2
5 files changed, 189 insertions, 2 deletions
diff --git a/targets/arduino.json b/targets/arduino.json
index a490c8259..1890b9ee7 100644
--- a/targets/arduino.json
+++ b/targets/arduino.json
@@ -2,5 +2,5 @@
"llvm-target": "avr-atmel-none",
"build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"],
"linker": "avr-gcc",
- "pre-link-args": ["-nostdlib", "-T", "avr.ld", "-Wl,--gc-sections", "avr.S"]
+ "pre-link-args": ["-nostdlib", "-T", "targets/avr.ld", "-Wl,--gc-sections", "targets/avr.S"]
}
diff --git a/targets/arm.ld b/targets/arm.ld
new file mode 100644
index 000000000..76a64f1ff
--- /dev/null
+++ b/targets/arm.ld
@@ -0,0 +1,82 @@
+
+MEMORY
+{
+ FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 256K /* .text */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
+}
+
+_stack_size = 2K;
+
+/* define output sections */
+SECTIONS
+{
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ _stext = .;
+ . = ALIGN(4);
+ KEEP(*(.isr_vector))
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = ALIGN(4);
+ _etext = .; /* define a global symbol at end of code */
+ } >FLASH_TEXT
+
+ /* Put the stack at the bottom of RAM, so that the application will
+ * crash on stack overflow instead of silently corrupting memory.
+ * See: http://blog.japaric.io/stack-overflow-protection/ */
+ .stack :
+ {
+ . = ALIGN(4);
+ . += _stack_size;
+ __StackTop = .;
+ } >RAM
+
+ /* This is the initialized data section
+ The program executes knowing that the data is in the RAM
+ but the loader puts the initial values in the FLASH (inidata).
+ It is one task of the startup to copy the initial values from FLASH to RAM. */
+ .data :
+ {
+ . = ALIGN(4);
+ _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
+ } >RAM AT>FLASH_TEXT
+
+ /* Uninitialized data section */
+ .bss :
+ {
+ . = ALIGN(4);
+ _sbss = .; /* define a global symbol at bss start; used by startup code */
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ebss = .; /* define a global symbol at bss end; used by startup code and GC */
+ } >RAM
+
+ /DISCARD/ :
+ {
+ *(.ARM.exidx.*)
+ *(.ARM.attributes)
+ *(.stack) /* from nrfx */
+ *(.heap) /* from nrfx */
+ }
+}
+
+/* For the nrfx startup file. */
+__etext = _etext;
+__data_start__ = _sdata;
+__bss_start__ = _sbss;
+__bss_end__ = _ebss;
+
+/* For the memory allocator. */
+_heap_start = _ebss;
+_heap_end = ORIGIN(RAM) + LENGTH(RAM);
diff --git a/targets/avr.S b/targets/avr.S
new file mode 100644
index 000000000..962527597
--- /dev/null
+++ b/targets/avr.S
@@ -0,0 +1,62 @@
+.section .isr
+isr:
+ rjmp reset
+
+.org 0x18 ; WDT
+ rjmp wdt
+
+; Startup code
+.section .reset
+.org 26
+reset:
+ clr r1 ; r1 is expected to be 0 by the C calling convention
+
+ ; Zero .bss
+clear_bss:
+ ldi xl, lo8(_sbss)
+ ldi xh, hi8(_sbss)
+clear_bss_loop:
+ ldi yl, lo8(_ebss)
+ ldi yh, hi8(_ebss)
+ cp xl, yl ; if x == y
+ cpc xh, yh
+ breq clear_bss_end
+ st x+, r1 ; zero byte in *x
+ rjmp clear_bss_loop
+clear_bss_end:
+
+ ; Set up the stack pointer.
+ ldi xl, lo8(_stack_top)
+ ldi xh, hi8(_stack_top)
+ out 0x3d, xl; SPL
+ out 0x3e, xh; SPH
+
+ ; Enable interrupts.
+ ; TODO: make sure interrupts are started after all initializers have run.
+ sei
+
+ ; main will be placed right after here by the linker script so there's no
+ ; need to jump.
+
+
+; The only thing this WDT handler really does is disable itself, to get out of
+; sleep mode.
+.section .text.wdt
+wdt:
+ push r16
+
+ clr r16
+ wdr ; Reset watchdog
+ out 0x34, r16 ; Clear reset reason (MCUSR)
+
+ ; part 1: set WDCE and WDE to enable editing WDTCSR
+ lds r16, 0x60 ; r16 = WDTCSR
+ ori r16, 0x18 ; r16 |= WDCE | WDE
+ sts 0x60, r16 ; WDTCSR = r16
+
+ ; part 2: within 4 clock cycles, set the new value for WDTCSR
+ clr r16
+ sts 0x60, r16 ; WDTCSR = 0
+
+ pop r16
+ reti
diff --git a/targets/avr.ld b/targets/avr.ld
new file mode 100644
index 000000000..a26e00031
--- /dev/null
+++ b/targets/avr.ld
@@ -0,0 +1,43 @@
+
+MEMORY
+{
+ FLASH_TEXT (rw) : ORIGIN = 0, LENGTH = 32256
+ RAM (xrw) : ORIGIN = 0, LENGTH = 2K
+}
+
+_stack_size = 512;
+
+SECTIONS
+{
+ .text :
+ {
+ KEEP(*(.isr))
+ KEEP(*(.reset))
+ KEEP(*(.text.main)) /* main must follow the reset handler */
+ *(.text.*)
+ *(.rodata)
+ *(.rodata.*)
+ }
+
+ .stack :
+ {
+ . += _stack_size;
+ _stack_top = .;
+ } >RAM
+
+ .data :
+ {
+ *(.data)
+ *(.data*)
+ } >RAM AT>FLASH_TEXT
+
+ .bss :
+ {
+ _sbss = .;
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+ _ebss = .;
+ _heap_start = .;
+ } >RAM
+}
diff --git a/targets/pca10040.json b/targets/pca10040.json
index 54eed5e42..cc17d784f 100644
--- a/targets/pca10040.json
+++ b/targets/pca10040.json
@@ -2,5 +2,5 @@
"llvm-target": "armv7m-none-eabi",
"build-tags": ["nrf", "nrf52", "nrf52832", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
- "pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "arm.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-D__STARTUP_CLEAR_BSS", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/gcc_startup_nrf51.S", "lib/nrfx/mdk/system_nrf52.c"]
+ "pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "targets/arm.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-D__STARTUP_CLEAR_BSS", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/gcc_startup_nrf51.S", "lib/nrfx/mdk/system_nrf52.c"]
}