Conditional kernel inclusion

parent 962004fc
...@@ -4,18 +4,27 @@ TARGET=$(ARCH)-unknown-none ...@@ -4,18 +4,27 @@ TARGET=$(ARCH)-unknown-none
export LD=ld export LD=ld
export OBJCOPY=objcopy export OBJCOPY=objcopy
export RUST_TARGET_PATH=$(CURDIR)/targets export RUST_TARGET_PATH=$(CURDIR)/targets
export XARGO_HOME=$(CURDIR)/build/xargo export XARGO_HOME=$(CURDIR)/target/xargo
all: build/bootloader all: build/bootloader
build/libstartup.o: src/nasm/startup.asm src/nasm/* build/kernel clean:
rm -rf build
build/libstartup.o: src/nasm/startup.asm src/nasm/*
mkdir -p build
ifeq ($(KERNEL),)
nasm -f elf32 $< -I src/nasm/ -o $@ nasm -f elf32 $< -I src/nasm/ -o $@
else
nasm -f elf32 $< -I src/nasm/ -D KERNEL=$(KERNEL) -o $@
endif
build/libbootloader.a: Cargo.lock Cargo.toml src/* src/*/* src/*/*/* src/*/*/*/* build/libbootloader.a: Cargo.lock Cargo.toml src/* src/*/* src/*/*/* src/*/*/*/*
mkdir -p build mkdir -p build
xargo rustc --lib --target $(TARGET) --release -- -C soft-float -C debuginfo=2 --emit link=$@ xargo rustc --lib --target $(TARGET) --release -- -C soft-float -C debuginfo=2 --emit link=$@
build/bootloader: linkers/$(ARCH).ld build/libstartup.o build/libbootloader.a build/bootloader: linkers/$(ARCH).ld build/libstartup.o build/libbootloader.a
mkdir -p build
$(LD) -m elf_i386 --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libstartup.o build/libbootloader.a && \ $(LD) -m elf_i386 --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libstartup.o build/libbootloader.a && \
$(OBJCOPY) --only-keep-debug $@ $@.sym && \ $(OBJCOPY) --only-keep-debug $@ $@.sym && \
$(OBJCOPY) --strip-debug $@ $(OBJCOPY) --strip-debug $@
...@@ -43,6 +43,7 @@ long_mode: ...@@ -43,6 +43,7 @@ long_mode:
mov gs, rax mov gs, rax
mov ss, rax mov ss, rax
%ifdef KERNEL
; set kernel size ; set kernel size
mov rax, __kernel_end mov rax, __kernel_end
sub rax, __kernel sub rax, __kernel
...@@ -61,6 +62,8 @@ long_mode: ...@@ -61,6 +62,8 @@ long_mode:
; entry point ; entry point
mov rax, [args.kernel_base] mov rax, [args.kernel_base]
call [rax + 0x18] call [rax + 0x18]
%endif
.halt: .halt:
cli cli
hlt hlt
...@@ -111,6 +114,9 @@ iend ...@@ -111,6 +114,9 @@ iend
.end equ $ - gdt .end equ $ - gdt
SECTION .kernel SECTION .kernel
%ifdef KERNEL
__kernel: __kernel:
INCBIN "build/kernel" %defstr KERNEL_STR %[KERNEL]
INCBIN KERNEL_STR
__kernel_end: __kernel_end:
%endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment