public ReadLoggingWrapper(IBusPeripheral peripheral, Func <long, T> originalMethod) :
     base(peripheral, originalMethod)
 {
     mapper  = new RegisterMapper(peripheral.GetType());
     machine = peripheral.GetMachine();
     needsByteSwapForDisplay = !peripheral.IsHostEndian();
 }
Ejemplo n.º 2
0
 public void VisitAccessMethods(IBusPeripheral peripheral, Func <PeripheralAccessMethods, PeripheralAccessMethods> onPam)
 {
     lock (sync)
     {
         blocks = blocks.Select(block =>
         {
             if (block.Peripheral.Peripheral != peripheral)
             {
                 return(block);
             }
             block.AccessMethods = onPam(block.AccessMethods);
             return(block);
         }).ToArray();
         shortBlocks = shortBlocks.Select(dEntry =>
         {
             if (dEntry.Value.Peripheral.Peripheral != peripheral)
             {
                 return(dEntry);
             }
             var block           = dEntry.Value;
             block.AccessMethods = onPam(block.AccessMethods);
             return(new KeyValuePair <long, Block>(dEntry.Key, block));
         }).ToDictionary(x => x.Key, x => x.Value);
         InvalidateLastBlock();
     }
 }
        public BusPeripheralsHooksPythonEngine(SystemBus sysbus, IBusPeripheral peripheral, string readScript = null, string writeScript = null)
        {       
            Peripheral = peripheral;
            Sysbus = sysbus;
            ReadScript = readScript;
            WriteScript = writeScript;

            InnerInit();

            if (WriteScript != null)
            {
                WriteHook = new Func<uint, long, uint>((valueToWrite, offset) =>
                    {
                        Scope.SetVariable("value", valueToWrite);
                        Scope.SetVariable("offset", offset);
                        WriteSource.Value.Execute(Scope);
                        return (uint)Scope.GetVariable("value");
                    });
            }

            if (ReadScript != null)
            {
                ReadHook = new Func<uint, long, uint>((readValue, offset) =>
                    {
                        Scope.SetVariable("value", readValue);
                        Scope.SetVariable("offset", offset);
                        ReadSource.Value.Execute(Scope);
                        return (uint)Scope.GetVariable("value");
                    });
            }
        }
Ejemplo n.º 4
0
 public static void SetHookBeforeWrite(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)
 {
     var runner = new BusHooksPythonEngine(sysbus, peripheral, null, pythonScript);
     sysbus.SetHookBeforeWrite<uint>(peripheral, runner.WriteHook, subrange);
     sysbus.SetHookBeforeWrite<ushort>(peripheral, (valueToWrite, offset) => (ushort)runner.WriteHook(valueToWrite, offset), subrange);
     sysbus.SetHookBeforeWrite<byte>(peripheral, (valueToWrite, offset) => (byte)runner.WriteHook(valueToWrite, offset), subrange);
 }
        public BusPeripheralsHooksPythonEngine(SystemBus sysbus, IBusPeripheral peripheral, string readScript = null, string writeScript = null)
        {
            Peripheral  = peripheral;
            Sysbus      = sysbus;
            ReadScript  = readScript;
            WriteScript = writeScript;

            InnerInit();

            if (WriteScript != null)
            {
                WriteHook = new Func <uint, long, uint>((valueToWrite, offset) =>
                {
                    Scope.SetVariable("value", valueToWrite);
                    Scope.SetVariable("offset", offset);
                    WriteSource.Value.Execute(Scope);
                    return((uint)Scope.GetVariable("value"));
                });
            }

            if (ReadScript != null)
            {
                ReadHook = new Func <uint, long, uint>((readValue, offset) =>
                {
                    Scope.SetVariable("value", readValue);
                    Scope.SetVariable("offset", offset);
                    ReadSource.Value.Execute(Scope);
                    return((uint)Scope.GetVariable("value"));
                });
            }
        }
Ejemplo n.º 6
0
 public static void SetHookAfterRead(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)
 {
     var runner = new BusHooksPythonEngine(sysbus, peripheral, pythonScript);
     sysbus.SetHookAfterRead<uint>(peripheral, runner.ReadHook, subrange);
     sysbus.SetHookAfterRead<ushort>(peripheral, (readValue, offset) => (ushort)runner.ReadHook(readValue, offset), subrange);
     sysbus.SetHookAfterRead<byte>(peripheral, (readValue, offset) => (byte)runner.ReadHook(readValue, offset), subrange);
 }
Ejemplo n.º 7
0
        public static void SetHookAfterPeripheralRead(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range?subrange = null)
        {
            var runner = new BusPeripheralsHooksPythonEngine(sysbus, peripheral, pythonScript);

            sysbus.SetHookAfterPeripheralRead <uint>(peripheral, runner.ReadHook, subrange);
            sysbus.SetHookAfterPeripheralRead <ushort>(peripheral, (readValue, offset) => (ushort)runner.ReadHook(readValue, offset), subrange);
            sysbus.SetHookAfterPeripheralRead <byte>(peripheral, (readValue, offset) => (byte)runner.ReadHook(readValue, offset), subrange);
        }
Ejemplo n.º 8
0
        public static void SetHookBeforePeripheralWrite(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range?subrange = null)
        {
            var runner = new BusPeripheralsHooksPythonEngine(sysbus, peripheral, null, pythonScript);

            sysbus.SetHookBeforePeripheralWrite <uint>(peripheral, runner.WriteHook, subrange);
            sysbus.SetHookBeforePeripheralWrite <ushort>(peripheral, (valueToWrite, offset) => (ushort)runner.WriteHook(valueToWrite, offset), subrange);
            sysbus.SetHookBeforePeripheralWrite <byte>(peripheral, (valueToWrite, offset) => (byte)runner.WriteHook(valueToWrite, offset), subrange);
        }
        public LiteX_Framebuffer(Machine machine, PixelFormat format, IBusPeripheral memory) : base(machine)
        {
            this.memory  = memory;
            this.machine = machine;
            this.format  = format;

            RegistersCollection = new DoubleWordRegisterCollection(this);
            DefineRegisters();
        }
Ejemplo n.º 10
0
        public void SetHookBeforePeripheralWrite <T>(IBusPeripheral peripheral, Func <T, long, T> hook, Range?subrange = null)
        {
            if (!machine.IsRegistered(peripheral))
            {
                throw new RecoverableException(string.Format("Cannot set hook on peripheral {0}, it is not registered.", peripheral));
            }
            var type = typeof(T);

            if (type == typeof(byte))
            {
                peripherals.VisitAccessMethods(peripheral, pam =>
                {
                    if (pam.WriteByte.Target is WriteHookWrapper <byte> )
                    {
                        pam.WriteByte = new BusAccess.ByteWriteMethod(((WriteHookWrapper <byte>)pam.WriteByte.Target).OriginalMethod);
                    }
                    if (hook != null)
                    {
                        pam.WriteByte = new BusAccess.ByteWriteMethod(new WriteHookWrapper <byte>(peripheral, new Action <long, byte>(pam.WriteByte), (Func <byte, long, byte>)(object) hook, subrange).Write);
                    }
                    return(pam);
                });
                return;
            }
            if (type == typeof(ushort))
            {
                peripherals.VisitAccessMethods(peripheral, pam =>
                {
                    if (pam.WriteWord.Target is WriteHookWrapper <ushort> )
                    {
                        pam.WriteWord = new BusAccess.WordWriteMethod(((WriteHookWrapper <ushort>)pam.WriteWord.Target).OriginalMethod);
                    }
                    if (hook != null)
                    {
                        pam.WriteWord = new BusAccess.WordWriteMethod(new WriteHookWrapper <ushort>(peripheral, new Action <long, ushort>(pam.WriteWord), (Func <ushort, long, ushort>)(object) hook, subrange).Write);
                    }
                    return(pam);
                });
                return;
            }
            if (type == typeof(uint))
            {
                peripherals.VisitAccessMethods(peripheral, pam =>
                {
                    if (pam.WriteDoubleWord.Target is WriteHookWrapper <uint> )
                    {
                        pam.WriteDoubleWord = new BusAccess.DoubleWordWriteMethod(((WriteHookWrapper <uint>)pam.WriteDoubleWord.Target).OriginalMethod);
                    }
                    if (hook != null)
                    {
                        pam.WriteDoubleWord = new BusAccess.DoubleWordWriteMethod(new WriteHookWrapper <uint>(peripheral, new Action <long, uint>(pam.WriteDoubleWord), (Func <uint, long, uint>)(object) hook, subrange).Write);
                    }
                    return(pam);
                });
                return;
            }
        }
        public LiteX_Framebuffer_CSR32(Machine machine, PixelFormat format, IBusPeripheral memory, uint offset = 0, ushort hres = 0, ushort vres = 0) : base(machine)
        {
            this.memory      = memory;
            this.resetOffset = offset;
            this.resetHres   = hres;
            this.resetVres   = vres;
            this.machine     = machine;
            this.format      = format;

            DefineDMARegisters();
            DefineVTGRegisters();
        }
        private static void LogNotTranslated(IBusPeripheral peripheral, SysbusAccessWidth operationWidth, long address, uint?value = null)
        {
            var strBldr = new StringBuilder();

            strBldr.AppendFormat("Attempt to {0} {1} from peripheral that doesn't support {1} interface.", value.HasValue ? "write" : "read", operationWidth);
            strBldr.AppendFormat(" Offset 0x{0:X}", address);
            if (value.HasValue)
            {
                strBldr.AppendFormat(", value 0x{0:X}", value.Value);
            }
            strBldr.Append(".");

            peripheral.Log(LogLevel.Warning, peripheral.GetMachine().SystemBus.DecorateWithCPUNameAndPC(strBldr.ToString()));
        }
Ejemplo n.º 13
0
        public BusPeripheralsHooksPythonEngine(SystemBus sysbus, IBusPeripheral peripheral, string readScript = null, string writeScript = null)
        {
            Peripheral  = peripheral;
            Sysbus      = sysbus;
            ReadScript  = readScript;
            WriteScript = writeScript;

            InnerInit();

            if (WriteScript != null)
            {
                WriteHook = new Func <uint, long, uint>((valueToWrite, offset) =>
                {
                    Scope.SetVariable("value", valueToWrite);
                    Scope.SetVariable("offset", offset);
                    Execute(writeCode, error =>
                    {
                        Sysbus.Log(LogLevel.Error, "Python runtime error: {0}", error);
                    });
                    return((uint)Scope.GetVariable("value"));
                });
            }

            if (ReadScript != null)
            {
                ReadHook = new Func <uint, long, uint>((readValue, offset) =>
                {
                    Scope.SetVariable("value", readValue);
                    Scope.SetVariable("offset", offset);
                    Execute(readCode, error =>
                    {
                        Sysbus.Log(LogLevel.Error, "Python runtime error: {0}", error);
                    });
                    return((uint)Scope.GetVariable("value"));
                });
            }
        }
Ejemplo n.º 14
0
 public void ClearHookBeforePeripheralWrite <T>(IBusPeripheral peripheral)
 {
     SetHookBeforePeripheralWrite <T>(peripheral, null);
 }
Ejemplo n.º 15
0
 public void ClearHookAfterPeripheralRead <T>(IBusPeripheral peripheral)
 {
     SetHookAfterPeripheralRead <T>(peripheral, null);
 }
Ejemplo n.º 16
0
 public WriteLoggingWrapper(IBusPeripheral peripheral, Action <long, T> originalMethod) : base(peripheral, originalMethod, null, null)
 {
     mapper  = new RegisterMapper(peripheral.GetType());
     machine = peripheral.GetMachine();
 }
Ejemplo n.º 17
0
		public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range)
		{
			sysbus.Register(peripheral, new BusRangeRegistration(range));
		}
Ejemplo n.º 18
0
 public WriteHookWrapper(IBusPeripheral peripheral, Action <long, T> originalMethod, Func <T, long, T> newMethod = null,
                         Range?subrange = null) : base(peripheral, typeof(T), subrange)
 {
     this.originalMethod = originalMethod;
     this.newMethod      = newMethod;
 }
Ejemplo n.º 19
0
 public static uint ReadDoubleWordNotTranslated(this IBusPeripheral peripheral, long address)
 {
     peripheral.Log(LogLevel.Warning, "Attempt to read dword from peripheral that doesn't support dword interface. Offset 0x{0:X}.", address);
     return(0);
 }
Ejemplo n.º 20
0
 public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range)
 {
     sysbus.Register(peripheral, new BusRangeRegistration(range));
 }
Ejemplo n.º 21
0
 public ReadLoggingWrapper(IBusPeripheral peripheral, Func <long, T> originalMethod) :
     base(peripheral, originalMethod)
 {
     mapper  = new RegisterMapper(peripheral.GetType());
     machine = peripheral.GetMachine();
 }
 public static byte ReadByteNotTranslated(this IBusPeripheral peripheral, long address)
 {
     LogNotTranslated(peripheral, SysbusAccessWidth.Byte, address);
     return(0);
 }
Ejemplo n.º 23
0
 public static void WriteDoubleWordNotTranslated(this IBusPeripheral peripheral, long address, uint value)
 {
     peripheral.Log(LogLevel.Warning, "Attempt to write dword to peripheral that doesn't support dword interface. Offset 0x{0:X}, value 0x{1:X}.", address, value);
 }
Ejemplo n.º 24
0
 public static void WriteByteNotTranslated(this IBusPeripheral peripheral, long address, byte value)
 {
     peripheral.Log(LogLevel.Warning, "Attempt to write byte to peripheral that doesn't support byte interface. Offset 0x{0:X}, value 0x{1:X}.", address, value);
 }
Ejemplo n.º 25
0
 protected HookWrapper(IBusPeripheral peripheral, Type type, Range? subrange)
 {
     Peripheral = peripheral;
     Name = type.Name;
     Subrange = subrange;
 }
Ejemplo n.º 26
0
 protected HookWrapper(IBusPeripheral peripheral, Type type, Range?subrange)
 {
     Peripheral = peripheral;
     Name       = type.Name;
     Subrange   = subrange;
 }
Ejemplo n.º 27
0
 public static byte ReadByteNotTranslated(this IBusPeripheral peripheral, long address)
 {
     peripheral.Log(LogLevel.Warning, "Attempt to read byte from peripheral that doesn't support byte interface. Offset 0x{0:X}.", address);
     return(0);
 }
 public static uint ReadDoubleWordNotTranslated(this IBusPeripheral peripheral, long address)
 {
     LogNotTranslated(peripheral, SysbusAccessWidth.DoubleWord, address);
     return(0);
 }
 public static void WriteDoubleWordNotTranslated(this IBusPeripheral peripheral, long address, uint value)
 {
     LogNotTranslated(peripheral, SysbusAccessWidth.DoubleWord, address, value);
 }
 public static void WriteByteNotTranslated(this IBusPeripheral peripheral, long address, byte value)
 {
     LogNotTranslated(peripheral, SysbusAccessWidth.Byte, address, value);
 }
Ejemplo n.º 31
0
 public void VisitAccessMethods(IBusPeripheral peripheral, Func<PeripheralAccessMethods, PeripheralAccessMethods> onPam)
 {
     lock(sync)
     {
         blocks = blocks.Select(block => 
         {
             if(block.Peripheral.Peripheral != peripheral)
             {
                 return block;
             }
             block.AccessMethods = onPam(block.AccessMethods);
             return block;
         }).ToArray();
         shortBlocks = shortBlocks.Select(dEntry =>
         {
             if(dEntry.Value.Peripheral.Peripheral != peripheral)
             {
                 return dEntry;
             }
             var block = dEntry.Value;
             block.AccessMethods = onPam(block.AccessMethods);
             return new KeyValuePair<long, Block>(dEntry.Key, block);
         }).ToDictionary(x => x.Key, x => x.Value);
         InvalidateLastBlock();
     }
 }