# HG changeset patch # User John Tsiombikas # Date 1485839477 -7200 # Node ID 54739a11be66dfbe19281b62b110a9f57db1bd7f # Parent 51d1d6761601723f84e92d52fa202120fe05ca84 - .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 diff -r 51d1d6761601 -r 54739a11be66 megadrive.ldscript --- a/megadrive.ldscript Mon Jan 30 16:57:51 2017 +0200 +++ b/megadrive.ldscript Tue Jan 31 07:11:17 2017 +0200 @@ -21,23 +21,26 @@ .rodata : { * (.rodata); } >rom /* place the load address of the .data section after .rodata */ + . = ALIGN(4); _data_lma = .; _rom_end = _data_lma + _data_size; /* ---- start of RAM ---- */ . = 0xff0000; /* place the .data section at the start of RAM */ - .data : AT (_data_lma) { + .data ALIGN(4): AT (_data_lma) { _data_start = .; * (.data); + . = ALIGN(4); _data_end = .; } >ram _data_size = SIZEOF(.data); /* place the .bss section at the end */ - .bss : { + .bss ALIGN(4): { _bss_start = .; * (.bss); + . = ALIGN(4); _bss_end = .; } >ram _bss_size = SIZEOF(.bss); diff -r 51d1d6761601 -r 54739a11be66 src/startup.s --- a/src/startup.s Mon Jan 30 16:57:51 2017 +0200 +++ b/src/startup.s Tue Jan 31 07:11:17 2017 +0200 @@ -1,8 +1,27 @@ -| TODO: copy .data and zero .bss .text .extern main .global start start: + | copy .data section from ROM to RAM + move.l #_data_lma, %a0 + move.l #_data_start, %a1 + move.l #_data_end, %a2 + cmp.l %a1, %a2 + beq.s 1f | skip data copy if the section is empty +0: move.l (%a0)+, (%a1)+ + cmp.l %a1, %a2 + bne.s 0b +1: + + | zero the .bss section + move.l #_bss_start, %a0 + move.l #_bss_end, %a1 + cmp.l %a0, %a1 + beq.s 1f | skip bss zeroing if the section is empty +0: clr.l (%a0)+ + cmp.l %a0, %a1 + bne.s 0b +1: jsr main stop #0x2700