Bootable multiboot2 kernel
This commit is contained in:
10
src/kernel/Link.ld
Normal file
10
src/kernel/Link.ld
Normal file
@@ -0,0 +1,10 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
*(.multiboot)
|
||||
*(.text)
|
||||
}
|
||||
}
|
||||
33
src/kernel/Makefile
Normal file
33
src/kernel/Makefile
Normal 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
7
src/kernel/boot/boot.S
Normal file
@@ -0,0 +1,7 @@
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
.global _start
|
||||
.code32
|
||||
_start:
|
||||
cli
|
||||
jmp $
|
||||
15
src/kernel/boot/multiboot_header.S
Normal file
15
src/kernel/boot/multiboot_header.S
Normal 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:
|
||||
7
src/kernel/include/multiboot.h
Normal file
7
src/kernel/include/multiboot.h
Normal 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)
|
||||
Reference in New Issue
Block a user