Skip to content

Commit 5038b7a

Browse files
committedSep 11, 2023
ELF generation is working
1 parent ff6cb6e commit 5038b7a

File tree

8 files changed

+579
-12
lines changed

8 files changed

+579
-12
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.DS_Store
2-
bin/
32
*.bin
43
*.o
54
*.elf

‎Makefile

+15-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ INCLUDE_DIR = \
1010
OUTPUT_DIR = bin
1111
KERNEL_DIR = src/kernel
1212

13-
override CFILES := $(shell find -L . -type f -name '*.c')
13+
override CFILES := $(shell find -L src -type f -name '*.c')
14+
override OBJFILES := $(shell find -L . -type f -name '*.o')
1415

15-
KERNEL = $(OUTPUT_DIR)/kernel.bin
16+
KERNEL = $(OUTPUT_DIR)/kernel.elf
1617

1718
override CFLAGS += \
1819
-Wall \
@@ -30,22 +31,25 @@ override CFLAGS += \
3031
-mno-sse \
3132
-mno-sse2 \
3233
-mno-red-zone \
33-
-o out
34+
-nostdlib \
35+
-static \
36+
-c
3437

3538
override CPPFLAGS := \
3639
-I./limine \
3740
$(CPPFLAGS) \
3841
-MMD \
3942
-MP
4043

44+
4145
override LDFLAGS += \
42-
-m elf_x86_64 \
4346
-nostdlib \
4447
-static \
4548
-pie \
46-
--no-dynamic-linker \
4749
-z text \
4850
-z max-page-size=0x1000 \
51+
-m elf_x86_64 \
52+
--no-dynamic-linker \
4953
-T linker.ld
5054

5155
override NASMFLAGS += \
@@ -54,9 +58,10 @@ override NASMFLAGS += \
5458

5559
GCC_KERNEL_OPTS = \
5660
$(CFLAGS) \
57-
-I./limine
61+
-I./include
5862

5963
GCC = $(GCC_DIR)/gcc
64+
LD = $(GCC_DIR)/ld
6065

6166
QEMU_MEMORY = 8
6267
QEMU_X86 = qemu-system-amd64
@@ -85,12 +90,14 @@ build:
8590
set +eux
8691

8792
ifeq ($(OS_NAME),linux)
88-
$(GCC) $(GCC_KERNEL_OPTS) $(KERNEL_SRC)
93+
@mkdir $(OUTPUT_DIR) || echo "$(OUTPUT_DIR) already exists"
94+
@$(GCC) $(GCC_KERNEL_OPTS) $(CFILES)
95+
@$(LD) $(OBJFILES) $(LDFLAGS) -o $(KERNEL)
8996
else
9097
@make docker
9198
@echo "Building inside Docker"
9299
$(DOCKER) run -it --mount type=bind,source=$$(pwd),target=/mnt $(DOCKER_IMAGE) /bin/sh -c "make build"
93-
qemu-img resize $(BOOTLOADER) 8g
100+
qemu-img resize $(KERNEL) 8g
94101
endif
95102

96103
.PHONY: run

‎bin/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)