public ReadLoggingWrapper(IBusPeripheral peripheral, Func <long, T> originalMethod) : base(peripheral, originalMethod) { mapper = new RegisterMapper(peripheral.GetType()); machine = peripheral.GetMachine(); needsByteSwapForDisplay = !peripheral.IsHostEndian(); }
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"); }); } }
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")); }); } }
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); }
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); }
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(); }
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())); }
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")); }); } }
public void ClearHookBeforePeripheralWrite <T>(IBusPeripheral peripheral) { SetHookBeforePeripheralWrite <T>(peripheral, null); }
public void ClearHookAfterPeripheralRead <T>(IBusPeripheral peripheral) { SetHookAfterPeripheralRead <T>(peripheral, null); }
public WriteLoggingWrapper(IBusPeripheral peripheral, Action <long, T> originalMethod) : base(peripheral, originalMethod, null, null) { mapper = new RegisterMapper(peripheral.GetType()); machine = peripheral.GetMachine(); }
public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range) { sysbus.Register(peripheral, new BusRangeRegistration(range)); }
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; }
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); }
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); }
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); }
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); }
protected HookWrapper(IBusPeripheral peripheral, Type type, Range? subrange) { Peripheral = peripheral; Name = type.Name; Subrange = subrange; }
protected HookWrapper(IBusPeripheral peripheral, Type type, Range?subrange) { Peripheral = peripheral; Name = type.Name; Subrange = subrange; }
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); }
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(); } }