Compare commits
10 commits
bb7be171fd
...
4856134d39
Author | SHA1 | Date | |
---|---|---|---|
|
4856134d39 | ||
|
78cc2486ad | ||
|
2286ff7db5 | ||
|
302427b1e1 | ||
|
6c3707c731 | ||
|
28e78d5cad | ||
|
200579e900 | ||
|
470ff36612 | ||
|
2ea57613c1 | ||
|
62be50a063 |
7 changed files with 46 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Nuke built-in rules and variables.
|
# Nuke built-in rules and variables.
|
||||||
override MAKEFLAGS += -rR
|
override MAKEFLAGS += -rR
|
||||||
|
|
||||||
override IMAGE_NAME := barebones
|
override IMAGE_NAME := template
|
||||||
|
|
||||||
# Convenience macro to reliably declare user overridable variables.
|
# Convenience macro to reliably declare user overridable variables.
|
||||||
define DEFAULT_VAR =
|
define DEFAULT_VAR =
|
||||||
|
@ -52,7 +52,7 @@ ovmf:
|
||||||
cd ovmf && curl -Lo OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd
|
cd ovmf && curl -Lo OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd
|
||||||
|
|
||||||
limine:
|
limine:
|
||||||
git clone https://github.com/limine-bootloader/limine.git --branch=v5.x-branch-binary --depth=1
|
git clone https://github.com/limine-bootloader/limine.git --branch=binary --depth=1
|
||||||
$(MAKE) -C limine \
|
$(MAKE) -C limine \
|
||||||
CC="$(HOST_CC)" \
|
CC="$(HOST_CC)" \
|
||||||
CFLAGS="$(HOST_CFLAGS)" \
|
CFLAGS="$(HOST_CFLAGS)" \
|
||||||
|
@ -67,7 +67,7 @@ kernel:
|
||||||
$(IMAGE_NAME).iso: limine kernel
|
$(IMAGE_NAME).iso: limine kernel
|
||||||
rm -rf iso_root
|
rm -rf iso_root
|
||||||
mkdir -p iso_root
|
mkdir -p iso_root
|
||||||
cp -v kernel/kernel.elf \
|
cp -v kernel/bin/kernel \
|
||||||
limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
|
limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
|
||||||
mkdir -p iso_root/EFI/BOOT
|
mkdir -p iso_root/EFI/BOOT
|
||||||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
||||||
|
@ -87,7 +87,7 @@ $(IMAGE_NAME).hdd: limine kernel
|
||||||
./limine/limine bios-install $(IMAGE_NAME).hdd
|
./limine/limine bios-install $(IMAGE_NAME).hdd
|
||||||
mformat -i $(IMAGE_NAME).hdd@@1M
|
mformat -i $(IMAGE_NAME).hdd@@1M
|
||||||
mmd -i $(IMAGE_NAME).hdd@@1M ::/EFI ::/EFI/BOOT
|
mmd -i $(IMAGE_NAME).hdd@@1M ::/EFI ::/EFI/BOOT
|
||||||
mcopy -i $(IMAGE_NAME).hdd@@1M kernel/kernel.elf limine.cfg limine/limine-bios.sys ::/
|
mcopy -i $(IMAGE_NAME).hdd@@1M kernel/bin/kernel limine.cfg limine/limine-bios.sys ::/
|
||||||
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
||||||
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTIA32.EFI ::/EFI/BOOT
|
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTIA32.EFI ::/EFI/BOOT
|
||||||
|
|
||||||
|
|
13
LICENSE
13
LICENSE
|
@ -1,5 +1,12 @@
|
||||||
Copyright (C) 2022-2023 mintsuki and contributors.
|
Copyright (C) 2022-2024 mintsuki and contributors.
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Limine Bare Bones
|
# Limine C Template
|
||||||
|
|
||||||
This repository will demonstrate how to set up a basic x86-64 kernel using Limine.
|
This repository will demonstrate how to set up a basic x86-64 kernel in C using Limine.
|
||||||
|
|
||||||
It is recommended to cross reference the contents of this repository with [the Limine Bare Bones](https://wiki.osdev.org/Limine_Bare_Bones) OSDev wiki page.
|
It is recommended to cross reference the contents of this repository with [the Limine Bare Bones](https://wiki.osdev.org/Limine_Bare_Bones) OSDev wiki page.
|
||||||
|
|
||||||
|
|
3
kernel/.gitignore
vendored
3
kernel/.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
/src/limine.h
|
/src/limine.h
|
||||||
|
/bin
|
||||||
/obj
|
/obj
|
||||||
*.elf
|
|
||||||
*.o
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ override MAKEFLAGS += -rR
|
||||||
|
|
||||||
# This is the name that our final kernel executable will have.
|
# This is the name that our final kernel executable will have.
|
||||||
# Change as needed.
|
# Change as needed.
|
||||||
override KERNEL := kernel.elf
|
override KERNEL := kernel
|
||||||
|
|
||||||
# Convenience macro to reliably declare user overridable variables.
|
# Convenience macro to reliably declare user overridable variables.
|
||||||
define DEFAULT_VAR =
|
define DEFAULT_VAR =
|
||||||
|
@ -84,21 +84,22 @@ override NASMFLAGS += \
|
||||||
|
|
||||||
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
|
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
|
||||||
# object and header dependency file names.
|
# object and header dependency file names.
|
||||||
override CFILES := $(shell cd src && find -L . -type f -name '*.c')
|
override CFILES := $(shell cd src && find -L * -type f -name '*.c')
|
||||||
override ASFILES := $(shell cd src && find -L . -type f -name '*.S')
|
override ASFILES := $(shell cd src && find -L * -type f -name '*.S')
|
||||||
override NASMFILES := $(shell cd src && find -L . -type f -name '*.asm')
|
override NASMFILES := $(shell cd src && find -L * -type f -name '*.asm')
|
||||||
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
|
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
|
||||||
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
|
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
|
||||||
|
|
||||||
# Default target.
|
# Default target.
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(KERNEL)
|
all: bin/$(KERNEL)
|
||||||
|
|
||||||
src/limine.h:
|
src/limine.h:
|
||||||
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
|
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
|
||||||
|
|
||||||
# Link rules for the final kernel executable.
|
# Link rules for the final kernel executable.
|
||||||
$(KERNEL): GNUmakefile linker.ld $(OBJ)
|
bin/$(KERNEL): GNUmakefile linker.ld $(OBJ)
|
||||||
|
mkdir -p "$$(dirname $@)"
|
||||||
$(LD) $(OBJ) $(LDFLAGS) -o $@
|
$(LD) $(OBJ) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
# Include header dependencies.
|
# Include header dependencies.
|
||||||
|
@ -110,7 +111,7 @@ obj/%.c.o: src/%.c GNUmakefile src/limine.h
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||||
|
|
||||||
# Compilation rules for *.S files.
|
# Compilation rules for *.S files.
|
||||||
obj/%.S.o: src/%.S GNUmakefile src/limine.h
|
obj/%.S.o: src/%.S GNUmakefile
|
||||||
mkdir -p "$$(dirname $@)"
|
mkdir -p "$$(dirname $@)"
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ obj/%.asm.o: src/%.asm GNUmakefile
|
||||||
# Remove object files and the final executable.
|
# Remove object files and the final executable.
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(KERNEL) obj
|
rm -rf bin obj
|
||||||
|
|
||||||
.PHONY: distclean
|
.PHONY: distclean
|
||||||
distclean: clean
|
distclean: clean
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <limine.h>
|
#include <limine.h>
|
||||||
|
|
||||||
// The Limine requests can be placed anywhere, but it is important that
|
// Set the base revision to 1, this is recommended as this is the latest
|
||||||
// the compiler does not optimise them away, so, usually, they should
|
// base revision described by the Limine boot protocol specification.
|
||||||
// be made volatile or equivalent.
|
// See specification for further info.
|
||||||
|
|
||||||
static volatile struct limine_framebuffer_request framebuffer_request = {
|
LIMINE_BASE_REVISION(1)
|
||||||
|
|
||||||
|
// The Limine requests can be placed anywhere, but it is important that
|
||||||
|
// the compiler does not optimise them away, so, in C, they should
|
||||||
|
// NOT be made "static".
|
||||||
|
|
||||||
|
struct limine_framebuffer_request framebuffer_request = {
|
||||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||||
.revision = 0
|
.revision = 0
|
||||||
};
|
};
|
||||||
|
@ -80,6 +87,11 @@ static void hcf(void) {
|
||||||
// If renaming _start() to something else, make sure to change the
|
// If renaming _start() to something else, make sure to change the
|
||||||
// linker script accordingly.
|
// linker script accordingly.
|
||||||
void _start(void) {
|
void _start(void) {
|
||||||
|
// Ensure the bootloader actually understands our base revision (see spec).
|
||||||
|
if (LIMINE_BASE_REVISION_SUPPORTED == false) {
|
||||||
|
hcf();
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure we got a framebuffer.
|
// Ensure we got a framebuffer.
|
||||||
if (framebuffer_request.response == NULL
|
if (framebuffer_request.response == NULL
|
||||||
|| framebuffer_request.response->framebuffer_count < 1) {
|
|| framebuffer_request.response->framebuffer_count < 1) {
|
||||||
|
|
|
@ -2,18 +2,18 @@
|
||||||
TIMEOUT=3
|
TIMEOUT=3
|
||||||
|
|
||||||
# The entry name that will be displayed in the boot menu.
|
# The entry name that will be displayed in the boot menu.
|
||||||
:Limine Barebones (KASLR on)
|
:Limine Template (KASLR on)
|
||||||
# We use the Limine boot protocol.
|
# We use the Limine boot protocol.
|
||||||
PROTOCOL=limine
|
PROTOCOL=limine
|
||||||
|
|
||||||
# Path to the kernel to boot. boot:/// represents the partition on which limine.cfg is located.
|
# Path to the kernel to boot. boot:/// represents the partition on which limine.cfg is located.
|
||||||
KERNEL_PATH=boot:///kernel.elf
|
KERNEL_PATH=boot:///kernel
|
||||||
|
|
||||||
# Same thing, but without KASLR.
|
# Same thing, but without KASLR.
|
||||||
:Limine Barebones (KASLR off)
|
:Limine Template (KASLR off)
|
||||||
PROTOCOL=limine
|
PROTOCOL=limine
|
||||||
|
|
||||||
# Disable KASLR (it is enabled by default for relocatable kernels)
|
# Disable KASLR (it is enabled by default for relocatable kernels)
|
||||||
KASLR=no
|
KASLR=no
|
||||||
|
|
||||||
KERNEL_PATH=boot:///kernel.elf
|
KERNEL_PATH=boot:///kernel
|
||||||
|
|
Loading…
Reference in a new issue