aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--targets/avr.S17
-rw-r--r--targets/avr.ld4
2 files changed, 21 insertions, 0 deletions
diff --git a/targets/avr.S b/targets/avr.S
index 838fd7841..b62c1add6 100644
--- a/targets/avr.S
+++ b/targets/avr.S
@@ -17,6 +17,23 @@ reset:
out 0x3d, xl; SPL
out 0x3e, xh; SPH
+ ; Initialize .data
+init_data:
+ ldi xl, lo8(_sdata)
+ ldi xh, hi8(_sdata)
+ ldi yl, lo8(_edata)
+ ldi yh, hi8(_edata)
+ ldi zl, lo8(_sidata)
+ ldi zh, hi8(_sidata)
+init_data_loop:
+ cp xl, yl ; if x == y
+ cpc xh, yh
+ breq init_data_end ; goto main
+ lpm r0, Z+ ; r0 = *(z++)
+ st X+, r0 ; *(x++) = r0
+ rjmp init_data_loop ; goto init_data_loop
+init_data_end:
+
; main will be placed right after here by the linker script so there's no
; need to jump.
diff --git a/targets/avr.ld b/targets/avr.ld
index a26e00031..bd23d2744 100644
--- a/targets/avr.ld
+++ b/targets/avr.ld
@@ -25,10 +25,14 @@ SECTIONS
_stack_top = .;
} >RAM
+ _sidata = LOADADDR(.data);
+
.data :
{
+ _sdata = .;
*(.data)
*(.data*)
+ _edata = .;
} >RAM AT>FLASH_TEXT
.bss :