public RiscVInstructionPythonEngine(BaseRiscV cpu, string pattern, string script = null, OptionalReadFilePath path = null) { if ((script == null && path == null) || (script != null && path != null)) { throw new ConstructionException("Parameters 'script' and 'path' cannot be both set or both unset"); } this.cpu = cpu; this.pattern = pattern; this.script = script; this.path = path; InnerInit(); Hook = (instr) => { Scope.SetVariable("instruction", instr); Execute(code, error => { this.cpu.Log(LogLevel.Error, "Python runtime error: {0}", error); throw new CpuAbortException($"Python runtime error: {error}"); }); }; }
public RiscVCsrPythonEngine(BaseRiscV cpu, ulong csr, bool initable, string script = null, OptionalReadFilePath path = null) { if ((script == null && path == null) || (script != null && path != null)) { throw new ConstructionException("Parameters 'script' and 'path' cannot be both set or both unset"); } this.cpu = cpu; this.csr = csr; this.script = script; this.path = path; this.initable = initable; InnerInit(); CsrWriteHook = (value) => { TryInit(); request.value = value; request.type = CsrRequest.RequestType.WRITE; Execute(code, error => { this.cpu.Log(LogLevel.Error, "Python runtime error: {0}", error); throw new CpuAbortException($"Python runtime error: {error}"); }); }; CsrReadHook = () => { TryInit(); request.type = CsrRequest.RequestType.READ; Execute(code, error => { this.cpu.Log(LogLevel.Error, "Python runtime error: {0}", error); throw new CpuAbortException($"Python runtime error: {error}"); }); return(request.value); }; }
public void RegisterCPU(BaseRiscV cpu) { var hartId = (int)cpu.HartId; if (cpus.ContainsKey(hartId)) { throw new ConstructionException($"CPU with hart id {hartId} already registered in CLINT."); } if (cpus.ContainsValue(cpu)) { throw new ConstructionException("CPU already registered in CLINT"); } cpus.Add(hartId, cpu); irqs[2 * hartId] = new GPIO(); irqs[2 * hartId + 1] = new GPIO(); var timer = new ComparingTimer(machine.ClockSource, timerFrequency, enabled: true, eventEnabled: true); timer.CompareReached += () => irqs[2 * hartId + 1].Set(true); mTimers.Add(hartId, timer); }
public RiscVInstructionPythonEngine(BaseRiscV cpu, string pattern, string script = null, string path = null) { if ((script == null && path == null) || (script != null && path != null)) { throw new ConstructionException("Parameters 'script' and 'path' cannot be both set or both unset"); } this.cpu = cpu; this.pattern = pattern; this.script = script; this.path = path; InnerInit(); Hook = (instr) => { Scope.SetVariable("instruction", instr); source.Value.Execute(Scope); }; }
public RiscVCsrPythonEngine(BaseRiscV cpu, ulong csr, bool initable, string script = null, string path = null) { if ((script == null && path == null) || (script != null && path != null)) { throw new ConstructionException("Parameters 'script' and 'path' cannot be both set or both unset"); } this.cpu = cpu; this.csr = csr; this.script = script; this.path = path; this.initable = initable; InnerInit(); CsrWriteHook = (value) => { TryInit(); request.value = value; request.type = CsrRequest.RequestType.WRITE; Source.Value.Execute(Scope); }; CsrReadHook = () => { TryInit(); request.type = CsrRequest.RequestType.READ; Source.Value.Execute(Scope); return(request.value); }; }
public static void InstallCustomInstructionHandlerFromFile(this BaseRiscV cpu, string pattern, string path) { var engine = new RiscVInstructionPythonEngine(cpu, pattern, path: path); cpu.InstallCustomInstruction(pattern, engine.Hook); }
public static void InstallCustomInstructionHandlerFromString(this BaseRiscV cpu, string pattern, string pythonScript) { var engine = new RiscVInstructionPythonEngine(cpu, pattern, script: pythonScript); cpu.InstallCustomInstruction(pattern, engine.Hook); }
public static void RegisterCSRHandlerFromFile(this BaseRiscV cpu, ulong csr, string path, bool initable = false) { var engine = new RiscVCsrPythonEngine(cpu, csr, initable, path: path); cpu.RegisterCSR(csr, engine.CsrReadHook, engine.CsrWriteHook); }
public static void RegisterCSRHandlerFromString(this BaseRiscV cpu, ulong csr, string pythonScript, bool initable = false) { var engine = new RiscVCsrPythonEngine(cpu, csr, initable, script: pythonScript); cpu.RegisterCSR(csr, engine.CsrReadHook, engine.CsrWriteHook); }