Skip to content

Commit

Permalink
build: Added support for limine.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Sep 17, 2020
1 parent 6fd3f19 commit 2c807cb
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 27 deletions.
34 changes: 13 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ DIRECTORY_GUARD=@mkdir -p $(@D)
BUILD_ARCH?=x86_32
BUILD_CONFIG?=debug
BUILD_SYSTEM?=skift
BUILD_LOADER?=multiboot
BUILD_DISTRO?=$(BUILD_LOADER)-$(BUILD_ARCH)

BUILD_TARGET=$(BUILD_CONFIG)-$(BUILD_ARCH)-$(BUILD_SYSTEM)
BUILD_GITREF=$(shell git rev-parse --abbrev-ref HEAD || echo unknown)@$(shell git rev-parse --short HEAD || echo unknown)
BUILD_UNAME=$(shell uname -s -o -m -r)
BUILD_DIRECTORY=$(shell pwd)/build

SYSROOT=$(BUILD_DIRECTORY)/sysroot
BOOTROOT=$(BUILD_DIRECTORY)/bootroot
BOOTROOT=$(BUILD_DIRECTORY)/bootroot/
BOOTDISK=$(BUILD_DIRECTORY)/bootdisk.img

RAMDISK=$(BUILD_DIRECTORY)/ramdisk.tar

BUILD_DIRECTORY_LIBS=$(SYSROOT)/System/Libraries
BUILD_DIRECTORY_INCLUDE=$(SYSROOT)/System/Includes
Expand Down Expand Up @@ -85,11 +90,10 @@ include kernel/.build.mk
include libraries/.build.mk
include applications/.build.mk
include icons/.build.mk
include distro/.build.mk

# --- Ramdisk -------------------------------------------- #

RAMDISK=$(BOOTROOT)/boot/ramdisk.tar

SYSROOT_CONTENT=$(shell find sysroot/ -type f)

$(RAMDISK): $(CRTS) $(TARGETS) $(HEADERS) $(SYSROOT_CONTENT)
Expand Down Expand Up @@ -123,20 +127,6 @@ $(RAMDISK): $(CRTS) $(TARGETS) $(HEADERS) $(SYSROOT_CONTENT)

@cd $(SYSROOT); tar -cf $@ *

# --- Bootdisk ------------------------------------------- #

BOOTDISK=$(BUILD_DIRECTORY)/bootdisk.iso

$(BOOTDISK): $(RAMDISK) $(KERNEL_BINARY) grub.cfg
$(DIRECTORY_GUARD)
@echo [GRUB-MKRESCUE] $@

@mkdir -p $(BOOTROOT)/boot/grub
@cp grub.cfg $(BOOTROOT)/boot/grub/

@grub-mkrescue -o $@ $(BOOTROOT) || \
grub2-mkrescue -o $@ $(BOOTROOT)

# --- Phony ---------------------------------------------- #

.PHONY: all
Expand All @@ -152,6 +142,8 @@ QEMU_FLAGS=-m $(VM_MEMORY)M \
-serial stdio \
-rtc base=localtime

QEMU_DISK?=-cdrom $(BOOTDISK)

QEMU_FLAGS_VIRTIO=-device virtio-rng-pci \
-device virtio-serial \
-nic user,model=virtio-net-pci \
Expand All @@ -160,15 +152,15 @@ QEMU_FLAGS_VIRTIO=-device virtio-rng-pci \
.PHONY: run-qemu
run-qemu: $(BOOTDISK)
@echo [QEMU] $^
$(QEMU) -cdrom $^ $(QEMU_FLAGS) $(QEMU_EXTRA) -enable-kvm || \
$(QEMU) -cdrom $^ $(QEMU_FLAGS) $(QEMU_EXTRA)
$(QEMU) $(QEMU_DISK) $(QEMU_FLAGS) $(QEMU_EXTRA) -enable-kvm || \
$(QEMU) $(QEMU_DISK) $(QEMU_FLAGS) $(QEMU_EXTRA)

run-qemu-no-kvm: $(BOOTDISK)
$(QEMU) -cdrom $^ $(QEMU_FLAGS) $(QEMU_EXTRA)
$(QEMU) $(QEMU_DISK) $(QEMU_FLAGS) $(QEMU_EXTRA)

run-qemu-virtio: $(BOOTDISK)
@echo [QEMU] $^
$(QEMU) -cdrom $^ $(QEMU_FLAGS) $(QEMU_FLAGS_VIRTIO) $(QEMU_EXTRA) -enable-kvm
$(QEMU) $(QEMU_DISK)$(QEMU_FLAGS) $(QEMU_FLAGS_VIRTIO) $(QEMU_EXTRA) -enable-kvm

.PHONY: run-bochs
run-bochs: $(BOOTDISK)
Expand Down
10 changes: 10 additions & 0 deletions arch/x86_32/boot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "kernel/handover/Stivale1.h"

__attribute__((section(".stivalehdr"), used)) StivaleHeader header = {
.stack = 0,
.flags = 1,
.framebuffer_width = 0,
.framebuffer_height = 0,
.framebuffer_bpp = 32,
.entry_point = 0,
};
4 changes: 2 additions & 2 deletions arch/x86_64/x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#include "arch/x86/COM.h"
#include "arch/x86_64/x86_64.h"

#include "kernel/multiboot/Stivale.h"
#include "kernel/handover/Stivale1.h"

__aligned(4096) static char stack[16384] = {};

__attribute__((section(".stivalehdr"), used)) StivaleHeader header = {
.stack = (uintptr_t)stack + sizeof(stack),
.flags = 1,
.framebuffer_bpp = 32,
.framebuffer_width = 0,
.framebuffer_height = 0,
.flags = 1,
.entry_point = 0,
};

Expand Down
3 changes: 3 additions & 0 deletions distro/.build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISTRO_DIRECTORY:=distro/$(BUILD_DISTRO)

-include $(DISTRO_DIRECTORY)/.build.mk
11 changes: 11 additions & 0 deletions distro/multiboot-x86_32/.build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$(BOOTDISK): $(RAMDISK) $(KERNEL_BINARY) $(DISTRO_DIRECTORY)/grub.cfg
$(DIRECTORY_GUARD)
@echo [GRUB-MKRESCUE] $@

@mkdir -p $(BOOTROOT)/boot/grub
@cp $(DISTRO_DIRECTORY)/grub.cfg $(BOOTROOT)/boot/grub/
@cp $(RAMDISK) $(BOOTROOT)/boot/
@cp $(KERNEL_BINARY) $(BOOTROOT)/boot/kernel.bin

@grub-mkrescue -o $@ $(BOOTROOT) || \
grub2-mkrescue -o $@ $(BOOTROOT)
2 changes: 1 addition & 1 deletion distro/multiboot-x86_32/grub.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set timeout=15
set timeout=0
set default=0

menuentry "skiftOS" {
Expand Down
11 changes: 11 additions & 0 deletions distro/multiboot2-x86_32/.build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$(BOOTDISK): $(RAMDISK) $(KERNEL_BINARY) $(DISTRO_DIRECTORY)/grub.cfg
$(DIRECTORY_GUARD)
@echo [GRUB-MKRESCUE] $@

@mkdir -p $(BOOTROOT)/boot/grub
@cp $(DISTRO_DIRECTORY)/grub.cfg $(BOOTROOT)/boot/grub/
@cp $(RAMDISK) $(BOOTROOT)/boot/
@cp $(KERNEL_BINARY) $(BOOTROOT)/boot/kernel.bin

@grub-mkrescue -o $@ $(BOOTROOT) || \
grub2-mkrescue -o $@ $(BOOTROOT)
18 changes: 18 additions & 0 deletions distro/stival-x86_32/.build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(BOOTDISK): $(RAMDISK) $(KERNEL_BINARY) $(DISTRO_DIRECTORY)/limine.cfg $(ECHFS) $(LIMINE) $(LIMINE_LOADER)
$(DIRECTORY_GUARD)

rm -f $(BOOTDISK)

dd if=/dev/zero bs=1M count=0 seek=64 of=$(BOOTDISK)

parted -s $(BOOTDISK) mklabel msdos
parted -s $(BOOTDISK) mkpart primary 1 100%

$(ECHFS) -m -p0 $(BOOTDISK) quick-format 32768
$(ECHFS) -m -p0 $(BOOTDISK) import $(KERNEL_BINARY) kernel.bin
$(ECHFS) -m -p0 $(BOOTDISK) import $(RAMDISK) ramdisk.tar
$(ECHFS) -m -p0 $(BOOTDISK) import $(DISTRO_DIRECTORY)/limine.cfg limine.cfg

$(LIMINE) $(LIMINE_LOADER) $(BOOTDISK)

QEMU_DISK:=-hda $(BOOTDISK)
12 changes: 12 additions & 0 deletions distro/stival-x86_32/limine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TIMEOUT=5

:skiftOS
PROTOCOL=stivale

KERNEL_PARTITION=0
KERNEL_PATH=kernel.bin
KERNEL_PROTO=stivale

MODULE_PARTITION=0
MODULE_PATH=ramdisk.tar
MODULE_PARTITION=ramdisk
18 changes: 18 additions & 0 deletions distro/stival-x86_64/.build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(BOOTDISK): $(RAMDISK) $(KERNEL_BINARY) $(DISTRO_DIRECTORY)/limine.cfg $(ECHFS) $(LIMINE) $(LIMINE_LOADER)
$(DIRECTORY_GUARD)

rm -f $(BOOTDISK)

dd if=/dev/zero bs=1M count=0 seek=64 of=$(BOOTDISK)

parted -s $(BOOTDISK) mklabel msdos
parted -s $(BOOTDISK) mkpart primary 1 100%

$(ECHFS) -m -p0 $(BOOTDISK) quick-format 32768
$(ECHFS) -m -p0 $(BOOTDISK) import $(KERNEL_BINARY) kernel.bin
$(ECHFS) -m -p0 $(BOOTDISK) import $(RAMDISK) ramdisk.tar
$(ECHFS) -m -p0 $(BOOTDISK) import $(DISTRO_DIRECTORY)/limine.cfg limine.cfg

$(LIMINE) $(LIMINE_LOADER) $(BOOTDISK)

QEMU_DISK:=-hda $(BOOTDISK)
6 changes: 5 additions & 1 deletion distro/stival-x86_64/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ TIMEOUT=5
PROTOCOL=stivale

KERNEL_PARTITION=0
KERNEL_PATH=kernel.elf
KERNEL_PATH=kernel.bin
KERNEL_PROTO=stivale

MODULE_PARTITION=0
MODULE_PATH=ramdisk.tar
MODULE_PARTITION=ramdisk
2 changes: 1 addition & 1 deletion kernel/.build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ KERNEL_LIBRARIES_SOURCES = \
$(wildcard libraries/libsystem/system/*.cpp) \
$(wildcard libraries/libsystem/cxx/new-delete.cpp)

KERNEL_BINARY = $(BOOTROOT)/boot/kernel.bin
KERNEL_BINARY = $(BOOTROOT)/kernel.bin

KERNEL_OBJECTS = \
$(patsubst %.cpp, $(BUILD_DIRECTORY)/%.o, $(KERNEL_SOURCES)) \
Expand Down
Empty file added kernel/handover/Stivale1.cpp
Empty file.
File renamed without changes.
4 changes: 4 additions & 0 deletions thirdparty/.build.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ECHFS:=thirdparty/echfs/echfs-utils
LIMINE:=thirdparty/limine/limine-install
LIMINE_LOADER:=thirdparty/limine/limine.bin

$(ECHFS):
make -C thirdparty/echfs/ all

$(LIMINE):
make -C thirdparty/limine/ limine-install

$(LIMINE_LOADER):
make -C thirdparty/limine/ all
2 changes: 1 addition & 1 deletion thirdparty/limine

0 comments on commit 2c807cb

Please sign in to comment.