Seperate kernel and userspace targets
This commit is contained in:
parent
729c7fd004
commit
0b1265d87e
155
Makefile
155
Makefile
|
@ -1,15 +1,50 @@
|
||||||
ARCH?=x86_64
|
ARCH?=x86_64
|
||||||
|
|
||||||
|
# Kernel variables
|
||||||
|
KTARGET=$(ARCH)-unknown-none
|
||||||
|
KBUILD=build/kernel
|
||||||
|
KRUSTC=./krustc.sh
|
||||||
|
KRUSTCFLAGS=--target $(KTARGET).json -O -C soft-float
|
||||||
|
KCARGO=RUSTC="$(KRUSTC)" cargo
|
||||||
|
KCARGOFLAGS=--target $(KTARGET).json -- -O -C soft-float
|
||||||
|
|
||||||
|
# Userspace variables
|
||||||
|
TARGET=$(ARCH)-unknown-redox
|
||||||
|
BUILD=build/userspace
|
||||||
|
RUSTC=./rustc.sh
|
||||||
|
RUSTCFLAGS=--target $(TARGET).json -O -C soft-float --cfg redox
|
||||||
|
CARGO=RUSTC="$(RUSTC)" cargo
|
||||||
|
CARGOFLAGS=--target $(TARGET).json -- -O -C soft-float --cfg redox
|
||||||
|
|
||||||
|
# Default targets
|
||||||
|
.PHONY: all clean qemu bochs FORCE
|
||||||
|
|
||||||
|
all: $(KBUILD)/harddrive.bin
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
|
cargo clean --manifest-path libstd/Cargo.toml
|
||||||
|
cargo clean --manifest-path init/Cargo.toml
|
||||||
|
rm -rf build
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
|
||||||
|
# Emulation
|
||||||
QEMU=qemu-system-$(ARCH)
|
QEMU=qemu-system-$(ARCH)
|
||||||
QEMUFLAGS=-serial mon:stdio -d guest_errors
|
QEMUFLAGS=-serial mon:stdio -d guest_errors
|
||||||
|
|
||||||
RUSTCFLAGS=--target $(ARCH)-unknown-redox.json -O -C soft-float --cfg redox
|
|
||||||
CARGOFLAGS=--target $(ARCH)-unknown-redox.json -- -O -C soft-float --cfg redox
|
|
||||||
|
|
||||||
ifeq ($(ARCH),arm)
|
ifeq ($(ARCH),arm)
|
||||||
LD=$(ARCH)-none-eabi-ld
|
LD=$(ARCH)-none-eabi-ld
|
||||||
QEMUFLAGS+=-cpu arm1176 -machine integratorcp
|
QEMUFLAGS+=-cpu arm1176 -machine integratorcp
|
||||||
QEMUFLAGS+=-nographic
|
QEMUFLAGS+=-nographic
|
||||||
|
|
||||||
|
$(KBUILD)/kernel.list: $(KBUILD)/kernel.bin
|
||||||
|
$(ARCH)-none-eabi-objdump -C -D $< > $@
|
||||||
|
|
||||||
|
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel.bin
|
||||||
|
cp $< $@
|
||||||
|
|
||||||
|
qemu: $(KBUILD)/harddrive.bin
|
||||||
|
$(QEMU) $(QEMUFLAGS) -kernel $<
|
||||||
else
|
else
|
||||||
LD=ld
|
LD=ld
|
||||||
QEMUFLAGS+=-enable-kvm -cpu host -machine q35 -smp 4
|
QEMUFLAGS+=-enable-kvm -cpu host -machine q35 -smp 4
|
||||||
|
@ -22,69 +57,63 @@ else
|
||||||
LD=$(ARCH)-elf-ld
|
LD=$(ARCH)-elf-ld
|
||||||
QEMUFLAGS=
|
QEMUFLAGS=
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
all: build/kernel.bin
|
$(KBUILD)/kernel.list: $(KBUILD)/kernel.bin
|
||||||
|
|
||||||
list: build/kernel.list
|
|
||||||
|
|
||||||
run: bochs
|
|
||||||
|
|
||||||
bochs: build/harddrive.bin
|
|
||||||
bochs -f bochs.$(ARCH)
|
|
||||||
|
|
||||||
FORCE:
|
|
||||||
|
|
||||||
build/libcore.rlib: rust/src/libcore/lib.rs
|
|
||||||
mkdir -p build
|
|
||||||
./rustc.sh $(RUSTCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
build/librand.rlib: rust/src/librand/lib.rs build/libcore.rlib
|
|
||||||
./rustc.sh $(RUSTCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
build/liballoc.rlib: rust/src/liballoc/lib.rs build/libcore.rlib
|
|
||||||
./rustc.sh $(RUSTCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
build/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs build/libcore.rlib
|
|
||||||
./rustc.sh $(RUSTCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
build/libcollections.rlib: rust/src/libcollections/lib.rs build/libcore.rlib build/liballoc.rlib build/librustc_unicode.rlib
|
|
||||||
./rustc.sh $(RUSTCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
build/libstd.rlib: libstd/Cargo.toml libstd/src/** build/libcore.rlib build/liballoc.rlib build/librustc_unicode.rlib build/libcollections.rlib build/librand.rlib
|
|
||||||
RUSTC="./rustc.sh" cargo rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
|
||||||
cp libstd/target/$(ARCH)-unknown-redox/debug/deps/*.rlib build
|
|
||||||
|
|
||||||
build/init: init/Cargo.toml init/src/*.rs build/libstd.rlib
|
|
||||||
RUSTC="./rustc.sh" cargo rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
|
||||||
strip $@
|
|
||||||
|
|
||||||
build/libkernel.a: build/libcore.rlib build/liballoc.rlib build/libcollections.rlib build/init kernel/** FORCE
|
|
||||||
RUSTC="./rustc.sh" cargo rustc $(CARGOFLAGS) -o $@
|
|
||||||
|
|
||||||
build/kernel.bin: build/libkernel.a
|
|
||||||
$(LD) --gc-sections -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $<
|
|
||||||
strip $@
|
|
||||||
|
|
||||||
ifeq ($(ARCH),arm)
|
|
||||||
build/kernel.list: build/kernel.bin
|
|
||||||
$(ARCH)-none-eabi-objdump -C -D $< > $@
|
|
||||||
|
|
||||||
qemu: build/kernel.bin
|
|
||||||
$(QEMU) $(QEMUFLAGS) -kernel $<
|
|
||||||
else
|
|
||||||
build/kernel.list: build/kernel.bin
|
|
||||||
objdump -C -M intel -D $< > $@
|
objdump -C -M intel -D $< > $@
|
||||||
|
|
||||||
build/harddrive.bin: build/kernel.bin bootloader/$(ARCH)/**
|
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel.bin bootloader/$(ARCH)/**
|
||||||
nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ -ibuild/ bootloader/$(ARCH)/harddrive.asm
|
nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ -i$(KBUILD)/ bootloader/$(ARCH)/harddrive.asm
|
||||||
|
|
||||||
qemu: build/harddrive.bin
|
qemu: $(KBUILD)/harddrive.bin
|
||||||
$(QEMU) $(QEMUFLAGS) -drive file=$<,format=raw,index=0,media=disk
|
$(QEMU) $(QEMUFLAGS) -drive file=$<,format=raw,index=0,media=disk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
clean:
|
bochs: $(KBUILD)/harddrive.bin
|
||||||
cargo clean
|
bochs -f bochs.$(ARCH)
|
||||||
cargo clean --manifest-path libstd/Cargo.toml
|
|
||||||
cargo clean --manifest-path init/Cargo.toml
|
# Kernel recipes
|
||||||
rm -rf build/*
|
$(KBUILD)/libcore.rlib: rust/src/libcore/lib.rs
|
||||||
|
mkdir -p $(KBUILD)
|
||||||
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(KBUILD)/librand.rlib: rust/src/librand/lib.rs $(KBUILD)/libcore.rlib
|
||||||
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(KBUILD)/liballoc.rlib: rust/src/liballoc/lib.rs $(KBUILD)/libcore.rlib
|
||||||
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(KBUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(KBUILD)/libcore.rlib
|
||||||
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/librustc_unicode.rlib
|
||||||
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(KBUILD)/libkernel.a: $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/init kernel/** FORCE
|
||||||
|
$(KCARGO) rustc $(KCARGOFLAGS) -o $@
|
||||||
|
|
||||||
|
$(KBUILD)/kernel.bin: $(KBUILD)/libkernel.a
|
||||||
|
$(LD) --gc-sections -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $<
|
||||||
|
|
||||||
|
# Userspace recipes
|
||||||
|
$(BUILD)/libcore.rlib: rust/src/libcore/lib.rs
|
||||||
|
mkdir -p $(BUILD)
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/librand.rlib: rust/src/librand/lib.rs $(BUILD)/libcore.rlib
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/liballoc.rlib: rust/src/liballoc/lib.rs $(BUILD)/libcore.rlib
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(BUILD)/libcore.rlib
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(BUILD)/libcore.rlib $(BUILD)/liballoc.rlib $(BUILD)/librustc_unicode.rlib
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/libstd.rlib: libstd/Cargo.toml libstd/src/** $(BUILD)/libcore.rlib $(BUILD)/liballoc.rlib $(BUILD)/librustc_unicode.rlib $(BUILD)/libcollections.rlib $(BUILD)/librand.rlib
|
||||||
|
$(CARGO) rustc --verbose --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
|
cp libstd/target/$(TARGET)/debug/deps/*.rlib $(BUILD)
|
||||||
|
|
||||||
|
$(BUILD)/init: init/Cargo.toml init/src/*.rs $(BUILD)/libstd.rlib
|
||||||
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
|
|
|
@ -142,7 +142,7 @@ pub extern fn kmain() {
|
||||||
let stderr = syscall::open("debug:".as_bytes(), 0);
|
let stderr = syscall::open("debug:".as_bytes(), 0);
|
||||||
println!("STDERR: {:?}", stderr);
|
println!("STDERR: {:?}", stderr);
|
||||||
|
|
||||||
let elf = elf::Elf::from(include_bytes!("../build/init")).expect("could not load elf");
|
let elf = elf::Elf::from(include_bytes!("../build/userspace/init")).expect("could not load elf");
|
||||||
elf.run();
|
elf.run();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
2
krustc.sh
Executable file
2
krustc.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/bash
|
||||||
|
RUST_BACKTRACE=1 rustc -L build/kernel --cfg redox $*
|
2
rustc.sh
2
rustc.sh
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
RUST_BACKTRACE=1 rustc -L build --cfg redox $*
|
RUST_BACKTRACE=1 rustc -L build/userspace --cfg redox $*
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"dynamic-linking": false,
|
"dynamic-linking": false,
|
||||||
"executables": true,
|
"executables": true,
|
||||||
"relocation-model": "static",
|
"relocation-model": "static",
|
||||||
"code-model": "kernel",
|
"code-model": "default",
|
||||||
"disable-redzone": true,
|
"disable-redzone": true,
|
||||||
"eliminate-frame-pointer": false,
|
"eliminate-frame-pointer": false,
|
||||||
"exe-suffix": "",
|
"exe-suffix": "",
|
||||||
|
|
Loading…
Reference in a new issue