Exemple #1
0
        public void FlashMCU(ReadFilePath path)
        {
            var address = 0;
            var data    = new byte[256 + 5];

            data[0] = ((byte)Commands.WriteMemory << 6) | (byte)MemoryBanks.MCUFlash;

            var bytes = File.ReadAllBytes(path);
            var left  = bytes.Length;

            while (left > 0)
            {
                var batchSize = Math.Min(left, 256);
                Array.Copy(bytes, address, data, 5, batchSize);
                data[1] = (byte)(address >> 24);
                data[2] = (byte)(address >> 16);
                data[3] = (byte)(address >> 8);
                data[4] = (byte)address;
                IssueCommand(data);

                currentSlave.Read(0);
                // The software needs time to handle the data
                Thread.Sleep(200);

                address += 256;
                left    -= batchSize;
            }
        }
        public void Load(ReadFilePath path)
        {
            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var deserializationResult = serializer.TryDeserialize <string>(stream, out var version);
                if (deserializationResult != DeserializationResult.OK)
                {
                    throw new RecoverableException($"There was an error when deserializing the emulation: {deserializationResult}\n Underlying exception: {serializer.LastException.Message}\n{serializer.LastException.StackTrace}");
                }

                deserializationResult = serializer.TryDeserialize <Emulation>(stream, out var emulation);
                if (deserializationResult != DeserializationResult.OK)
                {
                    throw new RecoverableException($"There was an error when deserializing the emulation: {deserializationResult}\n Underlying exception: {serializer.LastException.Message}\n{serializer.LastException.StackTrace}");
                }

                CurrentEmulation = emulation;
                CurrentEmulation.BlobManager.Load(stream);

                if (version != VersionString)
                {
                    Logger.Log(LogLevel.Warning, "Version of deserialized emulation ({0}) does not match current one {1}. Things may go awry!", version, VersionString);
                }
            }
        }
        public bool TryExecutePythonScript(ReadFilePath fileName, ICommandInteraction writer)
        {
            var script = Engine.CreateScriptSourceFromFile(fileName);

            ExecutePythonScriptInner(script, writer);
            return(true);
        }
Exemple #4
0
        public static void EnableRiscvOpcodesCounting(this BaseRiscV cpu, ReadFilePath file)
        {
            foreach (var x in RiscVOpcodesParser.Parse(file))
            {
                cpu.InstallOpcodeCounterPattern(x.Item1, x.Item2);
            }

            cpu.EnableOpcodesCounting = true;
        }
Exemple #5
0
        public static void PyDevFromFile(this Machine @this, ReadFilePath path, ulong address, int size, bool initable = false, string name = null, ulong offset = 0)
        {
            var pyDev = new PythonPeripheral(size, initable, filename: path);

            @this.SystemBus.Register(pyDev, new BusPointRegistration(address, offset));
            if (!string.IsNullOrEmpty(name))
            {
                @this.SetLocalName(pyDev, name);
            }
        }
Exemple #6
0
 public void LoadVMem(ReadFilePath filename)
 {
     try
     {
         var reader = new VmemReader(filename);
         lock (memoryLock)
         {
             foreach (var pair in reader.GetIndexDataPairs())
             {
                 // VmemReader returns 4 byte values, but the two first contains only the ECC which we don't need
                 var offset = pair.Item1 * 2;
                 underlyingMemory.WriteWord(offset, (ushort)pair.Item2);
             }
         }
     }
     catch (Exception e)
     {
         throw new RecoverableException($"Exception while loading file {filename}: {e.Message}");
     }
 }
Exemple #7
0
        public void LoadFile(ReadFilePath path)
        {
            var sampleSize = (int)(sampleWidthBits / 8);

            lock (samples)
            {
                using (var br = new BinaryReader(File.Open(path, FileMode.Open)))
                {
                    while (true)
                    {
                        var bytes = br.ReadBytes(sampleSize);
                        if (bytes.Length == 0)
                        {
                            break;
                        }

                        var sample = BitHelper.ToUInt32(bytes, 0, bytes.Length, false);
                        samples.Enqueue(sample);
                    }
                }
            }
        }
        public static void SetPacketHookFromFile(this WirelessMedium medium, IRadio radio, ReadFilePath filename)
        {
            var runner = new PacketInterceptionPythonEngine(radio, filename: filename);

            medium.AttachHookToRadio(radio, runner.Hook);
        }