mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
Kernel: Introduce basic pre-kernel environment
This implements a simple bootloader that is capable of loading ELF64 kernel images. It does this by using QEMU/GRUB to load the kernel image from disk and pass it to our bootloader as a Multiboot module. The bootloader then parses the ELF image and sets it up appropriately. The kernel's entry point is a C++ function with architecture-native code. Co-authored-by: Liav A <liavalb@gmail.com>
This commit is contained in:
parent
357ddd393e
commit
7e94b090fe
30 changed files with 1207 additions and 181 deletions
|
@ -1,4 +1,3 @@
|
|||
#define _BOOTLOADER
|
||||
#include <AK/Platform.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
.code32
|
||||
.set MULTIBOOT_MAGIC, 0x1badb002
|
||||
.set MULTIBOOT_PAGE_ALIGN, 0x1
|
||||
.set MULTIBOOT_MEMORY_INFO, 0x2
|
||||
.set MULTIBOOT_VIDEO_MODE, 0x4
|
||||
.set multiboot_flags, MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
|
||||
.set multiboot_checksum, -(MULTIBOOT_MAGIC + multiboot_flags)
|
||||
|
||||
.section .multiboot, "a"
|
||||
.align 4
|
||||
|
||||
.long MULTIBOOT_MAGIC
|
||||
.long multiboot_flags
|
||||
.long multiboot_checksum
|
||||
|
||||
|
||||
/* for MULTIBOOT_MEMORY_INFO */
|
||||
.long 0x00000000 /* header_addr */
|
||||
.long 0x00000000 /* load_addr */
|
||||
.long 0x00000000 /* load_end_addr */
|
||||
.long 0x00000000 /* bss_end_addr */
|
||||
.long 0x00000000 /* entry_addr */
|
||||
|
||||
/* for MULTIBOOT_VIDEO_MODE */
|
||||
.long 0x00000000 /* mode_type */
|
||||
.long 1280 /* width */
|
||||
.long 1024 /* height */
|
||||
.long 32 /* depth */
|
|
@ -1,4 +1,3 @@
|
|||
#define _BOOTLOADER
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
.extern init_ap
|
||||
|
@ -110,7 +109,7 @@ apic_ap_start32_2:
|
|||
|
||||
/* push the Processor pointer this CPU is going to use */
|
||||
movl (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %eax
|
||||
addl $KERNEL_BASE, %eax
|
||||
addl kernel_base, %eax
|
||||
movl 0(%eax, %esi, 4), %eax
|
||||
push %eax
|
||||
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
#define _BOOTLOADER
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
.section .text
|
||||
|
||||
.global gdt64ptr
|
||||
gdt64ptr:
|
||||
#if ARCH(X86_64)
|
||||
.quad 0
|
||||
#else
|
||||
.int 0
|
||||
#endif
|
||||
|
||||
.global code64_sel
|
||||
code64_sel:
|
||||
.short 0
|
||||
|
||||
.extern init_ap
|
||||
.type init_ap, @function
|
||||
|
||||
|
@ -92,16 +105,15 @@ apic_ap_start32:
|
|||
movl %eax, %cr0
|
||||
|
||||
/* load the temporary 64-bit gdt from boot that points above 3GB */
|
||||
mov $(gdt64ptr - KERNEL_BASE), %eax
|
||||
// FIXME: uncomment this
|
||||
//mov gdt64ptr, %eax
|
||||
lgdt (%eax)
|
||||
|
||||
/* jump above 3GB into our identity mapped area now */
|
||||
ljmpl $code64_sel, $(apic_ap_start64 - apic_ap_start + 0xc0008000)
|
||||
// FIXME: this assumes that code64_sel is always 8
|
||||
ljmpl $8, $(apic_ap_start64 - apic_ap_start + 0xc0008000)
|
||||
.code64
|
||||
apic_ap_start64:
|
||||
movabs $gdt64ptr, %rax
|
||||
lgdt (%rax)
|
||||
|
||||
mov $0, %ax
|
||||
mov %ax, %ss
|
||||
mov %ax, %ds
|
||||
|
@ -129,7 +141,8 @@ apic_ap_start64:
|
|||
|
||||
/* push the Processor pointer this CPU is going to use */
|
||||
movq (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %rax
|
||||
movq $KERNEL_BASE, %r8
|
||||
movabsq $(kernel_base), %r8
|
||||
movq (%r8), %r8
|
||||
addq %r8, %rax
|
||||
movq 0(%rax, %rsi, 4), %rax
|
||||
push %rax
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue