misc: Make sure relocatable kernels work
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 74c81b60..f755ddd7 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index ad9cdc3d..3a8a4743 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 501f70b9..c3c512ad 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/elf.c b/stage2/lib/elf.c
index 60d30744..23440c28 100644
--- a/stage2/lib/elf.c
+++ b/stage2/lib/elf.c
@@ -134,9 +134,6 @@ int elf_bits(struct file_handle *fd) {
}
static int elf64_apply_relocations(struct file_handle *fd, struct elf64_hdr *hdr, void *buffer, uint64_t vaddr, size_t size, uint64_t slide) {
- if (hdr->type != ET_DYN)
- return 0; // Nothing to do if the ELF is not relocatable
-
// Find RELA sections
for (uint16_t i = 0; i < hdr->sh_num; i++) {
struct elf64_shdr section;
diff --git a/stage2/mm/pmm.c b/stage2/mm/pmm.c
index 48749cbe..f5815a14 100644
--- a/stage2/mm/pmm.c
+++ b/stage2/mm/pmm.c
@@ -257,7 +257,8 @@ void memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type) {
if (base < 0x100000) {
// We don't do allocations below 1 MiB
- panic("Attempt to allocate memory below 1 MiB");
+ panic("Attempt to allocate memory below 1 MiB (%X-%X)",
+ base, base + length);
}
for (size_t i = 0; i < memmap_entries; i++) {
diff --git a/test/Makefile b/test/Makefile
index a4a885f6..f1c2e32f 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,10 +5,10 @@ CFLAGS = -O2
LD = ld
QEMU = qemu-system-x86_64
QEMUFLAGS = -m 1G -enable-kvm -cpu host
-LDINTERNALFLAGS := -Tlinker.ld -static -nostdlib -no-pie
+LDINTERNALFLAGS := -Tlinker.ld -nostdlib -pie -z max-page-size=0x1000
INTERNALCFLAGS := -I../stivale -I. -ffreestanding -fno-stack-protector \
- -fno-pic -fomit-frame-pointer -mno-80387 -mno-mmx -mno-3dnow -mno-sse \
- -mno-sse2 -masm=intel -mcmodel=kernel
+ -fpic -fpie -fomit-frame-pointer -mno-red-zone -mno-80387 -mno-mmx -mno-3dnow -mno-sse \
+ -mno-sse2 -masm=intel
all: $(TARGET)
diff --git a/test/limine.cfg b/test/limine.cfg
index 5b974048..b578fbc8 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -35,3 +35,13 @@ KERNEL_CMDLINE=Woah! Another example!
MODULE_PATH=bios://:1/boot/bg.bmp
MODULE_STRING=yooooo
+
+:Stivale2 Test (KASLR)
+
+PROTOCOL=stivale2
+RESOLUTION=640x480x16
+KERNEL_PATH=bios://:1/boot/test.elf
+KERNEL_CMDLINE=Woah! Another example!
+
+MODULE_PATH=bios://:1/boot/bg.bmp
+MODULE_STRING=yooooo
diff --git a/test/linker.ld b/test/linker.ld
index 222598af..1dd95644 100644
--- a/test/linker.ld
+++ b/test/linker.ld
@@ -1,5 +1,12 @@
ENTRY(stivale_main)
+PHDRS {
+ none PT_NULL FLAGS(0);
+ text PT_LOAD FLAGS((1 << 2) | (1 << 0) /* Readable | Executable */);
+ data PT_LOAD FLAGS((1 << 2) | (1 << 1) /* Readable | Writeable */);
+ rodata PT_LOAD FLAGS((1 << 2) /* Readable */);
+}
+
SECTIONS
{
. = 0xffffffff80100000;
@@ -7,7 +14,7 @@ SECTIONS
.stivalehdr ALIGN(4K) :
{
KEEP(*(.stivalehdr))
- }
+ }:none
.stivale2hdr ALIGN(4K) :
{
@@ -17,17 +24,17 @@ SECTIONS
.text ALIGN(4K) :
{
KEEP(*(.text*))
- }
+ }:text
.rodata ALIGN(4K) :
{
KEEP(*(.rodata*))
- }
+ }:rodata
.data ALIGN(4K) :
{
KEEP(*(.data*))
- }
+ }:data
.bss ALIGN(4K) :
{
diff --git a/test/stivale2.c b/test/stivale2.c
index 4da0e0c4..609e9e48 100644
--- a/test/stivale2.c
+++ b/test/stivale2.c
@@ -33,7 +33,7 @@ struct stivale2_header header2 = {
.tags = (uint64_t)&framebuffer_request
};
-void ap_entry(struct stivale2_smp_info *s) {
+static void ap_entry(struct stivale2_smp_info *s) {
e9_printf("AP %u started", s->lapic_id);
for (;;);
}
