diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 93f66ce..3252b85 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -138,7 +138,8 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result th.clone(), None => Err("Current thread is None")? }; - system.get_thread_manager().thread_finish(machine, th); + let code = machine.read_int_register(10); + system.get_thread_manager().thread_finish(machine, th, code); Ok(MachineOk::Ok) }, SC_EXEC => todo!(), diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index fa41a79..ec88c47 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -248,10 +248,10 @@ impl ThreadManager { } /// Finish the execution of the thread and prepare its deallocation - pub fn thread_finish(&mut self, machine: &mut Machine, thread: ThreadRef) { + pub fn thread_finish(&mut self, machine: &mut Machine, thread: ThreadRef, exit_code: i64) { let old_status = machine.interrupt.set_status(InterruptStatus::InterruptOff); assert!(self.g_alive.remove(Rc::clone(&thread))); - self.debug(format!("Finishing thread {}", thread.borrow().get_name())); + self.debug(format!("Finishing thread {} with code {}", thread.borrow().get_name(), exit_code)); // g_objets_addrs->removeObject(self.thread) // a ajouté plus tard for (_, el) in thread.borrow().join_thread.iter().enumerate() { self.ready_to_run(Rc::clone(&el)); diff --git a/test/syscall_tests/Makefile b/test/syscall_tests/Makefile index 79041ed..4c8f4ca 100644 --- a/test/syscall_tests/Makefile +++ b/test/syscall_tests/Makefile @@ -1,4 +1,4 @@ -PROGRAMS = halt.guac prints.guac producteur_consommateur.guac join.guac +PROGRAMS = halt.guac prints.guac producteur_consommateur.guac join.guac matmult.guac TOPDIR = ../.. include $(TOPDIR)/Makefile.rules diff --git a/test/syscall_tests/matmult.c b/test/syscall_tests/matmult.c new file mode 100644 index 0000000..cd62424 --- /dev/null +++ b/test/syscall_tests/matmult.c @@ -0,0 +1,60 @@ +/* matmult.c + * Test program to do matrix multiplication on large arrays. + * + * Intended to stress virtual memory system. + * + * Ideally, we could read the matrices off of the file system, + * and store the result back to the file system! + * + * ----------------------------------------------------- + * This file is part of the Nachos-RiscV distribution + * Copyright (c) 2022 University of Rennes 1. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details + * (see see ). + * ----------------------------------------------------- + + */ + +#include "userlib/syscall.h" + +#define Dim 10 /* sum total of the arrays doesn't fit in + * physical memory + */ + +/* The matrices to be filled-in and multiplied */ +int A[Dim][Dim]; +int B[Dim][Dim]; +int C[Dim][Dim]; + +int +main() +{ + int i, j, k; + + Write("Start matmult\n",14,CONSOLE_OUTPUT); + + for (i = 0; i < Dim; i++) /* first initialize the matrices */ + for (j = 0; j < Dim; j++) { + A[i][j] = i; + B[i][j] = j; + C[i][j] = 0; + } + + for (i = 0; i < Dim; i++) /* then multiply them together */ + for (j = 0; j < Dim; j++) + for (k = 0; k < Dim; k++) + C[i][j] += A[i][k] * B[k][j]; + + + Exit(C[Dim-1][Dim-1]); /* and then we're done */ + + return 0; +}