From 2034e184efa409ba466a333f76c5778ae7990547 Mon Sep 17 00:00:00 2001 From: Chunyang Xu Date: Wed, 29 Oct 2014 16:03:05 +0800 Subject: [PATCH 1/2] Makefile: build bootloader --- Makefile | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 3060744..71130b9 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,31 @@ -CINC := -Isrc/inc -Isrc/inc/usr -CFLAG := -Wall -Werror -nostdinc -fno-builtin -fno-stack-protector \ - -finline-functions -finline-small-functions -findirect-inlining \ - -finline-functions-called-once +CC = i386-elf-gcc +LD = i386-elf-ld +OBJCOPY = i386-elf-objcopy +AS = nasm -include build/boot.mk -include build/kern.mk -include build/rootfs.mk -include build/user.mk +CFLAGS = -Wall -Werror -Isrc/inc -Isrc/inc/usr -nostdinc -fno-builtin \ + -fno-stack-protector -finline-functions -finline-small-functions \ + -findirect-inlining -finline-functions-called-once all: bochs -bochs: build +bochs: kernel.img bochs -q -f .bochsrc -debug: build +debug: kernel.img bochs-dbg -q -f .bochsrc -build: - echo +kernel.img: bin/boot.bin bin/main.bin + cat bin/boot.bin bin/main.bin > bin/kernel.img + +# -------------------------------------------------------------------- +# the bootloader part +# => boot.bin +bin/boot.bin: bin/boot.o tool/boot.ld + $(LD) bin/boot.o -o bin/boot.bin -T tool/boot.ld + +bin/boot.o: src/boot/boot.S + $(AS) -f elf -o bin/boot.o src/boot/boot.S clean: -rm -rf bin/* root/bin/* src/kern/entry.S .bochsout From 30577d8959bdca065519b52cd723b851ccfe2007 Mon Sep 17 00:00:00 2001 From: Chunyang Xu Date: Wed, 29 Oct 2014 22:11:03 +0800 Subject: [PATCH 2/2] Makefile: build kernel All the middle objects files are exactly under the same path as source files, instead of move they to ./bin Beside, since 'tool/main.ld' is changed, 'Rakefile' should not work as we expected. --- Makefile | 35 +++++++++++++++++++++++++---------- tool/main.ld | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 71130b9..066e4a1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ LD = i386-elf-ld OBJCOPY = i386-elf-objcopy AS = nasm -CFLAGS = -Wall -Werror -Isrc/inc -Isrc/inc/usr -nostdinc -fno-builtin \ +CFLAGS = -Wall -Isrc/inc -Isrc/inc/usr -nostdinc -fno-builtin \ -fno-stack-protector -finline-functions -finline-small-functions \ -findirect-inlining -finline-functions-called-once @@ -15,19 +15,34 @@ bochs: kernel.img debug: kernel.img bochs-dbg -q -f .bochsrc -kernel.img: bin/boot.bin bin/main.bin - cat bin/boot.bin bin/main.bin > bin/kernel.img +kernel.img: boot.bin kernel.bin + cat boot.bin kernel.bin > kernel.img # -------------------------------------------------------------------- -# the bootloader part -# => boot.bin -bin/boot.bin: bin/boot.o tool/boot.ld - $(LD) bin/boot.o -o bin/boot.bin -T tool/boot.ld +# bootloader +boot.bin: src/boot/boot.o + $(LD) $< -o $@ -T tool/boot.ld -bin/boot.o: src/boot/boot.S - $(AS) -f elf -o bin/boot.o src/boot/boot.S +# -------------------------------------------------------------------- +# kernel +HEADERS = $(wildcard src/**/*.h) +SRCS = $(wildcard src/**/*.c) +OBJS = src/kern/entry.o $(SRCS:.c=.o) + +kernel.bin: kernel.elf + $(OBJCOPY) -R .pdr -R .comment -R .note -S -O binary $< $@ + +kernel.elf: $(OBJS) + $(LD) $^ -o $@ -T tool/main.ld + +%.o: %.S + $(AS) -f elf -o $@ $< + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< clean: - -rm -rf bin/* root/bin/* src/kern/entry.S .bochsout + rm -f src/boot/boot.o src/kern/entry.o $(OBJS) + rm -f kernel.img boot.bin kernel.bin kernel.elf .PHONY: all bochs build debug clean diff --git a/tool/main.ld b/tool/main.ld index 8e9db7a..5fa166f 100644 --- a/tool/main.ld +++ b/tool/main.ld @@ -5,7 +5,7 @@ SECTIONS { .text 0x100000 : { __kbegin__ = .; __code__ = .; - bin/entry.o(.text) bin/main.o(.text) *(.text); + src/kern/entry.o(.text) src/kern/main.o(.text) *(.text); . = ALIGN(4096); } .data : {