예제 #1
0
        public PacketInterceptionPythonEngine(IRadio radio, string script = null, OptionalReadFilePath filename = null)
        {
            if ((script == null && filename == null) || (script != null && filename != null))
            {
                throw new ConstructionException("Parameters `script` and `filename` cannot be both set or both unset.");
            }

            this.radio    = radio;
            this.script   = script;
            this.filename = filename;
            machine       = radio.GetMachine();

            InnerInit();

            Hook = packet =>
            {
                Scope.SetVariable("packet", packet);
                Execute(code, error =>
                {
                    this.radio.Log(LogLevel.Error, "Python runtime error: {0}", 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);
            };
        }
예제 #3
0
        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}");
                });
            };
        }