public void Read32Test1() { // The initial value for all register is zero! foreach (var curValue in registerNames) { var initValue = register.ReadUnsignedInt(curValue); Assert.AreEqual(initValue, 0); } }
public void ReadTest1() { var enums = new RegisterName[] { RegisterName.x0, RegisterName.x1, RegisterName.x2, RegisterName.x3, RegisterName.x4, RegisterName.x5, RegisterName.x6, RegisterName.x7, RegisterName.x8, RegisterName.x9, RegisterName.x10, RegisterName.x11, RegisterName.x12, RegisterName.x13, RegisterName.x14, RegisterName.x15, RegisterName.x16, RegisterName.x17, RegisterName.x18, RegisterName.x19, RegisterName.x20, RegisterName.x21, RegisterName.x22, RegisterName.x23, RegisterName.x24, RegisterName.x25, RegisterName.x26, RegisterName.x27, RegisterName.x28, RegisterName.x29, RegisterName.x30, RegisterName.x31, RegisterName.x32, }; // The initial value for all register is zero! foreach (var curValue in enums) { var initValue = register.ReadUnsignedInt(curValue); Assert.AreEqual(initValue, 0); } }
public string GetMemoryState() { var sb = new StringBuilder(); uint offset = 127; uint curIndex; sb.AppendLine("Memory in Little Endian:"); int blockCount; int blockIndex; if (architecture == Architecture.Rv64I) { blockCount = 1; blockIndex = 0; var globalPointer64 = register.ReadUnsignedLong(3); for (curIndex = 0; curIndex < offset; curIndex += 8) { var pos = Convert.ToUInt64(globalPointer64 + curIndex); var data = memory.GetDoubleWord(globalPointer64 + curIndex); if (blockIndex == 0) { sb.AppendFormat("{0:X16} : ", pos); } sb.AppendFormat("{0} ", BitConverter.ToString(data.ToArray(), 0)); if (blockIndex < blockCount) { blockIndex++; } else { sb.AppendLine(); blockIndex = 0; } } } else { blockCount = 3; blockIndex = 0; var globalPointer32 = register.ReadUnsignedInt(3); for (curIndex = 0; curIndex < offset; curIndex += 4) { var pos = globalPointer32 + curIndex; var data = memory.GetWord(globalPointer32 + curIndex); if (blockIndex == 0) { sb.AppendFormat("{0:X8} : ", pos); } sb.AppendFormat("{0} ", BitConverter.ToString(data.ToArray(), 0)); if (blockIndex < blockCount) { blockIndex++; } else { sb.AppendLine(); blockIndex = 0; } } } return(sb.ToString());; }
/// <summary> /// The generic fetch method for all hart implementations /// </summary> private void Fetch() { // Done! // Fetch the first instruction and run the loop. Get the first 2 Bytes from the Base Address aka PC var pc = register.ReadUnsignedInt(register.ProgramCounter); var instructionCoding = memory.GetHalfWord(pc); Logger.Info("Instruction {ins:X} fetched", BitConverter.ToString(instructionCoding.ToArray())); while (ContinueIfValid(instructionCoding)) { // Loop for the commands var instruction = instructionDecoder.Decode(instructionCoding); if (rvMode) { var isCustom = (instructionCoding.First() & 0x7F) == 0x00; if (isCustom) { Logger.Info("Processing RV custom command."); var customCoding = memory.GetWord(pc); var isHalt = customCoding.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x00 }); if (isHalt) { // Stop the simulation! break; } var payload = typeDecoder.DecodeCustom(instruction, customCoding); var rvOpcode = new RvOpcode(memory, register, environment); var inc = rvOpcode.Execute(instruction, payload); if (inc) { // Go to the next instruction... register.NextInstruction(4); } } else { // Handle instruction as usual.. HandleCompliantMode(pc, instructionCoding, instruction); } } else { HandleCompliantMode(pc, instructionCoding, instruction); } // Stop the instruction fetch if an error occured or the state is stopped var currentState = environment.GetCurrentState(); if (currentState == State.FatalError || currentState == State.Stopped) { break; } // Done. Next run. pc = register.ReadUnsignedInt(register.ProgramCounter); instructionCoding = memory.GetHalfWord(pc); Logger.Info("Instruction {ins:X} fetched", BitConverter.ToString(instructionCoding.ToArray())); } if (environment.GetCurrentState() == State.FatalError) { Console.Error.WriteLine("# FATAL ERROR occured : " + environment.GetStateDescription()); } if (environment.GetCurrentState() == State.Stopped) { Console.Out.WriteLine("# Hart Stopped"); } environment.NotifyStopped(); }