blob: 50cdd473c6fba0a398d33be19101894f71b9888b (
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
47
48
|
// ============================================================================
// arch/x86_64/entry.S - Kernel entry point (x86_64)
//
// Called by the UEFI loader after ExitBootServices.
// - Long mode active, paging on (identity map from UEFI)
// - RDI = pointer to BootInfo structure
// - Interrupts disabled
// ============================================================================
.section .text
.global _start
.extern kernel_main
_start:
// Disable interrupts
cli
// Set up kernel stack
// Load Effective Address quadword
// the address RIP (current exec instruction) + offset_to_stack_top
// to the Stack pointer register (rsp)
//(AT&T syntax: lea symbol(%rip), %reg)
leaq _stack_top(%rip), %rsp
// Align stack to 16 bytes (System V ABI)
// Because ABI mandates that rsp must be 16-byte aligned at the point of a call instruction
andq $-16, %rsp
// The UEFI boot loader (PE/MS x64 ABI) passes BootInfo* in RCX.
// kernel_main uses System V ABI and expects it in RDI.
movq %rcx, %rdi
call kernel_main
// Should never return
.Lhalt:
cli
hlt
jmp .Lhalt
// ============================================================================
// Kernel stack (16 KiB)
// ============================================================================
.section .bss
.align 4096
_stack_bottom:
.space CONFIG_KERNEL_STACK_SIZE
_stack_top:
|