avr: implement .data section

This doesn't completely work for some reason as the first character of
.data is corrupted, but otherwise it works.
This commit is contained in:
Ayke van Laethem
2018-09-16 16:26:04 +02:00
parent 39e3fe28db
commit a02426948b
2 changed files with 21 additions and 0 deletions
+17
View File
@@ -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.
+4
View File
@@ -25,10 +25,14 @@ SECTIONS
_stack_top = .;
} >RAM
_sidata = LOADADDR(.data);
.data :
{
_sdata = .;
*(.data)
*(.data*)
_edata = .;
} >RAM AT>FLASH_TEXT
.bss :