Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
buhe committed Oct 9, 2021
1 parent cdf607e commit 5ea4345
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ clean:
test: env
@echo Platform: $(BOARD)
@cd ../user && make build
@cargo test --no-run
$(eval override KERNEL_ELF := $(shell cargo test --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]"))
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $(KERNEL_BIN)
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)
Expand Down
4 changes: 2 additions & 2 deletions os/src/mmu/memory_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ bitflags! {
}
}

#[allow(unused)]
#[test_case]
pub fn remap_test() {
let mut kernel_space = KERNEL_SPACE.lock();
let kernel_space = KERNEL_SPACE.lock();
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
Expand Down
1 change: 0 additions & 1 deletion os/src/mmu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod page_table;
pub use address::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
use address::{StepByOne, VPNRange};
pub use frame_allocator::{frame_alloc, FrameTracker};
pub use memory_set::remap_test;
pub use memory_set::{MapPermission, MemorySet, KERNEL_SPACE};
pub use page_table::{translated_byte_buffer, PageTableEntry};
use page_table::{PTEFlags, PageTable};
Expand Down
8 changes: 4 additions & 4 deletions os/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ impl AppManagerInner {
}

unsafe fn load_app(&mut self) {
println!("preload app");
// clear app area
let app_src = core::slice::from_raw_parts(
self.app_start[0] as *const u8,
self.app_start[1] - self.app_start[0],
);
println!("loaded app");
// 入口点是从 elf 加载的
let (memory_set, user_sp, entry_point) = MemorySet::from_elf(&app_src);
self.token = memory_set.token();
println!("loaded elf");
// 通过查表, 从虚拟页获得实际的物理页
self.trap_cx_ppn = memory_set
.translate(VirtAddr::from(TRAP_CONTEXT).into())
Expand All @@ -57,7 +54,6 @@ impl AppManagerInner {
kernel_stack_top,
trap_handler as usize,
);
println!("loaded TRAP context");
}
}

Expand Down Expand Up @@ -98,4 +94,8 @@ pub fn run() -> ! {

pub fn current_user_token() -> usize {
APP_MANAGER.inner.borrow().token
}

pub fn current_trap_cx() -> &'static mut TrapContext {
APP_MANAGER.inner.borrow().trap_cx_ppn.get_mut()
}
5 changes: 3 additions & 2 deletions os/src/trap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use riscv::register::{
};
pub use trap_ctx::TrapContext;

use crate::{config::{TRAMPOLINE, TRAP_CONTEXT}, scall_sbi::syscall, task::current_user_token};
use crate::{config::{TRAMPOLINE, TRAP_CONTEXT}, scall_sbi::syscall, task::{current_trap_cx, current_user_token}};

mod trap_ctx;
global_asm!(include_str!("trap.asm"));
Expand Down Expand Up @@ -56,10 +56,11 @@ pub fn trap_from_kernel() -> ! {
}

#[no_mangle]
pub fn trap_handler(cx: &mut TrapContext) -> ! {
pub fn trap_handler() -> ! {
set_kernel_trap_entry();
let scause = scause::read();
let stval = stval::read();
let cx = current_trap_cx();
match scause.cause() {
Trap::Exception(Exception::UserEnvCall) => {
cx.sepc += 4;
Expand Down
10 changes: 5 additions & 5 deletions os/src/trap/trap_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ impl TrapContext {
sstatus.set_spp(SPP::User);
let mut cx = Self {
x: [0; 32],
sstatus,
sepc: entry,
kernel_satp,
kernel_sp,
trap_handler,
sstatus,//33
sepc: entry,//34
kernel_satp,//35
kernel_sp,//36
trap_handler,//37
};
cx.set_sp(sp);
cx
Expand Down

0 comments on commit 5ea4345

Please sign in to comment.