Building a multiboot 1 compatible executable
This commit is contained in:
parent
0df19ec2b7
commit
39b43d825a
11
src/kernel/Link.ld
Normal file
11
src/kernel/Link.ld
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
ENTRY(_start)
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text : AT(ADDR(.text))
|
||||||
|
{
|
||||||
|
*(.multiboot)
|
||||||
|
*(.text)
|
||||||
|
. = ALIGN(4096);
|
||||||
|
}
|
||||||
|
}
|
19
src/kernel/Makefile
Normal file
19
src/kernel/Makefile
Normal file
@ -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
|
26
src/kernel/boot/boot.S
Normal file
26
src/kernel/boot/boot.S
Normal file
@ -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 $
|
Loading…
x
Reference in New Issue
Block a user