From 97d3551106495fa18969e2690720b621ba5a9c0b Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sun, 24 Jun 2018 02:27:22 +1000 Subject: Re-structured the source tree and modified makefiles accordingly. Hopefully further separation will help to keep the code readable and understandable. --- Makefile | 22 ++++++++++++++++++---- kernel/Makefile | 13 +++---------- kernel/link.ld | 10 ---------- kernel/usrbin/Makefile | 32 -------------------------------- kernel/usrbin/lib.s | 10 ---------- kernel/usrbin/link.ld | 8 -------- kernel/usrbin/main.c | 7 ------- kernel/usrbin/print.c | 3 --- link.ld | 10 ++++++++++ usrbin/Makefile | 32 ++++++++++++++++++++++++++++++++ usrbin/lib.s | 10 ++++++++++ usrbin/link.ld | 8 ++++++++ usrbin/main.c | 7 +++++++ usrbin/print.c | 3 +++ 14 files changed, 91 insertions(+), 84 deletions(-) delete mode 100644 kernel/link.ld delete mode 100644 kernel/usrbin/Makefile delete mode 100644 kernel/usrbin/lib.s delete mode 100644 kernel/usrbin/link.ld delete mode 100644 kernel/usrbin/main.c delete mode 100644 kernel/usrbin/print.c create mode 100644 link.ld create mode 100644 usrbin/Makefile create mode 100644 usrbin/lib.s create mode 100644 usrbin/link.ld create mode 100644 usrbin/main.c create mode 100644 usrbin/print.c diff --git a/Makefile b/Makefile index 919e5f1..15f76ec 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,24 @@ +TARGET = kernel.elf + +LDFLAGS = -m elf_i386 -T link.ld + +LD = ld $(LDFLAGS) + all: build -build: - $(MAKE) -C kernel +build: $(TARGET) -run: - $(MAKE) -C kernel run +$(TARGET): .FORCE + $(MAKE) -C kernel + $(MAKE) -C usrbin + $(LD) -o $(TARGET) kernel/kernel.o usrbin/usrbin_blob.o clean: $(MAKE) -C kernel clean + $(MAKE) -C usrbin clean + rm -f $(TARGET) + +run: + qemu-system-x86_64 -s -kernel $(TARGET) + +.FORCE: diff --git a/kernel/Makefile b/kernel/Makefile index 6cf8ae4..c6cf24e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,11 +1,11 @@ -TARGET = kernel +TARGET = kernel.o SRCS = $(wildcard *.c) ASMS = $(wildcard *.s) -OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) usrbin/usrbin_blob.o +OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) CFLAGS = -m32 -I../include -ffreestanding -nostdinc -nostdlib -fno-stack-protector -fno-pie -gstabs+ -LDFLAGS = -m elf_i386 -T link.ld +LDFLAGS = -m elf_i386 -r ASMFLAGS = -f elf32 CC = gcc $(CFLAGS) @@ -16,9 +16,6 @@ all: build build: $(TARGET) -usrbin/usrbin_blob.o: $(wildcard usrbin/*.s) $(wildcard usrbin/*.c) - $(MAKE) -C usrbin - .s.o: $(ASM) -o $*.o $^ @@ -31,7 +28,3 @@ $(TARGET): $(OBJS) clean: rm -f $(OBJS) rm -f $(TARGET) - $(MAKE) -C usrbin clean - -run: $(TARGET) - qemu-system-x86_64 -s -kernel $(TARGET) diff --git a/kernel/link.ld b/kernel/link.ld deleted file mode 100644 index 21c9b7c..0000000 --- a/kernel/link.ld +++ /dev/null @@ -1,10 +0,0 @@ -OUTPUT_FORMAT(elf32-i386) -ENTRY(kboot) -SECTIONS -{ - . = 0; - .mboothdr : { *(.mboothdr) } - .text : { *(.text) } - .data : { *(.data) } - .bss : { *(.bss) } -} diff --git a/kernel/usrbin/Makefile b/kernel/usrbin/Makefile deleted file mode 100644 index dd42909..0000000 --- a/kernel/usrbin/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -TARGET = usrbin_blob.o - -SRCS = $(wildcard *.c) -ASMS = $(wildcard *.s) -OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) - -CFLAGS = -m32 -I../../include -ffreestanding -nostdinc -nostdlib -fno-stack-protector -fno-pie -LDFLAGS = -m elf_i386 -T link.ld -ASMFLAGS = -f elf32 - -CC = gcc $(CFLAGS) -LD = ld $(LDFLAGS) -ASM = nasm $(ASMFLAGS) - -all: build - -build: $(TARGET) - -.s.o: - $(ASM) -o $*.o $^ - -.c.o: - $(CC) -c -o $*.o $^ - -$(TARGET): $(OBJS) - $(LD) -o usrbin.bin $(OBJS) - objcopy -I binary -O elf32-i386 -B i386 usrbin.bin $(TARGET) - -clean: - rm -f usrbin.bin - rm -f $(OBJS) - rm -f $(TARGET) diff --git a/kernel/usrbin/lib.s b/kernel/usrbin/lib.s deleted file mode 100644 index ffe4f5f..0000000 --- a/kernel/usrbin/lib.s +++ /dev/null @@ -1,10 +0,0 @@ -bits 32 - -extern main - -section .entry -init: - call main -.loop: - ; loop forever - jmp .loop diff --git a/kernel/usrbin/link.ld b/kernel/usrbin/link.ld deleted file mode 100644 index c1a7a42..0000000 --- a/kernel/usrbin/link.ld +++ /dev/null @@ -1,8 +0,0 @@ -OUTPUT_FORMAT(binary) -SECTIONS -{ - . = 0x100000; - .text : { *(.entry); .*(.text) } - .data : { *(.data) } - .bss : { *(.bss) } -} diff --git a/kernel/usrbin/main.c b/kernel/usrbin/main.c deleted file mode 100644 index 5cc7567..0000000 --- a/kernel/usrbin/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -extern int print(char*); - -void main(void) { - print("We did it ma!\n"); -} diff --git a/kernel/usrbin/print.c b/kernel/usrbin/print.c deleted file mode 100644 index ea32cdf..0000000 --- a/kernel/usrbin/print.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -_syscall1(int, print, char*, s); diff --git a/link.ld b/link.ld new file mode 100644 index 0000000..21c9b7c --- /dev/null +++ b/link.ld @@ -0,0 +1,10 @@ +OUTPUT_FORMAT(elf32-i386) +ENTRY(kboot) +SECTIONS +{ + . = 0; + .mboothdr : { *(.mboothdr) } + .text : { *(.text) } + .data : { *(.data) } + .bss : { *(.bss) } +} diff --git a/usrbin/Makefile b/usrbin/Makefile new file mode 100644 index 0000000..16a607f --- /dev/null +++ b/usrbin/Makefile @@ -0,0 +1,32 @@ +TARGET = usrbin_blob.o + +SRCS = $(wildcard *.c) +ASMS = $(wildcard *.s) +OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) + +CFLAGS = -m32 -I../include -ffreestanding -nostdinc -nostdlib -fno-stack-protector -fno-pie +LDFLAGS = -m elf_i386 -T link.ld +ASMFLAGS = -f elf32 + +CC = gcc $(CFLAGS) +LD = ld $(LDFLAGS) +ASM = nasm $(ASMFLAGS) + +all: build + +build: $(TARGET) + +.s.o: + $(ASM) -o $*.o $^ + +.c.o: + $(CC) -c -o $*.o $^ + +$(TARGET): $(OBJS) + $(LD) -o usrbin.bin $(OBJS) + objcopy -I binary -O elf32-i386 -B i386 usrbin.bin $(TARGET) + +clean: + rm -f usrbin.bin + rm -f $(OBJS) + rm -f $(TARGET) diff --git a/usrbin/lib.s b/usrbin/lib.s new file mode 100644 index 0000000..ffe4f5f --- /dev/null +++ b/usrbin/lib.s @@ -0,0 +1,10 @@ +bits 32 + +extern main + +section .entry +init: + call main +.loop: + ; loop forever + jmp .loop diff --git a/usrbin/link.ld b/usrbin/link.ld new file mode 100644 index 0000000..c1a7a42 --- /dev/null +++ b/usrbin/link.ld @@ -0,0 +1,8 @@ +OUTPUT_FORMAT(binary) +SECTIONS +{ + . = 0x100000; + .text : { *(.entry); .*(.text) } + .data : { *(.data) } + .bss : { *(.bss) } +} diff --git a/usrbin/main.c b/usrbin/main.c new file mode 100644 index 0000000..5cc7567 --- /dev/null +++ b/usrbin/main.c @@ -0,0 +1,7 @@ +#include + +extern int print(char*); + +void main(void) { + print("We did it ma!\n"); +} diff --git a/usrbin/print.c b/usrbin/print.c new file mode 100644 index 0000000..ea32cdf --- /dev/null +++ b/usrbin/print.c @@ -0,0 +1,3 @@ +#include + +_syscall1(int, print, char*, s); -- cgit v1.3