From 7b038cdc2474daf22a0c0e7712a8542c952015e2 Mon Sep 17 00:00:00 2001 From: Stephen Marz Date: Thu, 12 Mar 2020 13:55:11 -0400 Subject: [PATCH] Right now, we return a pointer by usize. This is not good programming in Rust. Instead, the scheduler needs to be modified to return a process structure's reference. Then, we can extract the fields and then switch. However, this will require us to have to change how the PROCESS_LIST works. Since it uses move constructs, we cannot move a process out of it when we replace the process list. --- risc_v/ch9/src/sched.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/risc_v/ch9/src/sched.rs b/risc_v/ch9/src/sched.rs index 055596d..d852db8 100755 --- a/risc_v/ch9/src/sched.rs +++ b/risc_v/ch9/src/sched.rs @@ -6,7 +6,7 @@ use crate::{cpu::{build_satp, SatpMode}, process::{ProcessState, PROCESS_LIST}}; -pub fn schedule() -> (usize, usize, usize) { +pub fn schedule() -> (usize, usize) { unsafe { if let Some(mut pl) = PROCESS_LIST.take() { pl.rotate_left(1); @@ -19,7 +19,6 @@ pub fn schedule() -> (usize, usize, usize) { ProcessState::Running => { frame_addr = prc.get_frame_address(); - mepc = prc.get_program_counter(); satp = prc.get_table_address(); pid = prc.get_pid() as usize; }, @@ -37,7 +36,6 @@ pub fn schedule() -> (usize, usize, usize) { // processes. if satp != 0 { return (frame_addr, - mepc, build_satp( SatpMode::Sv39, pid, @@ -45,10 +43,10 @@ pub fn schedule() -> (usize, usize, usize) { )); } else { - return (frame_addr, mepc, 0); + return (frame_addr, 0); } } } } - (0, 0, 0) + (0, 0) }