This commit is contained in:
nub31
2025-09-03 15:22:35 +02:00
parent 022dde6c7c
commit 020e09c4e1
3 changed files with 25 additions and 14 deletions

View File

@@ -39,20 +39,17 @@ section .data
section .data section .data
align 8 align 8
multiboot_info: multiboot_info:
dq 0 dd 0
multiboot_magic:
dd 0
section .text section .text
bits 32 bits 32
_start: _start:
mov esp, stack_top mov esp, stack_top
; Multiboot will place a magic value in eax
; If this magic value is not present, then we might not have multiboot info in ebx,
; therefore we throw an error
cmp eax, 0x2BADB002
jne error
; Save multiboot info pointer for later ; Save multiboot info pointer for later
mov [multiboot_magic], eax
mov [multiboot_info], ebx mov [multiboot_info], ebx
; Check if cpuid is available by flipping bit 21 ; Check if cpuid is available by flipping bit 21
@@ -150,7 +147,8 @@ section .text
mov ss, ax mov ss, ax
; Finally, we call in to c ; Finally, we call in to c
mov rdi, [multiboot_info] mov edi, [multiboot_magic]
mov esi, [multiboot_info]
call entry call entry
.hang: .hang:
hlt hlt

View File

@@ -6,14 +6,27 @@
#include "multiboot.h" #include "multiboot.h"
#include "util.h" #include "util.h"
#include "vga.h" #include "vga.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
void entry(multiboot_info_t* mbd) void entry(uint32_t magic, multiboot_info_t* info)
{ {
if (magic != 0x2BADB002)
{
printf("Multiboot magic does not match");
panic();
}
if (info == NULL)
{
printf("Multiboot info is NULL");
panic();
}
vga_clear(); vga_clear();
idt_init(); idt_init();
remap_pic(); remap_pic();
map_memory(mbd); map_memory(info);
enable_interrupts(); enable_interrupts();
main(); main();
} }

View File

@@ -9,9 +9,9 @@ memory_map_t memory_map;
static memory_region_t usable_regions[USABLE_REGION_SIZE]; static memory_region_t usable_regions[USABLE_REGION_SIZE];
void map_memory(multiboot_info_t* mbd) void map_memory(multiboot_info_t* info)
{ {
if (!(mbd->flags & (1 << 6))) if (!(info->flags & (1 << 6)))
{ {
printf("Invalid memory map given by bootloader\n"); printf("Invalid memory map given by bootloader\n");
panic(); panic();
@@ -20,9 +20,9 @@ void map_memory(multiboot_info_t* mbd)
size_t num_regions = 0; size_t num_regions = 0;
uint64_t offset = 0; uint64_t offset = 0;
while (offset < mbd->mmap_length) while (offset < info->mmap_length)
{ {
multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*)(mbd->mmap_addr + offset); multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*)(info->mmap_addr + offset);
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
{ {