freebsd的启动代码在https://github.com/freebsd/freebsd/blob/projects/arm64/sys/arm64/arm64/locore.S
在入口需要关闭mmu,D-Cache 一定要关闭,I-Cache 不要求关闭。
/*
* We assume:
* MMU off
* D-Cache: off
* I-Cache: on or off
* We are loaded at a 2MiB aligned address
*/
#define INIT_STACK_SIZE (PAGE_SIZE * 4)
.text
.globl _start
_start:
/* Drop to EL1 */
bl drop_to_el1
/* Get the virt -> phys offset */
bl get_virt_delta
/*
* At this point:
* x29 = PA - VA
* x28 = Our physical load address
*/
/* Create the page tables */
bl create_pagetables
/*
* At this point:
* x27 = TTBR0 table
* x26 = TTBR1 table
*/
#开启smmu
/* Enable the mmu */
bl start_mmu
/* Jump to the virtual address space */
ldr x15, .Lvirtdone
br x15
virtdone:
/* Set up the stack */
adr x25, initstack
mov sp, x25
/* Zero the BSS */
ldr x15, .Lbss
ldr x14, .Lend
b 2f
1:
str xzr, [x15], #8
cmp x15, x14
b.lo 1b
2:
/* Backup the module pointer */
mov x1, x0
/* Make the page table base a virtual address */
sub x26, x26, x29
sub sp, sp, #(64 * 4)
mov x0, sp
/* Degate the delda so it is VA -> PA */
neg x29, x29
str x1, [x0] /* modulep */
str x26, [x0, 8] /* kern_l1pt */
str x29, [x0, 16] /* kern_delta */
str x25, [x0, 24] /* kern_stack */
#从这里开始跳入到c代码
/* Branch to C code */
bl initarm
bl mi_startup