Bootable multiboot2 kernel
This commit is contained in:
parent
fdcb46d6f2
commit
e0979ed357
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
dist/
|
||||
build/
|
||||
sysroot/
|
||||
sysroot/
|
||||
|
||||
*.d
|
||||
*.o
|
||||
|
||||
src/kernel/kernel
|
10
Makefile
10
Makefile
@ -7,8 +7,18 @@ SYSROOT := $(BUILDROOT)/sysroot
|
||||
DIST := $(BUILDROOT)/dist/mittos.iso
|
||||
|
||||
$(DIST):
|
||||
setup-grub.sh
|
||||
grub-mkrescue -o $@ $(SYSROOT)
|
||||
|
||||
kernel:
|
||||
ifeq ($(shell make -sqC src/kernel || echo 1), 1)
|
||||
$(MAKE) -C src/kernel install
|
||||
endif
|
||||
|
||||
install: $(DIST)
|
||||
|
||||
clean:
|
||||
rm -rf $(DIST)
|
||||
$(MAKE) -C src/kernel clean
|
||||
|
||||
.PHONY: install
|
2
make
2
make
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
docker-compose -f toolchain/docker-compose.yml run --rm make "$@"
|
||||
docker-compose -f toolchain/docker-compose.yml run --rm -u $(id -u):$(id -g) make make "$@"
|
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)
|
@ -13,4 +13,9 @@ end
|
||||
|
||||
define reset
|
||||
monitor system_reset
|
||||
end
|
||||
|
||||
python
|
||||
import os
|
||||
gdb.execute('file ' + os.environ['BUILDROOT'] + '/sysroot/kernel')
|
||||
end
|
13
toolchain/setup-grub.sh
Executable file
13
toolchain/setup-grub.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p ${BUILDROOT}/sysroot/boot/grub
|
||||
|
||||
cat > ${BUILDROOT}/sysroot/boot/grub/grub.cfg << EOF
|
||||
set timeout=1
|
||||
set default=0
|
||||
|
||||
menuentry "mittos64" {
|
||||
multiboot2 /kernel
|
||||
}
|
||||
|
||||
EOF
|
Loading…
x
Reference in New Issue
Block a user