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 using Antmicro.Renode.Core;
10 using Antmicro.Renode.Utilities;
11 
12 namespace Antmicro.Renode.Hooks
13 {
14     public static class RiscVCpuHooksExtensions
15     {
RegisterCSRHandlerFromString(this BaseRiscV cpu, ulong csr, string pythonScript, bool initable = false)16         public static void RegisterCSRHandlerFromString(this BaseRiscV cpu, ulong csr, string pythonScript, bool initable = false)
17         {
18             var engine = new RiscVCsrPythonEngine(cpu, csr, initable, script: pythonScript);
19             cpu.RegisterCSR(csr, engine.CsrReadHook, engine.CsrWriteHook);
20         }
21 
RegisterCSRHandlerFromFile(this BaseRiscV cpu, ulong csr, string path, bool initable = false)22         public static void RegisterCSRHandlerFromFile(this BaseRiscV cpu, ulong csr, string path, bool initable = false)
23         {
24             var engine = new RiscVCsrPythonEngine(cpu, csr, initable, path: path);
25             cpu.RegisterCSR(csr, engine.CsrReadHook, engine.CsrWriteHook);
26         }
27 
InstallCustomInstructionHandlerFromString(this BaseRiscV cpu, string pattern, string pythonScript)28         public static void InstallCustomInstructionHandlerFromString(this BaseRiscV cpu, string pattern, string pythonScript)
29         {
30             var engine = new RiscVInstructionPythonEngine(cpu, pattern, script: pythonScript);
31             cpu.InstallCustomInstruction(pattern, engine.Hook);
32         }
33 
InstallCustomInstructionHandlerFromFile(this BaseRiscV cpu, string pattern, string path)34         public static void InstallCustomInstructionHandlerFromFile(this BaseRiscV cpu, string pattern, string path)
35         {
36             var engine = new RiscVInstructionPythonEngine(cpu, pattern, path: path);
37             cpu.InstallCustomInstruction(pattern, engine.Hook);
38         }
39     }
40 }
41 
42