mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-17 17:36:44 +00:00
Clear bss at runtime like Nintendo actually does
This commit is contained in:
parent
303774aeb7
commit
0a89831193
2 changed files with 32 additions and 17 deletions
|
@ -68,8 +68,14 @@ SECTIONS
|
|||
build/package2.o(.rodata*)
|
||||
build/package2.o(.data*)
|
||||
. = ALIGN(8);
|
||||
} >pk2ldr AT>fake
|
||||
|
||||
.pk2ldr.bss :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__pk2ldr_bss_start__ = ABSOLUTE(.);
|
||||
build/package2.o(.bss*)
|
||||
. = ALIGN(16);
|
||||
. = ALIGN(8);
|
||||
__pk2ldr_end__ = ABSOLUTE(.);
|
||||
} >pk2ldr AT>fake
|
||||
|
||||
|
@ -79,7 +85,7 @@ SECTIONS
|
|||
__vectors_lma__ = LOADADDR(.vectors);
|
||||
__vectors_start__ = ABSOLUTE(.);
|
||||
KEEP (*(.vectors*))
|
||||
. = ALIGN(16);
|
||||
. = ALIGN(8);
|
||||
__vectors_end__ = ABSOLUTE(.);
|
||||
} >evt AT>fake
|
||||
|
||||
|
@ -178,16 +184,6 @@ SECTIONS
|
|||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(8);
|
||||
/*
|
||||
We're too lazy to clear BSS so we integrate it into .data.
|
||||
Nintendo does the same for this main segment's BSS.
|
||||
*/
|
||||
__bss_start__ = ABSOLUTE(.);
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
__bss_end__ = ABSOLUTE(.);
|
||||
} >main AT>fake
|
||||
|
||||
|
||||
|
@ -209,6 +205,17 @@ SECTIONS
|
|||
.dynstr : { *(.dynstr) } >main AT>fake
|
||||
.rela.dyn : { *(.rela.*); __main_end__ = ABSOLUTE(.);} >main AT>fake
|
||||
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__main_bss_start__ = ABSOLUTE(.);
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
__main_end__ = ABSOLUTE(.);
|
||||
} >main AT>fake
|
||||
|
||||
__end__ = ABSOLUTE(.) ;
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <string.h>
|
||||
#include "utils.h"
|
||||
#include "mmu.h"
|
||||
#include "memory_map.h"
|
||||
|
@ -5,8 +6,8 @@
|
|||
extern const uint8_t __start_cold[];
|
||||
|
||||
extern const uint8_t __warmboot_crt0_start__[], __warmboot_crt0_end__[], __warmboot_crt0_lma__[];
|
||||
extern const uint8_t __main_start__[], __main_end__[], __main_lma__[];
|
||||
extern const uint8_t __pk2ldr_start__[], __pk2ldr_end__[], __pk2ldr_lma__[];
|
||||
extern const uint8_t __main_start__[], __main_bss_start__[], __main_end__[], __main_lma__[];
|
||||
extern const uint8_t __pk2ldr_start__[], __pk2ldr_bss_start__[], __pk2ldr_end__[], __pk2ldr_lma__[];
|
||||
extern const uint8_t __vectors_start__[], __vectors_end__[], __vectors_lma__[];
|
||||
|
||||
/* warmboot_init.c */
|
||||
|
@ -120,10 +121,17 @@ __attribute__((target("cmodel=large"), noinline)) static void copy_other_section
|
|||
copy_lma_to_vma(__vectors_start__, __vectors_lma__, __vectors_end__ - __vectors_start__);
|
||||
}
|
||||
|
||||
__attribute__((target("cmodel=large"), noinline)) static void clear_bss(void) {
|
||||
memset((void *)__pk2ldr_bss_start__, 0, __pk2ldr_end__ - __pk2ldr_bss_start__);
|
||||
memset((void *)__main_bss_start__, 0, __main_end__ - __main_bss_start__);
|
||||
}
|
||||
|
||||
void coldboot_init(void) {
|
||||
/* TODO: Set NX BOOTLOADER clock time field */
|
||||
|
||||
copy_warmboot_crt0();
|
||||
/* At this point, we can (and will) access functions located in .warm_crt0 */
|
||||
|
||||
/* TODO: initialize DMA controllers, etc. */
|
||||
configure_ttbls();
|
||||
copy_other_sections();
|
||||
|
@ -131,7 +139,7 @@ void coldboot_init(void) {
|
|||
|
||||
flush_dcache_all_tzram_pa();
|
||||
invalidate_icache_all_inner_shareable_tzram_pa();
|
||||
/* At this point we can access all the mapped segments */
|
||||
/* TODO: zero-initialize the cpu context */
|
||||
/* Nintendo clears the (emtpy) pk2ldr's BSS section here , but we embed it 0-filled in the binary */
|
||||
/* At this point we can access all the mapped segments (all other functions, data...) normally */
|
||||
|
||||
clear_bss();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue