summaryrefslogtreecommitdiff
path: root/kernel/arch/aarch64/entry.S
blob: 1ca9b0cd708060754e6c6a23d1b69bd80901c3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ============================================================================
// arch/aarch64/entry.S - Kernel entry point (AArch64)
//
// Called by the UEFI loader after ExitBootServices.
//   - EL1, MMU on (identity map from UEFI)
//   - X0 = pointer to BootInfo structure (AAPCS64 6.8.2 C.9 Pointer located in X[NGRN])
//   - Interrupts masked (DAIF)
// ============================================================================

.section .text
.global _start
.extern kernel_main

_start:
    // Mask all interrupts
    msr     daifset, #0xF

    // Set up kernel stack pointer to Stack Pointer(SP)
    adrp    x1, _stack_top
    add     x1, x1, :lo12:_stack_top
    mov     sp, x1

    // Clear frame pointer for clean stack traces
    // x29 is Frame Pointer (FP), points to the prev stack frame. Make kerne_main is root of the call chain (remove UEFI calls)
    // x30 is Link Register (LR), holds the return address from the last bl. Same logic.
    mov     x29, #0
    mov     x30, #0

    // X0 already holds BootInfo*
    bl      kernel_main

    // Should never return
.Lhalt:
    wfi
    b       .Lhalt

// ============================================================================
// Kernel stack (16 KiB)
// Maybe in future i will increase this value, but i hope it's not necessary
// ============================================================================

.section .bss
.balign 4096
_stack_bottom:
    .space CONFIG_KERNEL_STACK_SIZE
_stack_top: