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.CPU;
10 using Antmicro.Renode.Core;
11 using Antmicro.Renode.Utilities;
12 
13 namespace Antmicro.Renode.Hooks
14 {
15     public static class CpuHooksExtensions
16     {
AddHook(this ICPUWithHooks cpu, [AutoParameter]Machine m, ulong addr, string pythonScript)17         public static void AddHook(this ICPUWithHooks cpu, [AutoParameter]Machine m, ulong addr, string pythonScript)
18         {
19             var engine = new BlockPythonEngine(m, cpu, pythonScript);
20             cpu.AddHook(addr, engine.Hook);
21         }
22 
AddHookAtWfiStateChange(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)23         public static void AddHookAtWfiStateChange(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)
24         {
25             var engine = new WFIPythonEngine(m, cpu, pythonScript);
26             cpu.AddHookAtWfiStateChange(engine.HookWithWfiEnterExit);
27         }
28 
AddHookAtInterruptBegin(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)29         public static void AddHookAtInterruptBegin(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)
30         {
31             var engine = new InterruptPythonEngine(m, cpu, pythonScript);
32             cpu.AddHookAtInterruptBegin(engine.HookWithExceptionIndex);
33         }
34 
AddHookAtInterruptEnd(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)35         public static void AddHookAtInterruptEnd(this ICPUWithHooks cpu, [AutoParameter]Machine m, string pythonScript)
36         {
37             var engine = new InterruptPythonEngine(m, cpu, pythonScript);
38             cpu.AddHookAtInterruptEnd(engine.HookWithExceptionIndex);
39         }
40     }
41 }
42 
43