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
|
||||
OS := bluesnow
|
||||
target ?= $(ARCH)-$(OS)
|
||||
TARGET ?= $(ARCH)-$(OS)
|
||||
|
||||
NASM := /usr/bin/nasm -f elf -g
|
||||
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
|
||||
## COMPILE ASM (nasm)
|
||||
asm_source := $(wildcard src/arch/$(ARCH)/*.asm)
|
||||
asm_object := $(patsubst src/arch/$(ARCH)/%.asm, build/arch/$(ARCH)/%.o, $(asm_source))
|
||||
|
||||
all: $(kernel)
|
||||
|
||||
NASM := /usr/bin/nasm -f elf -g
|
||||
build/arch/$(ARCH)/%.o: src/arch/$(ARCH)/%.asm Makefile
|
||||
@$(MKDIR) $(shell dirname $@)
|
||||
@mkdir -p $(shell dirname $@)
|
||||
$(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
|
||||
$(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:
|
||||
@xargo clean
|
||||
@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)
|
||||
|
||||
# Emulation recipes
|
||||
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
|
||||
|
||||
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;\
|
||||
telnet 127.0.0.1 $(PORT);\
|
||||
|
|
@ -21,5 +21,5 @@ GDB := gdb -q\
|
|||
|
||||
qemu:
|
||||
@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:
|
||||
; our stack, located in bss, linker.ld puts bss at the end of the binary
|
||||
mov esp, stack_top
|
||||
|
||||
; multiboot information pointer
|
||||
push ebx
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ align 4096
|
|||
p2_table:
|
||||
resb 4096
|
||||
stack_bottom:
|
||||
resb 4096 * 4
|
||||
resb 4096 * 3
|
||||
stack_top:
|
||||
|
||||
section .gdt
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub extern "x86-interrupt" fn page_fault(
|
|||
code: PageFaultErrorCode,
|
||||
) {
|
||||
println!("Exception: page_fault");
|
||||
println!("Error code: {:#b}", code);
|
||||
println!("Error code: {:?}", code);
|
||||
println!("{:#?}", stack_frame);
|
||||
flush!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue