From 39b43d825ae7ef961d56651ff04892e2273f970a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Tue, 24 Oct 2017 16:04:09 +0200 Subject: [PATCH] Building a multiboot 1 compatible executable --- src/kernel/Link.ld | 11 +++++++++++ src/kernel/Makefile | 19 +++++++++++++++++++ src/kernel/boot/boot.S | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/kernel/Link.ld create mode 100644 src/kernel/Makefile create mode 100644 src/kernel/boot/boot.S diff --git a/src/kernel/Link.ld b/src/kernel/Link.ld new file mode 100644 index 0000000..201e57d --- /dev/null +++ b/src/kernel/Link.ld @@ -0,0 +1,11 @@ +ENTRY(_start) + +SECTIONS +{ + .text : AT(ADDR(.text)) + { + *(.multiboot) + *(.text) + . = ALIGN(4096); + } +} diff --git a/src/kernel/Makefile b/src/kernel/Makefile new file mode 100644 index 0000000..3207999 --- /dev/null +++ b/src/kernel/Makefile @@ -0,0 +1,19 @@ +ifeq ($(MITTOS64),) +$(error Unsupported environment! See README) +endif + +CC := x86_64-elf-gcc + +SRC := $(wildcard **/*.[cS]) +OBJ := $(patsubst %, %.o, $(basename $(SRC))) + +CFLAGS ?= -Wall -Wextra +CFLAGS += -ffreestanding + +all: kernel + +kernel: LDFLAGS += -n -nostdlib -T Link.ld +kernel: $(OBJ) + $(LINK.c) $^ -o $@ + mkdir -p /opt/sysroot + cp kernel /opt/sysroot/kernel diff --git a/src/kernel/boot/boot.S b/src/kernel/boot/boot.S new file mode 100644 index 0000000..2132181 --- /dev/null +++ b/src/kernel/boot/boot.S @@ -0,0 +1,26 @@ +#define MBOOT1_MAGIC 0x1BADB002 +#define MBOOT1_PALIGN 0x01 +#define MBOOT1_MEMINFO 0x02 +#define MBOOT1_FLAGS (MBOOT1_PALIGN | MBOOT1_MEMINFO) +#define MBOOT1_CS -(MBOOT1_FLAGS + MBOOT1_MAGIC) + +.intel_syntax noprefix + +.section .multiboot +.align 0x1000 +MultiBootHeader1: +.long MBOOT1_MAGIC +.long MBOOT1_FLAGS +.long MBOOT1_CS + +.section .text +.global _start +.code32 +_start: +cli + +// Print a red exclamation mark in top left corner +mov eax, 0x0421 +mov short [0xB8000], ax +// and loop infinitely +jmp $