1 //
2 // Copyright (c) 2010-2022 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System;
8 using Antmicro.Renode.Peripherals.CPU;
9 
10 namespace Antmicro.Renode.Peripherals.Bus
11 {
BusHookDelegate(ICpuSupportingGdb cpu, ulong address, SysbusAccessWidth access, ulong value)12     public delegate void BusHookDelegate(ICpuSupportingGdb cpu, ulong address, SysbusAccessWidth access, ulong value);
13 
14     public class BusHookHandler
15     {
BusHookHandler(BusHookDelegate action, SysbusAccessWidth width)16         public BusHookHandler(BusHookDelegate action, SysbusAccessWidth width)
17         {
18             this.action = action;
19             this.width = width;
20             Enabled = true;
21         }
22 
Invoke(ICpuSupportingGdb cpu, ulong currentAddress, SysbusAccessWidth currentWidth, ulong value = 0)23         public void Invoke(ICpuSupportingGdb cpu, ulong currentAddress, SysbusAccessWidth currentWidth, ulong value = 0)
24         {
25             if((currentWidth & width) != 0)
26             {
27                 action(cpu, currentAddress, currentWidth, value);
28             }
29         }
30 
ContainsAction(BusHookDelegate actionToTest)31         public bool ContainsAction(BusHookDelegate actionToTest)
32         {
33             return action == actionToTest;
34         }
35 
36         public bool Enabled { get; set; }
37 
38         private readonly BusHookDelegate action;
39         private readonly SysbusAccessWidth width;
40     }
41 }
42 
43