makefile refactor
This commit is contained in:
parent
9f1c31f298
commit
93e48044f5
5 changed files with 33 additions and 34 deletions
|
|
@ -2,49 +2,38 @@ SHELL := /bin/bash
|
||||||
|
|
||||||
ARCH := x86
|
ARCH := x86
|
||||||
OS := bluesnow
|
OS := bluesnow
|
||||||
target ?= $(ARCH)-$(OS)
|
TARGET ?= $(ARCH)-$(OS)
|
||||||
|
|
||||||
NASM := /usr/bin/nasm -f elf -g
|
## COMPILE ASM (nasm)
|
||||||
LD := /usr/bin/ld -m elf_i386 -L ./ -n --gc-sections
|
|
||||||
MKDIR := mkdir -p
|
|
||||||
|
|
||||||
kernel := build/$(OS)
|
|
||||||
iso := $(kernel).iso
|
|
||||||
DIRISO := build/isofiles
|
|
||||||
|
|
||||||
rust_os := target/$(target)/debug/lib$(OS).a
|
|
||||||
|
|
||||||
linker_script := src/arch/$(ARCH)/linker.ld
|
|
||||||
grub.cfg := src/arch/$(ARCH)/grub.cfg
|
|
||||||
asm_source := $(wildcard src/arch/$(ARCH)/*.asm)
|
asm_source := $(wildcard src/arch/$(ARCH)/*.asm)
|
||||||
asm_object := $(patsubst src/arch/$(ARCH)/%.asm, build/arch/$(ARCH)/%.o, $(asm_source))
|
asm_object := $(patsubst src/arch/$(ARCH)/%.asm, build/arch/$(ARCH)/%.o, $(asm_source))
|
||||||
|
NASM := /usr/bin/nasm -f elf -g
|
||||||
all: $(kernel)
|
|
||||||
|
|
||||||
build/arch/$(ARCH)/%.o: src/arch/$(ARCH)/%.asm Makefile
|
build/arch/$(ARCH)/%.o: src/arch/$(ARCH)/%.asm Makefile
|
||||||
@$(MKDIR) $(shell dirname $@)
|
@mkdir -p $(shell dirname $@)
|
||||||
$(NASM) $< -o $@
|
$(NASM) $< -o $@
|
||||||
|
|
||||||
|
## COMPILE RUST (xargo)
|
||||||
|
rust_os := target/$(TARGET)/debug/lib$(OS).a
|
||||||
|
$(rust_os): $(TARGET).json Makefile
|
||||||
|
@RUST_TARGET_PATH="$(shell pwd)" xargo build --target $(TARGET)
|
||||||
|
|
||||||
|
## LINKAGE
|
||||||
|
kernel := build/$(OS)
|
||||||
|
linker_script := src/arch/$(ARCH)/linker.ld
|
||||||
|
LD := /usr/bin/ld -m elf_i386 -L ./ -n --gc-sections
|
||||||
$(kernel): $(rust_os) $(asm_object) $(linker_script) Makefile
|
$(kernel): $(rust_os) $(asm_object) $(linker_script) Makefile
|
||||||
$(LD) -o $@ -T $(linker_script) $(asm_object) $(rust_os)
|
$(LD) -o $@ -T $(linker_script) $(asm_object) $(rust_os)
|
||||||
|
|
||||||
$(iso): $(kernel) $(grub.cfg) Makefile
|
|
||||||
@$(MKDIR) $(DIRISO)/boot/grub
|
|
||||||
@cp $(grub.cfg) $(DIRISO)/boot/grub
|
|
||||||
@cp $(kernel) $(DIRISO)/boot/$(OS)
|
|
||||||
@grub-mkrescue -o $@ $(DIRISO) 2>/dev/null
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@xargo clean
|
@xargo clean
|
||||||
@rm -rf build
|
@rm -rf build
|
||||||
|
|
||||||
$(rust_os): $(target).json Makefile
|
|
||||||
@RUST_TARGET_PATH="$(shell pwd)" xargo build --target $(target)
|
|
||||||
|
|
||||||
kernel: $(rust_os)
|
|
||||||
iso: $(iso)
|
|
||||||
|
|
||||||
.PHONY: clean kernel iso $(rust_os)
|
.PHONY: clean kernel iso $(rust_os)
|
||||||
|
|
||||||
# Emulation recipes
|
# Emulation recipes
|
||||||
include mk/qemu.mk
|
include mk/qemu.mk
|
||||||
|
|
||||||
|
# Bootloader recipes
|
||||||
|
include mk/grub.mk
|
||||||
|
iso: $(grub-iso)
|
||||||
|
|
||||||
|
|
|
||||||
9
kernel-rs/mk/grub.mk
Normal file
9
kernel-rs/mk/grub.mk
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
grub-iso := $(kernel).iso
|
||||||
|
grub-cfg := src/arch/$(ARCH)/grub.cfg
|
||||||
|
isodir := build/isofiles
|
||||||
|
|
||||||
|
$(grub-iso): $(kernel) $(grub-cfg) Makefile
|
||||||
|
@mkdir -p $(isodir)/boot/grub
|
||||||
|
@cp $(grub-cfg) $(isodir)/boot/grub
|
||||||
|
@cp $(kernel) $(isodir)/boot/$(OS)
|
||||||
|
@grub-mkrescue -o $@ $(isodir) 2>/dev/null
|
||||||
|
|
@ -7,7 +7,7 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
QEMU := qemu-system-x86_64
|
QEMU := qemu-system-x86_64
|
||||||
QEMUFLAGS := -gdb tcp::$(PORTG) -enable-kvm -monitor telnet:127.0.0.1:$(PORT),server,nowait -curses -cdrom
|
QEMUFLAGS := -gdb tcp::$(PORTG) -enable-kvm -monitor telnet:127.0.0.1:$(PORT),server,nowait -curses -cdrom build/$(kernel).iso
|
||||||
|
|
||||||
MONITOR := sleep 0.5;\
|
MONITOR := sleep 0.5;\
|
||||||
telnet 127.0.0.1 $(PORT);\
|
telnet 127.0.0.1 $(PORT);\
|
||||||
|
|
@ -21,5 +21,5 @@ GDB := gdb -q\
|
||||||
|
|
||||||
qemu:
|
qemu:
|
||||||
@tmux info >&- || { echo -e "\033[38;5;16mPlease run inside a tmux session\033[0m" ; exit 1; }
|
@tmux info >&- || { echo -e "\033[38;5;16mPlease run inside a tmux session\033[0m" ; exit 1; }
|
||||||
@tmux new-window 'tmux split-window -h "$(MONITOR)"; tmux split-window -fv "$(GDB)"; tmux select-pane -t 1; tmux resize-pane -x 80 -y 25; $(QEMU) $(QEMUFLAGS) $(iso)'
|
@tmux new-window 'tmux split-window -h "$(MONITOR)"; tmux split-window -fv "$(GDB)"; tmux select-pane -t 1; tmux resize-pane -x 80 -y 25; $(QEMU) $(QEMUFLAGS)'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ bits 32
|
||||||
start:
|
start:
|
||||||
; our stack, located in bss, linker.ld puts bss at the end of the binary
|
; our stack, located in bss, linker.ld puts bss at the end of the binary
|
||||||
mov esp, stack_top
|
mov esp, stack_top
|
||||||
|
|
||||||
; multiboot information pointer
|
; multiboot information pointer
|
||||||
push ebx
|
push ebx
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ align 4096
|
||||||
p2_table:
|
p2_table:
|
||||||
resb 4096
|
resb 4096
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
resb 4096 * 4
|
resb 4096 * 3
|
||||||
stack_top:
|
stack_top:
|
||||||
|
|
||||||
section .gdt
|
section .gdt
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ exception_err!(general_protection, {});
|
||||||
pub extern "x86-interrupt" fn page_fault(
|
pub extern "x86-interrupt" fn page_fault(
|
||||||
stack_frame: &mut ExceptionStackFrame,
|
stack_frame: &mut ExceptionStackFrame,
|
||||||
code: PageFaultErrorCode,
|
code: PageFaultErrorCode,
|
||||||
) {
|
) {
|
||||||
println!("Exception: page_fault");
|
println!("Exception: page_fault");
|
||||||
println!("Error code: {:#b}", code);
|
println!("Error code: {:?}", code);
|
||||||
println!("{:#?}", stack_frame);
|
println!("{:#?}", stack_frame);
|
||||||
flush!();
|
flush!();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue