コード例 #1
0
ファイル: SVDDummyDevice.cs プロジェクト: rasomc/emul8
        public SVDDummyDevice(string path, SystemBus parent)
        {
            this.parent    = parent;
            readRegisters  = new Dictionary <long, Register>();
            writeRegisters = new Dictionary <long, Register>();
            Stream possibleGzip;

            using (possibleGzip = File.OpenRead(path))
            {
                if (possibleGzip.ReadByte() == 0x1F && possibleGzip.ReadByte() == 0x8B) // gzip header
                {
                    parent.Log(LogLevel.Info, "Detected gzipped file, ungzipping.");
                    possibleGzip.Close();
                    possibleGzip = new GZipStream(File.OpenRead(path), CompressionMode.Decompress);
                    path         = TemporaryFilesManager.Instance.GetTemporaryFile();
                    using (var extractedFile = File.OpenWrite(path))
                    {
                        possibleGzip.CopyTo(extractedFile);
                    }
                    parent.Log(LogLevel.Info, "Successfully ungzipped.");
                }
            }
            try
            {
                var document   = XDocument.Load(path);
                var deviceNode = document.Elements().First(x => x.Name == "device");
                FillRegisters(deviceNode);
                parent.Log(LogLevel.Info, "Loaded SVD: {0}", deviceNode.Descendants().First(x => x.Name == "description").Value);
            }
            catch (XmlException e)
            {
                throw new RecoverableException(string.Format("Given SVD file could not be processed due to an exception: {0}.", e.Message));
            }
        }
コード例 #2
0
ファイル: SVDParser.cs プロジェクト: vainamon/emul8
        public SVDParser(string path, SystemBus parent)
        {
            currentSystemBus = parent;
            XDocument document;
            Stream    possibleGzip;

            try
            {
                using (possibleGzip = File.OpenRead(path))
                {
                    if (possibleGzip.ReadByte() == 0x1F && possibleGzip.ReadByte() == 0x8B) // gzip header
                    {
                        parent.Log(LogLevel.Info, "Detected gzipped file, ungzipping.");
                        possibleGzip.Close();
                        possibleGzip = new GZipStream(File.OpenRead(path), CompressionMode.Decompress);
                        path         = TemporaryFilesManager.Instance.GetTemporaryFile();
                        using (var extractedFile = File.OpenWrite(path))
                        {
                            possibleGzip.CopyTo(extractedFile);
                        }
                        parent.Log(LogLevel.Info, "Successfully ungzipped.");
                    }
                }
                document = XDocument.Load(path);
            }
            catch (Exception ex)
            {
                if (ex is FileNotFoundException || ex is DirectoryNotFoundException || ex is PathTooLongException)
                {
                    throw new RecoverableException($"File '{path}' does not exist.");
                }
                else if (ex is UnauthorizedAccessException)
                {
                    throw new RecoverableException($"File '{path}' cannot be loaded due to insufficient permissions.");
                }
                else if (ex is IOException)
                {
                    throw new RecoverableException($"An I/O error occurred while opening the file '{path}'.");
                }
                else if (ex is XmlException)
                {
                    throw new RecoverableException($"Given SVD file could not be loaded due to an exception: {ex.Message}.");
                }
                throw;
            }
            var deviceNode = document.Elements().FirstOrDefault(x => x.Name == "device");

            if (deviceNode == null)
            {
                throw new RecoverableException($"There is no <device> element in the file '{path}'.");
            }
            var device = new SVDDevice(deviceNode, this);

            registerDictionary = new Dictionary <long, SVDRegister>();
            foreach (var register in device.Peripherals.SelectMany(x => x.Registers))
            {
                AppendRegisterToDictionary(register);
            }
            parent.Log(LogLevel.Info, "Loaded SVD: {0}. Name: {1}. Description: {2}.", path, device.Name, device.Description);
        }
コード例 #3
0
        public static void Redirect(this SystemBus sysbus, long from, long to, long size)
        {
            var redirector = new Redirector(sysbus.Machine, to);
            var rangePoint = new BusRangeRegistration(from.By(size));

            sysbus.Register(redirector, rangePoint);
        }
コード例 #4
0
 internal PeripheralCollection(SystemBus sysbus)
 {
     this.sysbus = sysbus;
     blocks      = new Block[0];
     shortBlocks = new Dictionary <long, Block>();
     sync        = new object();
     InvalidateLastBlock();
 }