From 03ac599c7feeea7385abfa6832f99bc1152cfe2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Tue, 14 Mar 2023 14:49:45 +0100 Subject: [PATCH 1/3] Removed lifetime tag from Semaphore implementation --- src/kernel/synch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/synch.rs b/src/kernel/synch.rs index d4e349c..ec1ba90 100644 --- a/src/kernel/synch.rs +++ b/src/kernel/synch.rs @@ -18,7 +18,7 @@ pub struct Semaphore { } -impl<'t> Semaphore { +impl Semaphore { /// Decrement the value, and wait if it becomes < 0. Checking the /// value and decrementing must be done atomically, so we From d1935e939905acd77213aebab0f91489a387fed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Tue, 14 Mar 2023 14:49:58 +0100 Subject: [PATCH 2/3] Fully documented mem_cmp.rs --- src/simulator/mem_cmp.rs | 74 +++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 306c084..c955daf 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -1,49 +1,41 @@ +///! FILE.TXT FORMAT Representing machine memory memory +/// - PC +/// - SP +/// - Section_1 +/// - Section_2 +/// - ... +/// - Section_n +/// +/// Each section is divided in 3 parts, on two lines of text +/// addr SPACE len +/// content + use std::{fs, io::{BufRead, BufReader, Lines, Error}}; use crate::Machine; -const MEM_SIZE : usize = 4096; - -/* FORMAT FICHIER.TXT Représentant la mémoire apres éxecution d'un prog -* PC -* SP -* Section_1 -* Section_2 -* ... -* ... -* Section_n -*/ - -/* Chaque section se divise en 3 parties, sur 2 lignes de texte -* addr ESPACE len -* content -*/ - -//content est une suite hexadécimale - /// File section pub struct SectionFormat{ + /// Memory address of the section addr: String, + /// The size of data in bytes len: String, + /// The data itself in Hexadecimal format content: String, } /// # Memory section /// /// Representation of a section of memory from BurritOS or NachOS -/// -/// - addr: Memory address of the section -/// - len: The size of data in bytes -/// - content: the data itself pub struct Section{ - addr: usize, // adresse dans la mémoire - len: usize, // nombre d'octets de la donnée à addr - content: Vec, // la donnée en question + /// Memory address of the section + addr: usize, + /// The size of data in bytes + len: usize, + /// The data itself in Hexadecimal format + content: Vec } -/* -* Voir si instanciation d'une structure deplace les valeurs "locales" à la méthode from, je sais plus .... - */ -impl Section{ +impl Section { /// Creates a memory section from a SectionFormat fn from(section: &SectionFormat) -> Section { @@ -61,12 +53,17 @@ impl Section{ } } -/* -* Representation de l'etat de la mémoire (apres execution.... a confirmer), sous forme de sections -*/ -pub struct MemChecker{ + +/// # Representation of the state of machine memory +/// +/// Could represent memory at any point in time, before, during, or after execution. +/// The memory is split into sections. +pub struct MemChecker { + /// Value of the program counter pc: usize, + /// Value of the stack pointer sp: usize, + /// Sections sections: Vec
, } @@ -181,20 +178,13 @@ impl MemChecker{ } - /* - * FOR DEBUG - */ + /// For debug fn compare_print_m_c_machine(m_c: &MemChecker, machine: &mut Machine){ - MemChecker::print_mem_checker(m_c); - for section in m_c.sections.iter() { - print!("\n\n"); - println!("Content addr : {}", section.addr); println!("Content len (number of bytes) : {}", section.len); - for i in 0..section.len { println!("mem[{}] = {}", section.addr + i, machine.main_memory[section.addr + i]); } From 4ee0c11c565194aae050ed72e57306632e0fc31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Tue, 14 Mar 2023 15:16:40 +0100 Subject: [PATCH 3/3] A few documentation updates --- src/kernel/synch.rs | 8 ++++---- src/kernel/thread_manager.rs | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/kernel/synch.rs b/src/kernel/synch.rs index e7b9ac2..88f5d69 100644 --- a/src/kernel/synch.rs +++ b/src/kernel/synch.rs @@ -43,12 +43,12 @@ impl Semaphore { machine.interrupt.set_status(old_status); } - /// Increment semaphore value, waking up a waiting thread if any. - /// As with P(), this operation must be atomic, so we need to disable - /// interrupts. + /// Increment semaphore value, waking up a waiting thread if any. + /// As with P(), this operation must be atomic, so we need to disable + /// interrupts. /// /// scheduler::ready_to_run() assumes that interrupts - /// are disabled when it is called. + /// are disabled when it is called. /// /// ### Parameters /// - **machine** the machine where the threads are executed diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index b4d5632..0c65b85 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -6,17 +6,26 @@ use super::{scheduler::Scheduler, thread::Thread, system::System, mgerror::Error pub const SIMULATORSTACKSIZE: usize = 32 * 1024; +/// # Thread manager +/// +/// An instance of this struct is responsible for managing threads on behalf of the system #[derive(PartialEq)] pub struct ThreadManager { + /// Current running thread pub g_current_thread: Option>>, + /// The thread to be destroyed next pub g_thread_to_be_destroyed: Option>>, + /// The list of alive threads pub g_alive: List>>, + /// The thread scheduler pub g_scheduler: Scheduler, + /// The system owning the thread manager pub system: Option>> } impl ThreadManager { + /// Thread manager constructor pub fn new() -> Self { Self { g_current_thread: Option::None,