1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-09 21:51:45 +00:00

Fix coldboot init, Exosphere makes it to PK2LDR in this commit.

This commit is contained in:
Michael Scire 2018-03-01 20:10:05 -08:00
parent 63d0b08ac4
commit 0a80a7caf5
4 changed files with 30 additions and 18 deletions

View file

@ -93,15 +93,17 @@ static void configure_ttbls(void) {
tzram_map_all_segments(mmu_l3_tbl);
}
static void translate_warmboot_func_list(coldboot_crt0_reloc_list_t *reloc_list) {
static void translate_warmboot_func_list(coldboot_crt0_reloc_list_t *reloc_list, boot_func_list_t *func_list) {
coldboot_crt0_reloc_t *warmboot_crt0_reloc = &reloc_list->relocs[0];
coldboot_crt0_reloc_t *main_reloc = &reloc_list->relocs[reloc_list->nb_relocs_pre_mmu_init];
/* The main segment immediately follows the warmboot crt0 in TZRAM, in the same page. */
uintptr_t main_pa = (uintptr_t)warmboot_crt0_reloc->vma | ((uintptr_t)main_reloc->vma & ~0xFFF);
for(size_t i = 0; i < reloc_list->func_list->nb_funcs; i++) {
if(reloc_list->func_list->addrs[i] >= 0x1F0000000ull) {
reloc_list->func_list->addrs[i] = main_pa + reloc_list->func_list->addrs[i] - (uintptr_t)main_reloc->vma;
uintptr_t main_pa = (uintptr_t)warmboot_crt0_reloc->vma | ((uintptr_t)main_reloc->vma & 0xFFF);
for(size_t i = 0; i < func_list->nb_funcs; i++) {
if(func_list->addrs[i] >= 0x1F0000000ull) {
func_list->addrs[i] = main_pa + func_list->addrs[i] - (uintptr_t)main_reloc->vma;
}
}
}
@ -120,30 +122,32 @@ uintptr_t get_coldboot_crt0_stack_address(void) {
return TZRAM_GET_SEGMENT_PA(TZRAM_SEGMENT_ID_CORE3_STACK) + 0x800;
}
void coldboot_init(coldboot_crt0_reloc_list_t *reloc_list) {
void coldboot_init(coldboot_crt0_reloc_list_t *reloc_list, boot_func_list_t *func_list) {
/* Custom approach */
reloc_list->reloc_base = (uintptr_t)__start_cold;
/* TODO: Set NX BOOTLOADER clock time field */
/* This at least copies .warm_crt0 to its VMA. */
for(size_t i = 0; i < reloc_list->nb_relocs_pre_mmu_init; i++) {
do_relocation(reloc_list, i);
}
/* At this point, we can (and will) access functions located in .warm_crt0 */
translate_warmboot_func_list(reloc_list);
translate_warmboot_func_list(reloc_list, func_list);
/* TODO: initialize DMA controllers, etc. */
configure_ttbls();
reloc_list->func_list->funcs.set_memory_registers_enable_mmu();
func_list->funcs.set_memory_registers_enable_mmu();
/* Copy or clear the remaining sections */
for(size_t i = 0; i < reloc_list->nb_relocs_post_mmu_init; i++) {
do_relocation(reloc_list, reloc_list->nb_relocs_pre_mmu_init + i);
}
reloc_list->func_list->funcs.flush_dcache_all();
reloc_list->func_list->funcs.invalidate_icache_all();
func_list->funcs.flush_dcache_all();
func_list->funcs.invalidate_icache_all();
/* At this point we can access all the mapped segments (all other functions, data...) normally */
}

View file

@ -81,8 +81,8 @@ __start_cold:
mov sp, x0
mov fp, #0
adrp x19, g_coldboot_crt0_relocation_list
add x19, x19, #:lo12:g_coldboot_crt0_relocation_list
adr x19, g_coldboot_crt0_relocation_list
adr x1, g_coldboot_crt0_main_func_list
mov x0, x19
bl coldboot_init
@ -212,7 +212,6 @@ __jump_to_lower_el:
g_coldboot_crt0_relocation_list:
.quad 0, __loaded_end_lma__ /* __start_cold, to be set & loaded size */
.quad 1, 5 /* number of sections to relocate/clear before & after mmu init */
.quad g_warmboot_crt0_main_func_list
/* Relocations */
.quad __warmboot_crt0_start__, __warmboot_crt0_end__, __warmboot_crt0_lma__
.quad __main_start__, __main_bss_start__, __main_lma__
@ -222,6 +221,16 @@ g_coldboot_crt0_relocation_list:
.quad __main_bss_start__, __main_end__, 0
.quad __pk2ldr_bss_start__, __pk2ldr_end__, 0
.align 3
.section .cold_crt0.data.g_coldboot_crt0_main_func_list, "aw", %progbits
.global g_coldboot_crt0_main_func_list
g_coldboot_crt0_main_func_list:
.quad 3 /* Number of functions */
/* Functions */
.quad set_memory_registers_enable_mmu
.quad flush_dcache_all
.quad invalidate_icache_all
.align 3
.section .warm_crt0.data.g_warmboot_crt0_main_func_list, "aw", %progbits
.global g_warmboot_crt0_main_func_list

View file

@ -31,7 +31,7 @@ typedef struct {
} funcs;
uintptr_t addrs[3];
};
} warmboot_func_list_t;
} boot_func_list_t;
/* For coldboot */
typedef struct {
@ -45,7 +45,6 @@ typedef struct {
size_t loaded_bin_size;
size_t nb_relocs_pre_mmu_init; /* first is always warmboot_crt0 */
size_t nb_relocs_post_mmu_init; /* first is always main segment excl. .bss */
warmboot_func_list_t *func_list;
coldboot_crt0_reloc_t relocs[];
} coldboot_crt0_reloc_list_t;

View file

@ -63,6 +63,6 @@ void set_memory_registers_enable_mmu(void) {
__set_memory_registers(ttbr0, vbar, cpuectlr, scr, tcr, cptr, mair, sctlr);
}
void warmboot_init(warmboot_func_list_t *func_list) {
void warmboot_init(boot_func_list_t *func_list) {
(void)func_list;
}