commit 990e3f256078c75d2032d1846f71af7ec99fdafe
parent 7a2897c5b74e2e0ea53254c0eb6d8d58e50da8e2
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 19 Mar 2024 13:45:21 +0900
add linker script
Diffstat:
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,16 +1,17 @@
-CC = x86_64-w64-mingw32-gcc
-CFLAGS = -nostdlib -fpic -shared -mno-red-zone -fno-stack-protector \
+EFI_CFLAGS = -nostdlib -fpic -mno-red-zone -fno-stack-protector -static \
-fno-builtin \
-mno-stack-arg-probe -Wall -e EfiMain
+KERN_CFLAGS = -nostdlib -fpic -mno-red-zone -ffreestanding -Wall
+KERN_LDFLAGS = -e kernel_main -static
OBJCOPY = objcopy
SRC = loader.c utils.c
HDR = uefi.h
all: disk.img
-disk.img: loader.efi
+disk.img: loader.efi kernel.elf
qemu-img create -f raw disk.img 200M
- mkfs.fat -n 'setos' -s 2 -f 2 -R 32 -F 32 disk.img
+ mkfs.fat -n 'SETOS' -s 2 -f 2 -R 32 -F 32 disk.img
mkdir -p image
doas mount disk.img image
doas mkdir -p image/EFI/BOOT
@@ -18,11 +19,17 @@ disk.img: loader.efi
doas umount image
loader.dll: $(SRC) $(HDR)
- $(CC) $(CFLAGS) -o $@ $(SRC)
+ x86_64-w64-mingw32-gcc $(EFI_CFLAGS) -o $@ $(SRC)
loader.efi: loader.dll
$(OBJCOPY) --target=efi-app-x86_64 $< $@
+%.o: %.c
+ gcc $(KERN_CFLAGS) -c -o $@ $<
+
+kernel.elf: kernel.o kernel.ld
+ ld $(KERN_LDFLAGS) -T kernel.ld -o $@ $<
+
run: disk.img
qemu-system-x86_64 \
-bios /usr/share/edk2/x64/OVMF.fd \
@@ -32,5 +39,5 @@ test: test/* $(SRC) $(HDR)
(cd test && make)
clean:
- rm -rf *.o *.efi *.dll disk.img image
+ rm -rf *.o *.efi *.elf *.dll disk.img image
(cd test && make clean)
\ No newline at end of file
diff --git a/kernel.ld b/kernel.ld
@@ -0,0 +1,12 @@
+SECTIONS
+{
+ .text 0x10000 : {
+ *(.text)
+ }
+ .data : {
+ *(.data)
+ }
+ .bss : {
+ *(.bss)
+ }
+}
+\ No newline at end of file