1 // 2 // Copyright (c) 2010-2023 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 using Antmicro.Renode.Peripherals.Bus; 10 using Antmicro.Renode.Core; 11 12 using Range = Antmicro.Renode.Core.Range; 13 14 namespace Antmicro.Renode.Hooks 15 { 16 public static class IBusControllerHooksExtensions 17 { SetHookAfterPeripheralRead(this IBusController sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)18 public static void SetHookAfterPeripheralRead(this IBusController sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null) 19 { 20 var runner = new BusPeripheralsHooksPythonEngine(sysbus, peripheral, pythonScript); 21 sysbus.SetHookAfterPeripheralRead<ulong>(peripheral, runner.ReadHook, subrange); 22 sysbus.SetHookAfterPeripheralRead<uint>(peripheral, (readValue, offset) => (uint)runner.ReadHook(readValue, offset), subrange); 23 sysbus.SetHookAfterPeripheralRead<ushort>(peripheral, (readValue, offset) => (ushort)runner.ReadHook(readValue, offset), subrange); 24 sysbus.SetHookAfterPeripheralRead<byte>(peripheral, (readValue, offset) => (byte)runner.ReadHook(readValue, offset), subrange); 25 } 26 SetHookBeforePeripheralWrite(this IBusController sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)27 public static void SetHookBeforePeripheralWrite(this IBusController sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null) 28 { 29 var runner = new BusPeripheralsHooksPythonEngine(sysbus, peripheral, null, pythonScript); 30 sysbus.SetHookBeforePeripheralWrite<ulong>(peripheral, runner.WriteHook, subrange); 31 sysbus.SetHookBeforePeripheralWrite<uint>(peripheral, (valueToWrite, offset) => (uint)runner.WriteHook(valueToWrite, offset), subrange); 32 sysbus.SetHookBeforePeripheralWrite<ushort>(peripheral, (valueToWrite, offset) => (ushort)runner.WriteHook(valueToWrite, offset), subrange); 33 sysbus.SetHookBeforePeripheralWrite<byte>(peripheral, (valueToWrite, offset) => (byte)runner.WriteHook(valueToWrite, offset), subrange); 34 } 35 AddWatchpointHook(this IBusController sysbus, ulong address, SysbusAccessWidth width, Access access, string pythonScript)36 public static void AddWatchpointHook(this IBusController sysbus, ulong address, SysbusAccessWidth width, Access access, string pythonScript) 37 { 38 var engine = new WatchpointHookPythonEngine(sysbus, pythonScript); 39 sysbus.AddWatchpointHook(address, width, access, engine.Hook); 40 } 41 } 42 } 43 44