Compare commits

...

10 commits

Author SHA1 Message Date
mintsuki 4856134d39 Drop branch name prefix from binary branch name 2024-01-14 19:33:58 +01:00
mintsuki 78cc2486ad Update copyright years and update LICENSE format 2024-01-02 22:41:41 +01:00
mintsuki 2286ff7db5 Limine 6.x 2023-12-10 04:41:52 +01:00
mintsuki 302427b1e1 Use base revision 1 2023-11-03 06:40:04 +01:00
mintsuki 6c3707c731 Specify that the kernel is in C in README.md 2023-10-22 00:30:26 +02:00
mintsuki 28e78d5cad Rebranding 2023-10-22 00:27:35 +02:00
mintsuki 200579e900 Do not have .S files depend on limine.h 2023-10-03 02:33:50 -05:00
mintsuki 470ff36612 Use globbing instead of dot for find 2023-10-03 02:28:56 -05:00
mintsuki 2ea57613c1 Move bin/ part of kernel path off of the KERNEL var 2023-09-27 21:22:03 -05:00
mintsuki 62be50a063 Write out kernel executable in bin/ directory 2023-09-27 16:24:26 -05:00
7 changed files with 46 additions and 27 deletions

View file

@ -1,7 +1,7 @@
# Nuke built-in rules and variables.
override MAKEFLAGS += -rR
override IMAGE_NAME := barebones
override IMAGE_NAME := template
# Convenience macro to reliably declare user overridable variables.
define DEFAULT_VAR =
@ -52,7 +52,7 @@ ovmf:
cd ovmf && curl -Lo OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd
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 \
CC="$(HOST_CC)" \
CFLAGS="$(HOST_CFLAGS)" \
@ -67,7 +67,7 @@ kernel:
$(IMAGE_NAME).iso: limine kernel
rm -rf 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/
mkdir -p 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
mformat -i $(IMAGE_NAME).hdd@@1M
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/BOOTIA32.EFI ::/EFI/BOOT

13
LICENSE
View file

@ -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.

View file

@ -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.

3
kernel/.gitignore vendored
View file

@ -1,4 +1,3 @@
/src/limine.h
/bin
/obj
*.elf
*.o

View file

@ -3,7 +3,7 @@ override MAKEFLAGS += -rR
# This is the name that our final kernel executable will have.
# Change as needed.
override KERNEL := kernel.elf
override KERNEL := kernel
# Convenience macro to reliably declare user overridable variables.
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
# object and header dependency file names.
override CFILES := $(shell cd src && find -L . -type f -name '*.c')
override ASFILES := $(shell cd src && find -L . -type f -name '*.S')
override NASMFILES := $(shell cd src && find -L . -type f -name '*.asm')
override CFILES := $(shell cd src && find -L * -type f -name '*.c')
override ASFILES := $(shell cd src && find -L * -type f -name '*.S')
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 HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
# Default target.
.PHONY: all
all: $(KERNEL)
all: bin/$(KERNEL)
src/limine.h:
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
# 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 $@
# Include header dependencies.
@ -110,7 +111,7 @@ obj/%.c.o: src/%.c GNUmakefile src/limine.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.S files.
obj/%.S.o: src/%.S GNUmakefile src/limine.h
obj/%.S.o: src/%.S GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@ -122,7 +123,7 @@ obj/%.asm.o: src/%.asm GNUmakefile
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf $(KERNEL) obj
rm -rf bin obj
.PHONY: distclean
distclean: clean

View file

@ -1,12 +1,19 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <limine.h>
// The Limine requests can be placed anywhere, but it is important that
// the compiler does not optimise them away, so, usually, they should
// be made volatile or equivalent.
// Set the base revision to 1, this is recommended as this is the latest
// base revision described by the Limine boot protocol specification.
// 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,
.revision = 0
};
@ -80,6 +87,11 @@ static void hcf(void) {
// If renaming _start() to something else, make sure to change the
// linker script accordingly.
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.
if (framebuffer_request.response == NULL
|| framebuffer_request.response->framebuffer_count < 1) {

View file

@ -2,18 +2,18 @@
TIMEOUT=3
# 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.
PROTOCOL=limine
# 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.
:Limine Barebones (KASLR off)
:Limine Template (KASLR off)
PROTOCOL=limine
# Disable KASLR (it is enabled by default for relocatable kernels)
KASLR=no
KERNEL_PATH=boot:///kernel.elf
KERNEL_PATH=boot:///kernel