Bootable multiboot2 kernel

This commit is contained in:
2022-01-02 17:25:07 +01:00
parent fdcb46d6f2
commit e0979ed357
10 changed files with 107 additions and 2 deletions

10
src/kernel/Link.ld Normal file
View File

@@ -0,0 +1,10 @@
ENTRY(_start)
SECTIONS
{
.text :
{
*(.multiboot)
*(.text)
}
}

33
src/kernel/Makefile Normal file
View File

@@ -0,0 +1,33 @@
CC := x86_64-elf-gcc
SRC := $(wildcard **/*.[cS])
OBJ := $(patsubst %, %.o, $(basename $(SRC)))
CFLAGS := -Wall -Wextra -pedantic -ffreestanding
CFLAGS += -ggdb -O0
ASFLAGS += -ggdb
CPPFLAGS += -I include
LDFLAGS := -n -nostdlib -lgcc -T Link.ld
kernel: $(OBJ)
$(LINK.c) $^ -o $@
DEP := $(OBJ:.o=.d)
DEPFLAGS = -MT $@ -MMD -MP -MF $*.d
$(OBJ): CPPFLAGS += $(DEPFLAGS)
%.d: ;
DESTDIR ?= $(BUILDROOT)/sysroot
$(DESTDIR)$(PREFIX)/kernel: kernel
install -D kernel $(DESTDIR)$(PREFIX)/kernel
install: $(DESTDIR)$(PREFIX)/kernel
clean:
rm -rf $(OBJ) $(DEP) kernel
.PHONY: install
include $(DEP)

7
src/kernel/boot/boot.S Normal file
View File

@@ -0,0 +1,7 @@
.intel_syntax noprefix
.section .text
.global _start
.code32
_start:
cli
jmp $

View File

@@ -0,0 +1,15 @@
#include <multiboot.h>
.section .multiboot
.align 0x8
Multiboot2Header:
.long MBOOT2_MAGIC
.long MBOOT2_ARCH
.long MBOOT2_LENGTH
.long MBOOT2_CHECKSUM
.short 0
.short 0
.long 8
Multiboot2HeaderEnd:

View File

@@ -0,0 +1,7 @@
#pragma once
#define MBOOT2_MAGIC 0xE85250D6
#define MBOOT2_REPLY 0x36D76289
#define MBOOT2_ARCH 0
#define MBOOT2_LENGTH (Multiboot2HeaderEnd - Multiboot2Header)
#define MBOOT2_CHECKSUM -(MBOOT2_MAGIC + MBOOT2_ARCH + MBOOT2_LENGTH)