summaryrefslogtreecommitdiff
path: root/kernel/arch/x86_64/entry.S
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/arch/x86_64/entry.S')
-rw-r--r--kernel/arch/x86_64/entry.S48
1 files changed, 48 insertions, 0 deletions
diff --git a/kernel/arch/x86_64/entry.S b/kernel/arch/x86_64/entry.S
new file mode 100644
index 0000000..50cdd47
--- /dev/null
+++ b/kernel/arch/x86_64/entry.S
@@ -0,0 +1,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: