Restructure kernel project
This commit is contained in:
parent
61c12a11da
commit
cbf223b837
|
|
@ -1,5 +1,7 @@
|
|||
build/*
|
||||
kernel.elf
|
||||
kernel2.elf
|
||||
kornos.img
|
||||
|
||||
kernel/kernel
|
||||
|
||||
obj/
|
||||
*.o
|
||||
zig-cache/
|
||||
|
|
|
|||
42
Makefile
42
Makefile
|
|
@ -1,55 +1,29 @@
|
|||
CC = zig cc -target x86_64-freestanding
|
||||
LD = ld
|
||||
KERNEL_HDD = build/disk.hdd
|
||||
COMPONENTS = kernel
|
||||
|
||||
CFLAGS = -O2 -pipe -Wall -Wextra
|
||||
KERNEL_HDD = kornos.img
|
||||
|
||||
CHARDFLAGS := $(CFLAGS) \
|
||||
-std=gnu99 \
|
||||
-masm=intel \
|
||||
-fno-pic \
|
||||
-mno-sse \
|
||||
-mno-sse2 \
|
||||
-mno-mmx \
|
||||
-mno-80387 \
|
||||
-mno-red-zone \
|
||||
-mcmodel=kernel \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-Isrc/ \
|
||||
.PHONY: clean all $(COMPONENTS)
|
||||
|
||||
LDHARDFLAGS := $(LDFLAGS) \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-no-pie \
|
||||
-z max-page-size=0x1000 \
|
||||
-T src/linker.ld
|
||||
|
||||
.PHONY: clean all
|
||||
.DEFAULT_GOAL = $(KERNEL_HDD)
|
||||
$(COMPONENTS):
|
||||
$(MAKE) -C $@
|
||||
|
||||
disk: $(KERNEL_HDD)
|
||||
run: $(KERNEL_HDD)
|
||||
qemu-system-x86_64 -m 2G -hda $(KERNEL_HDD)
|
||||
|
||||
src-stivale2/kernel2.elf:
|
||||
$(MAKE) -C src-stivale2
|
||||
|
||||
ext/limine/limine-install:
|
||||
$(MAKE) -C ext/limine/ limine-install
|
||||
|
||||
$(KERNEL_HDD): ext/limine/limine-install src-stivale2/kernel2.elf
|
||||
-mkdir build
|
||||
$(KERNEL_HDD): ext/limine/limine-install $(COMPONENTS)
|
||||
rm -f $(KERNEL_HDD)
|
||||
dd if=/dev/zero bs=1M count=0 seek=64 of=$(KERNEL_HDD)
|
||||
parted -s $(KERNEL_HDD) mklabel msdos
|
||||
parted -s $(KERNEL_HDD) mkpart primary 1 100%
|
||||
echfs-utils -m -p0 $(KERNEL_HDD) quick-format 32768
|
||||
echfs-utils -m -p0 $(KERNEL_HDD) import src-stivale/kernel.elf kernel.elf
|
||||
echfs-utils -m -p0 $(KERNEL_HDD) import src-stivale2/kernel2.elf kernel2.elf
|
||||
for f in $(COMPONENTS); do echo "Installing $$f"; echfs-utils -m -p0 $@ import $$f/$$f $$f; done
|
||||
echfs-utils -m -p0 $(KERNEL_HDD) import ext/limine.cfg limine.cfg
|
||||
ext/limine/limine-install ext/limine/limine.bin $(KERNEL_HDD)
|
||||
|
||||
clean:
|
||||
rm -f $(KERNEL_HDD)
|
||||
$(MAKE) -C src-stivale2 clean
|
||||
for f in $(COMPONENTS); do $(MAKE) -C $$f clean; done
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ TIMEOUT=5
|
|||
|
||||
:OS2
|
||||
PROTOCOL=stivale2
|
||||
KERNEL_PATH=bios://:1/kernel2.elf
|
||||
KERNEL_PATH=bios://:1/kernel
|
||||
KERNEL_CMDLINE=Hi!
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
TARGET := kernel2.elf
|
||||
TARGET := kernel
|
||||
|
||||
CC = zig cc -target x86_64-freestanding
|
||||
CFLAGS = -O2
|
||||
|
|
@ -6,18 +6,24 @@ LD = ld -m elf_x86_64
|
|||
QEMU = qemu-system-x86_64
|
||||
QEMUFLAGS = -m 1G -enable-kvm -cpu host
|
||||
LDINTERNALFLAGS := -Tlinker.ld
|
||||
INTERNALCFLAGS := -I. \
|
||||
INTERNALCFLAGS := -I../ext/limine/stivale \
|
||||
|
||||
CFILES := $(shell find ./ -type f -name '*.c')
|
||||
OBJ := $(CFILES:.c=.o)
|
||||
CFILES := $(shell find src -type f -name '*.c')
|
||||
HFILES := $(shell find src -type f -name '*.h')
|
||||
OBJ := $(patsubst src/%.c,obj/%.o,$(CFILES))
|
||||
|
||||
.PHONY: all clean obj
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(LD) $(LDINTERNALFLAGS) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c
|
||||
obj/%.o: src/%.c $(HFILES) obj
|
||||
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
|
||||
|
||||
obj:
|
||||
mkdir -p obj
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.o
|
||||
rm -rf $(TARGET) obj zig-cache
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
The stivale 2 protocol is a replacement for the stivale protocol that is able to be cleanly extended without breaking changes, it has support for extra features such as SMP compared to the older protocol.
|
||||
|
||||
## the stivale 2 header
|
||||
This structure must be present in the `.stivale2hdr` section in order for your kernel to be loaded by stivale 2.
|
||||
|
||||
```c
|
||||
struct stivale2_header {
|
||||
uint64_t entry_point;
|
||||
uint64_t stack;
|
||||
uint64_t flags;
|
||||
uint64_t tags;
|
||||
} __attribute__((packed));
|
||||
```
|
||||
|
||||
If `entry_point` is 0 then the ELF entry point will be jumped to, otherwise the address specified will be used, `stack` will be loaded into the stack pointer register, as of now `flags` is 1 if KASLR is to be enabled.
|
||||
|
||||
`tags` is a pointer to the first of a linked list of tags which determine the features requested by the kernel, the base structure of a tag is:
|
||||
|
||||
```c
|
||||
struct stivale2_hdr_tag {
|
||||
uint64_t identifier;
|
||||
uint64_t next;
|
||||
} __attribute__((packed));
|
||||
```
|
||||
|
||||
Where `identifier` determines the type of the tag, while `next` determines the next tag, a value of `NULL` indicates the end of the list.
|
||||
For further information on the supported tags consule the [Stivale2 Specification](https://github.com/limine-bootloader/limine/blob/master/STIVALE2.md)
|
||||
Loading…
Reference in New Issue