Updated linker file to linker script

The linker script can now dynamically use variables such as PAGE_OFFSET.
Updated Makefile to process linker.lds.S
This commit is contained in:
Hunter White 2021-02-24 11:32:28 -05:00
parent 60c857324f
commit 1fc49a33df
3 changed files with 9 additions and 3 deletions

View File

@ -67,7 +67,7 @@ CRTENDOBJ := $(shell $(C) $(CFLAGS) -print-file-name=crtend.o)
CRTBEGIN := $(GLOBALARCHDIR)/crti.o $(CRTBEGINOBJ)
CRTEND := $(CRTENDOBJ) $(GLOBALARCHDIR)/crtn.o
MAKEOBJS := $(GLOBALARCHDIR)/crti.o $(GLOBALARCHDIR)/crtn.o $(SRCDIR)/linker.ld $(OBJECTS) $(ASOBJECTS)
MAKEOBJS := $(GLOBALARCHDIR)/crti.o $(GLOBALARCHDIR)/crtn.o $(BUILDDIR)/linker.lds $(OBJECTS) $(ASOBJECTS)
#Order the objects to prevent weird gcc bugs with global constructors
MAINOBJS := $(CRTBEGIN) $(OBJECTS) $(ASOBJECTS) $(CRTEND)
@ -82,11 +82,14 @@ bin/ZoarialBareOS.iso: bin/ZoarialBareOS.bin bin/grub.cfg
bin/ZoarialBareOS.bin: $(MAKEOBJS)
@echo " Linking... $(MAINOBJS)"
$(C) -T $(SRCDIR)/linker.ld $(MAINOBJS) -o $@ -ffreestanding -O2 -nostdlib -lgcc
$(C) -T build/linker.lds $(MAINOBJS) -o $@ -ffreestanding -O2 -nostdlib -lgcc
bin/grub.cfg: $(SRCDIR)/grub.cfg
cp $(SRCDIR)/grub.cfg bin/grub.cfg
$(BUILDDIR)/linker.lds: $(SRCDIR)/linker.lds.S
$(C) $(CFLAGS) $(INC) -E -P -o $@ -x c-header $^
#Include dependencies which are created
#-include $(DEPENDENCIES:)
include $(wildcard $(DEPENDENCIES))

View File

@ -0,0 +1 @@
#define PAGE_OFFSET 0xC0000000

View File

@ -1,3 +1,5 @@
#include <arch/i686/memory.h>
/* The bootloader will look at this image and start execution at the symbol
designated as the entry point. */
ENTRY(_start)
@ -25,7 +27,7 @@ SECTIONS
*(.paging.setup.text)
}
. += 0xC0000000;
. += PAGE_OFFSET;
.text ALIGN(4K) : AT (ADDR (.text) - 0xC0000000)
{