From c17e1ab26f4d6cdb6064241c85ff84029b3e0747 Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 9 Jan 2016 15:35:32 -0700 Subject: Add secondary cache syscalls --- src/system.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/system.rs b/src/system.rs index faadb13..b8b928e 100644 --- a/src/system.rs +++ b/src/system.rs @@ -1,4 +1,6 @@ use std; +use std::cell::RefCell; +use std::rc::Rc; use rustv::isa; use rustv::memory::SharedMemory; @@ -6,20 +8,27 @@ use rustv::register_file::RegisterFile; use rustv::syscall; use rustv::trap::Trap; +use shareable_cache::ShareableCache; + pub struct SyscallHandler<'a> { memory: SharedMemory<'a>, + caches: Vec>>>, } impl<'a> SyscallHandler<'a> { - pub fn new(memory: SharedMemory<'a>) -> SyscallHandler<'a> { + pub fn new(memory: SharedMemory<'a>, + caches: Vec>>>) + -> SyscallHandler<'a> { SyscallHandler { - memory: memory + memory: memory, + caches: caches, } } } impl<'a> SyscallHandler<'a> { - fn print(&mut self, registers: &mut RegisterFile) -> Option { + fn print(&mut self, core_id: usize, + registers: &mut RegisterFile) -> Option { let mut base = registers.read_word(isa::Register::X11); let mut string = vec![]; @@ -44,19 +53,31 @@ impl<'a> SyscallHandler<'a> { println!("Error printing string: not valid UTF-8: {:?}", result); } None + } + fn enable_secondary(&mut self, core_id: usize, + registers: &mut RegisterFile) -> Option { + self.caches[core_id].borrow_mut().enable_secondary(); + None + } + + fn disable_secondary(&mut self, core_id: usize, + registers: &mut RegisterFile) -> Option { + self.caches[core_id].borrow_mut().disable_secondary(); + None } } impl<'a> syscall::SyscallHandler for SyscallHandler<'a> { // TODO: is trap really appropriate here? - fn syscall(&mut self, registers: &mut RegisterFile) -> Option { + fn syscall(&mut self, core_id: usize, + registers: &mut RegisterFile) -> Option { let syscall_number = registers.read_word(isa::Register::X10); match syscall_number { - 22 => { - self.print(registers) - } + 22 => self.print(core_id, registers), + 23 => self.enable_secondary(core_id, registers), + 24 => self.disable_secondary(core_id, registers), _ => { // TODO: some sort of error reporting -- cgit v1.2.3