Fix x86_64. Not elegant.

master
WangRunji 6 years ago
parent b61a2c9dd2
commit 3d6fcb8d8c

2
.gitignore vendored

@ -1,3 +1,3 @@
build build
target target
kernel/src/arch/x86_64/boot/vector.asm /kernel/src/arch/x86_64/interrupt/vector.asm

@ -3,6 +3,9 @@ name = "ucore"
version = "0.1.0" version = "0.1.0"
authors = ["Runji Wang <wangrunji0408@163.com>"] authors = ["Runji Wang <wangrunji0408@163.com>"]
[lib]
crate-type = ["staticlib", "rlib"]
[features] [features]
use_apic = [] use_apic = []
link_user_program = [] link_user_program = []

@ -27,7 +27,7 @@ user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(u
user_obj := build/$(arch)/user.o user_obj := build/$(arch)/user.o
SFSIMG := ../user/ucore32.img SFSIMG := ../user/ucore32.img
ifeq ($(arch), x86_64) ifeq ($(arch), x86_64)
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback -device isa-debug-exit
endif endif
ifeq ($(arch), riscv32) ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic qemu_opts := -machine virt -kernel $(iso) -nographic
@ -42,25 +42,8 @@ features := $(features) link_user_program
assembly_object_files := $(assembly_object_files) $(user_obj) assembly_object_files := $(assembly_object_files) $(user_obj)
endif endif
# Link user-riscv.img for RV32 ifdef d
ifeq ($(arch), riscv32) qemu_opts := $(qemu_opts) -d $(d)
riscv_user_img_obj := build/riscv32/user-riscv.o
assembly_object_files := $(assembly_object_files) $(riscv_user_img_obj)
endif
ifdef travis
test := 1
features := $(features) qemu_auto_exit
endif
ifdef test
features := $(features) test
# enable shutdown inside the qemu
qemu_opts := $(qemu_opts) -device isa-debug-exit
endif
ifdef int
qemu_opts := $(qemu_opts) -d int
endif endif
build_args := --target $(target).json --features "$(features)" build_args := --target $(target).json --features "$(features)"
@ -69,6 +52,10 @@ ifeq ($(mode), release)
build_args := $(build_args) --release build_args := $(build_args) --release
endif endif
ifeq ($(arch), x86_64)
build_args := $(build_args) --lib
endif
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
uname := Win32 uname := Win32
@ -124,6 +111,7 @@ build/x86_64/os.iso: $(kernel) $(grub_cfg)
@rm -r build/isofiles @rm -r build/isofiles
build/riscv32/os.iso: kernel build/riscv32/os.iso: kernel
@mkdir -p build/riscv32
@cd ../riscv-pk && \ @cd ../riscv-pk && \
mkdir -p build && \ mkdir -p build && \
cd build && \ cd build && \
@ -138,7 +126,7 @@ build/riscv32/os.iso: kernel
$(kernel): kernel $(assembly_object_files) $(linker_script) $(kernel): kernel $(assembly_object_files) $(linker_script)
@$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \ @$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \
$(assembly_object_files) $(rust_lib) $(assembly_object_files) target/x86_64-blog_os/$(mode)/libucore.a
kernel: kernel:
@CC=$(cc) cargo xbuild $(build_args) @CC=$(cc) cargo xbuild $(build_args)
@ -148,18 +136,7 @@ build/x86_64/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@) @mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@ @nasm -felf64 $< -o $@
build/riscv32/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make user.o from binary files # make user.o from binary files
$(user_obj): $(user_bins) $(user_obj): $(user_bins)
@cd $(user_bin_path) && \ @cd $(user_bin_path) && \
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins))) $(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins)))
$(riscv_user_img_obj): ../user/user-riscv.img
@cd ../user && $(ld) -o $(abspath $@) -b binary $(notdir $<)
# patch Rust core for RISCV32I atomic
patch-core:
@patch -p0 /rust/rust-riscv-rust-1.26.0-1-dev/src/libcore/sync/atomic.rs src/arch/riscv32/atomic.patch

@ -15,11 +15,11 @@ fn main() {
} }
fn gen_vector_asm() -> Result<()> { fn gen_vector_asm() -> Result<()> {
let mut f = File::create("src/arch/x86_64/boot/vector.asm").unwrap(); let mut f = File::create("src/arch/x86_64/interrupt/vector.asm").unwrap();
writeln!(f, "# generated by build.rs - do not edit")?; writeln!(f, "# generated by build.rs - do not edit")?;
writeln!(f, "section .text")?; writeln!(f, ".section .text")?;
writeln!(f, "extern __alltraps")?; writeln!(f, ".intel_syntax noprefix")?;
for i in 0..256 { for i in 0..256 {
writeln!(f, "vector{}:", i)?; writeln!(f, "vector{}:", i)?;
if !(i == 8 || (i >= 10 && i <= 14) || i == 17) { if !(i == 8 || (i >= 10 && i <= 14) || i == 17) {
@ -29,11 +29,11 @@ fn gen_vector_asm() -> Result<()> {
writeln!(f, "\tjmp __alltraps")?; writeln!(f, "\tjmp __alltraps")?;
} }
writeln!(f, "\nsection .rodata")?; writeln!(f, "\n.section .rodata")?;
writeln!(f, "global __vectors")?; writeln!(f, ".global __vectors")?;
writeln!(f, "__vectors:")?; writeln!(f, "__vectors:")?;
for i in 0..256 { for i in 0..256 {
writeln!(f, "\tdq vector{}", i)?; writeln!(f, "\t.quad vector{}", i)?;
} }
Ok(()) Ok(())
} }

File diff suppressed because it is too large Load Diff

@ -67,6 +67,9 @@
use super::consts::*; use super::consts::*;
use super::TrapFrame; use super::TrapFrame;
global_asm!(include_str!("trap.asm"));
global_asm!(include_str!("vector.asm"));
#[no_mangle] #[no_mangle]
pub extern fn rust_trap(tf: &mut TrapFrame) { pub extern fn rust_trap(tf: &mut TrapFrame) {
trace!("Interrupt: {:#x}", tf.trap_num); trace!("Interrupt: {:#x}", tf.trap_num);

@ -1,5 +1,7 @@
section .text .section .text
global __alltraps .global __alltraps
.intel_syntax noprefix
__alltraps: __alltraps:
push rax push rax
push rcx push rcx
@ -19,14 +21,12 @@ __alltraps:
push r15 push r15
mov rdi, rsp mov rdi, rsp
extern rust_trap
call rust_trap call rust_trap
global trap_ret .global trap_ret
trap_ret: trap_ret:
mov rdi, rsp mov rdi, rsp
extern set_return_rsp
call set_return_rsp call set_return_rsp
pop r15 pop r15
@ -46,7 +46,7 @@ trap_ret:
pop rcx pop rcx
pop rax pop rax
; pop trap_num, error_code # pop trap_num, error_code
add rsp, 16 add rsp, 16
iretq iretq

@ -40,12 +40,6 @@ extern crate volatile;
extern crate x86_64; extern crate x86_64;
extern crate xmas_elf; extern crate xmas_elf;
// Export to asm
pub use arch::interrupt::rust_trap;
#[cfg(target_arch = "x86_64")]
pub use arch::interrupt::set_return_rsp;
#[cfg(target_arch = "x86_64")]
pub use arch::other_main;
use linked_list_allocator::LockedHeap; use linked_list_allocator::LockedHeap;
#[macro_use] // print! #[macro_use] // print!
@ -66,7 +60,7 @@ mod console;
#[allow(dead_code)] #[allow(dead_code)]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[path = "arch/x86_64/mod.rs"] #[path = "arch/x86_64/mod.rs"]
mod arch; pub mod arch;
#[cfg(target_arch = "riscv32")] #[cfg(target_arch = "riscv32")]
#[path = "arch/riscv32/mod.rs"] #[path = "arch/riscv32/mod.rs"]

Loading…
Cancel
Save