1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-24 08:56:17 +04:00

Fix x86_64. Not elegant.

This commit is contained in:
WangRunji 2018-08-05 17:50:56 +08:00
parent b61a2c9dd2
commit 3d6fcb8d8c
8 changed files with 29 additions and 1332 deletions

2
.gitignore vendored
View File

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

View File

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

View File

@ -27,7 +27,7 @@ user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(u
user_obj := build/$(arch)/user.o
SFSIMG := ../user/ucore32.img
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
ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic
@ -42,25 +42,8 @@ features := $(features) link_user_program
assembly_object_files := $(assembly_object_files) $(user_obj)
endif
# Link user-riscv.img for RV32
ifeq ($(arch), riscv32)
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
ifdef d
qemu_opts := $(qemu_opts) -d $(d)
endif
build_args := --target $(target).json --features "$(features)"
@ -69,6 +52,10 @@ ifeq ($(mode), release)
build_args := $(build_args) --release
endif
ifeq ($(arch), x86_64)
build_args := $(build_args) --lib
endif
ifeq ($(OS),Windows_NT)
uname := Win32
@ -124,6 +111,7 @@ build/x86_64/os.iso: $(kernel) $(grub_cfg)
@rm -r build/isofiles
build/riscv32/os.iso: kernel
@mkdir -p build/riscv32
@cd ../riscv-pk && \
mkdir -p build && \
cd build && \
@ -138,7 +126,7 @@ build/riscv32/os.iso: kernel
$(kernel): kernel $(assembly_object_files) $(linker_script)
@$(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:
@CC=$(cc) cargo xbuild $(build_args)
@ -148,18 +136,7 @@ build/x86_64/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
build/riscv32/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make user.o from binary files
$(user_obj): $(user_bins)
@cd $(user_bin_path) && \
$(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

View File

@ -15,11 +15,11 @@ fn main() {
}
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, "section .text")?;
writeln!(f, "extern __alltraps")?;
writeln!(f, ".section .text")?;
writeln!(f, ".intel_syntax noprefix")?;
for i in 0..256 {
writeln!(f, "vector{}:", i)?;
if !(i == 8 || (i >= 10 && i <= 14) || i == 17) {
@ -29,11 +29,11 @@ fn gen_vector_asm() -> Result<()> {
writeln!(f, "\tjmp __alltraps")?;
}
writeln!(f, "\nsection .rodata")?;
writeln!(f, "global __vectors")?;
writeln!(f, "\n.section .rodata")?;
writeln!(f, ".global __vectors")?;
writeln!(f, "__vectors:")?;
for i in 0..256 {
writeln!(f, "\tdq vector{}", i)?;
writeln!(f, "\t.quad vector{}", i)?;
}
Ok(())
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -40,12 +40,6 @@ extern crate volatile;
extern crate x86_64;
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;
#[macro_use] // print!
@ -66,7 +60,7 @@ mod console;
#[allow(dead_code)]
#[cfg(target_arch = "x86_64")]
#[path = "arch/x86_64/mod.rs"]
mod arch;
pub mod arch;
#[cfg(target_arch = "riscv32")]
#[path = "arch/riscv32/mod.rs"]