mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 18:56:03 +00:00
Fix coldboot init, Exosphere makes it to PK2LDR in this commit.
This commit is contained in:
parent
63d0b08ac4
commit
0a80a7caf5
4 changed files with 30 additions and 18 deletions
|
@ -93,15 +93,17 @@ static void configure_ttbls(void) {
|
||||||
tzram_map_all_segments(mmu_l3_tbl);
|
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 *warmboot_crt0_reloc = &reloc_list->relocs[0];
|
||||||
coldboot_crt0_reloc_t *main_reloc = &reloc_list->relocs[reloc_list->nb_relocs_pre_mmu_init];
|
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. */
|
/* 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++) {
|
uintptr_t main_pa = (uintptr_t)warmboot_crt0_reloc->vma | ((uintptr_t)main_reloc->vma & 0xFFF);
|
||||||
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;
|
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,7 +122,9 @@ uintptr_t get_coldboot_crt0_stack_address(void) {
|
||||||
return TZRAM_GET_SEGMENT_PA(TZRAM_SEGMENT_ID_CORE3_STACK) + 0x800;
|
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 */
|
/* Custom approach */
|
||||||
reloc_list->reloc_base = (uintptr_t)__start_cold;
|
reloc_list->reloc_base = (uintptr_t)__start_cold;
|
||||||
|
|
||||||
|
@ -131,19 +135,19 @@ void coldboot_init(coldboot_crt0_reloc_list_t *reloc_list) {
|
||||||
do_relocation(reloc_list, i);
|
do_relocation(reloc_list, i);
|
||||||
}
|
}
|
||||||
/* At this point, we can (and will) access functions located in .warm_crt0 */
|
/* At this point, we can (and will) access functions located in .warm_crt0 */
|
||||||
|
translate_warmboot_func_list(reloc_list, func_list);
|
||||||
translate_warmboot_func_list(reloc_list);
|
|
||||||
|
|
||||||
/* TODO: initialize DMA controllers, etc. */
|
/* TODO: initialize DMA controllers, etc. */
|
||||||
configure_ttbls();
|
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 */
|
/* Copy or clear the remaining sections */
|
||||||
for(size_t i = 0; i < reloc_list->nb_relocs_post_mmu_init; i++) {
|
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);
|
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 */
|
/* At this point we can access all the mapped segments (all other functions, data...) normally */
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,8 @@ __start_cold:
|
||||||
mov sp, x0
|
mov sp, x0
|
||||||
mov fp, #0
|
mov fp, #0
|
||||||
|
|
||||||
adrp x19, g_coldboot_crt0_relocation_list
|
adr x19, g_coldboot_crt0_relocation_list
|
||||||
add x19, x19, #:lo12:g_coldboot_crt0_relocation_list
|
adr x1, g_coldboot_crt0_main_func_list
|
||||||
mov x0, x19
|
mov x0, x19
|
||||||
bl coldboot_init
|
bl coldboot_init
|
||||||
|
|
||||||
|
@ -212,7 +212,6 @@ __jump_to_lower_el:
|
||||||
g_coldboot_crt0_relocation_list:
|
g_coldboot_crt0_relocation_list:
|
||||||
.quad 0, __loaded_end_lma__ /* __start_cold, to be set & loaded size */
|
.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 1, 5 /* number of sections to relocate/clear before & after mmu init */
|
||||||
.quad g_warmboot_crt0_main_func_list
|
|
||||||
/* Relocations */
|
/* Relocations */
|
||||||
.quad __warmboot_crt0_start__, __warmboot_crt0_end__, __warmboot_crt0_lma__
|
.quad __warmboot_crt0_start__, __warmboot_crt0_end__, __warmboot_crt0_lma__
|
||||||
.quad __main_start__, __main_bss_start__, __main_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 __main_bss_start__, __main_end__, 0
|
||||||
.quad __pk2ldr_bss_start__, __pk2ldr_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
|
.align 3
|
||||||
.section .warm_crt0.data.g_warmboot_crt0_main_func_list, "aw", %progbits
|
.section .warm_crt0.data.g_warmboot_crt0_main_func_list, "aw", %progbits
|
||||||
.global g_warmboot_crt0_main_func_list
|
.global g_warmboot_crt0_main_func_list
|
||||||
|
|
|
@ -31,7 +31,7 @@ typedef struct {
|
||||||
} funcs;
|
} funcs;
|
||||||
uintptr_t addrs[3];
|
uintptr_t addrs[3];
|
||||||
};
|
};
|
||||||
} warmboot_func_list_t;
|
} boot_func_list_t;
|
||||||
|
|
||||||
/* For coldboot */
|
/* For coldboot */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -45,7 +45,6 @@ typedef struct {
|
||||||
size_t loaded_bin_size;
|
size_t loaded_bin_size;
|
||||||
size_t nb_relocs_pre_mmu_init; /* first is always warmboot_crt0 */
|
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 */
|
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_t relocs[];
|
||||||
} coldboot_crt0_reloc_list_t;
|
} coldboot_crt0_reloc_list_t;
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,6 @@ void set_memory_registers_enable_mmu(void) {
|
||||||
__set_memory_registers(ttbr0, vbar, cpuectlr, scr, tcr, cptr, mair, sctlr);
|
__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;
|
(void)func_list;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue