megadrive_test1
changeset 3:54739a11be66
- .data copy and .bss clearing
- also made sure .data and .bss start and end markers are dword-aligned to make
sure I can copy 4bytes at a time
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 31 Jan 2017 07:11:17 +0200 |
parents | 51d1d6761601 |
children | e7138066c7ea |
files | megadrive.ldscript src/startup.s |
diffstat | 2 files changed, 25 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/megadrive.ldscript Mon Jan 30 16:57:51 2017 +0200 1.2 +++ b/megadrive.ldscript Tue Jan 31 07:11:17 2017 +0200 1.3 @@ -21,23 +21,26 @@ 1.4 .rodata : { * (.rodata); } >rom 1.5 1.6 /* place the load address of the .data section after .rodata */ 1.7 + . = ALIGN(4); 1.8 _data_lma = .; 1.9 _rom_end = _data_lma + _data_size; 1.10 1.11 /* ---- start of RAM ---- */ 1.12 . = 0xff0000; 1.13 /* place the .data section at the start of RAM */ 1.14 - .data : AT (_data_lma) { 1.15 + .data ALIGN(4): AT (_data_lma) { 1.16 _data_start = .; 1.17 * (.data); 1.18 + . = ALIGN(4); 1.19 _data_end = .; 1.20 } >ram 1.21 _data_size = SIZEOF(.data); 1.22 1.23 /* place the .bss section at the end */ 1.24 - .bss : { 1.25 + .bss ALIGN(4): { 1.26 _bss_start = .; 1.27 * (.bss); 1.28 + . = ALIGN(4); 1.29 _bss_end = .; 1.30 } >ram 1.31 _bss_size = SIZEOF(.bss);
2.1 --- a/src/startup.s Mon Jan 30 16:57:51 2017 +0200 2.2 +++ b/src/startup.s Tue Jan 31 07:11:17 2017 +0200 2.3 @@ -1,8 +1,27 @@ 2.4 -| TODO: copy .data and zero .bss 2.5 .text 2.6 .extern main 2.7 2.8 .global start 2.9 start: 2.10 + | copy .data section from ROM to RAM 2.11 + move.l #_data_lma, %a0 2.12 + move.l #_data_start, %a1 2.13 + move.l #_data_end, %a2 2.14 + cmp.l %a1, %a2 2.15 + beq.s 1f | skip data copy if the section is empty 2.16 +0: move.l (%a0)+, (%a1)+ 2.17 + cmp.l %a1, %a2 2.18 + bne.s 0b 2.19 +1: 2.20 + 2.21 + | zero the .bss section 2.22 + move.l #_bss_start, %a0 2.23 + move.l #_bss_end, %a1 2.24 + cmp.l %a0, %a1 2.25 + beq.s 1f | skip bss zeroing if the section is empty 2.26 +0: clr.l (%a0)+ 2.27 + cmp.l %a0, %a1 2.28 + bne.s 0b 2.29 +1: 2.30 jsr main 2.31 stop #0x2700