/// <summary> /// Acquires the lock for the MMU then executes its write to functionality /// --> Make async if MMU lock /// </summary> /// <returns>True if the memory was written</returns> static void WriteToMemory(int allocationStartAddress) { Driver._MMULock.Wait(); var allProgramData = ReadFromDisk; for (int i = 0; i < allProgramData.Length; i++) { MMU.WriteWord(allocationStartAddress + i, currentPointer, allProgramData[i]); } Driver._MMULock.Release(); }
/// <summary> /// Does an IO instruction through the DMA /// </summary> /// <param name="readOrWrite">True for read, false for write</param> /// <param name="callingCPU">The CPU that's calling the DMA</param> /// <param name="reg1">Reg1 in the instructions</param> /// <param name="secondLocation">The second location to be called, whether it be register or address</param> /// <param name="reg2ORAddress">True for reg2, false for address as second location</param> /// <returns></returns> public static async Task IOExecution(bool readOrWrite, CPU callingCPU, int reg1, int secondLocation, bool reg2ORAddress) { /* * Start the timer */ // Metrics.Stop(callingCPU.ActiveProgram); if (readOrWrite) // ==> Read { Task thread = Task.Factory.StartNew(() => { blocker().GetAwaiter().GetResult(); if (reg2ORAddress) { callingCPU.Registers[reg1] = callingCPU.Registers[secondLocation]; } else { callingCPU.Registers[reg1] = MMU.ReadWord(secondLocation, callingCPU.ActiveProgram); } unlocker().GetAwaiter().GetResult(); }); thread.Wait(); } else // ==> Write { Task thread = Task.Factory.StartNew(() => { blocker().GetAwaiter().GetResult(); if (reg2ORAddress) { callingCPU.Registers[secondLocation] = callingCPU.Registers[reg1]; } else { MMU.WriteWord(secondLocation, callingCPU.ActiveProgram, callingCPU.Registers[reg1]); } unlocker().GetAwaiter().GetResult(); }); thread.Wait(); } /* * Stop the waiting timer */ // Metrics.Stop(callingCPU.ActiveProgram); // Increment the IO count for the pcb callingCPU.ActiveProgram.IOOperationCount++; }