示例#1
0
        private ExecutionUnit GetExecutionUnit()
        {
            dynamic       window      = GetMainWindowInstance();
            ExecutionUnit currentUnit = window.ActiveUnit;

            return(currentUnit);
        }
示例#2
0
 /// <summary>
 /// This function returns from the interrupt routine
 /// </summary>
 /// <param name="returnAddress">the logical address to return back to</param>
 public override void Return(int returnAddress)
 {
     handled = true;
     if (handler.HandlerFunction != null)
     {
         handler.HandlerFunction();
     }
     else
     {
         SimulatorProgram prog     = GetCurrentProgram();
         ExecutionUnit    unit     = GetExecutionUnit();
         dynamic          procunit = GetCurrentProcessExecutionUnit();
         if (procunit == null)
         {
             unit = GetExecutionUnit();
             unit.LogicalAddress = returnAddress;
             unit.CurrentIndex   = returnAddress / 4;
             unit.Done           = false;
             unit.Stop           = false;
         }
         else
         {
             procunit.LogicalAddress = returnAddress;
             procunit.CurrentIndex   = returnAddress / 4;
             procunit.Stop           = false;
             procunit.Done           = false;
         }
     }
 }
示例#3
0
        /// <summary>
        ///     Tells the module to begin x86 execution at the specified Entry Point
        /// </summary>
        /// <param name="entryPoint">Entry Point where execution will begin</param>
        /// <param name="channelNumber">Channel Number calling for execution</param>
        /// <param name="simulateCallFar">Are we simulating a CALL FAR? This is usually when we're calling a local function pointer</param>
        /// <param name="bypassSetState">Should we bypass setting a startup state? This is true for execution of things like Text Variable processing</param>
        /// <param name="initialStackValues">Initial Stack Values to be pushed to the stack prior to executing (simulating parameters on a method call)</param>
        /// <param name="initialStackPointer">
        ///     Initial Stack Pointer Value. Because EU's share the same memory space, including stack space, we need to sometimes need to manually decrement the
        ///     stack pointer enough to where the stack on the nested call won't overlap with the stack on the parent caller.
        /// </param>
        /// <returns></returns>
        public CpuRegisters Execute(FarPtr entryPoint, ushort channelNumber, bool simulateCallFar = false, bool bypassSetState = false,
                                    Queue <ushort> initialStackValues = null, ushort initialStackPointer = CpuCore.STACK_BASE)
        {
            //Set the proper DLL making the call based on the Segment
            for (ushort i = 0; i < ModuleDlls.Count; i++)
            {
                var dll = ModuleDlls[i];
                if (entryPoint.Segment >= dll.SegmentOffset &&
                    entryPoint.Segment <= (dll.SegmentOffset + dll.File.SegmentTable.Count))
                {
                    foreach (var(_, value) in ExportedModuleDictionary)
                    {
                        ((ExportedModuleBase)value).ModuleDll = i;
                    }
                }
            }

            //Try to dequeue an execution unit, if one doesn't exist, create a new one
            if (!ExecutionUnits.TryDequeue(out var executionUnit))
            {
                _logger.Debug($"({ModuleIdentifier}) Exhausted execution Units, creating additional");
                executionUnit = new ExecutionUnit(Memory, _clock, ExportedModuleDictionary, _logger, ModulePath);
            }

            var resultRegisters = executionUnit.Execute(entryPoint, channelNumber, simulateCallFar, bypassSetState, initialStackValues, initialStackPointer);

            ExecutionUnits.Enqueue(executionUnit);
            return(resultRegisters);
        }
示例#4
0
        //Should be Synchronized
        public StatusCode AddExecutionUnitIfAvailable(ExecutionUnit unit, bool ReturnIfErrorFound)
        {
            object[] args = new object[1];
            if (ReturnIfErrorFound && ErrorList.Count > 0)
            {
                args[0] = ErrorList.Count;
                return
                    (new CommonStatusCode(CommonStatusCode.QUEUE_ERROR_FOUND, args, Config, ApplicationId));
            }
            ThreadPoolItem nextItem = null;

            while ((nextItem = AvailablePoolItem) == null)
            {
                System.Threading.Thread.Sleep(0);
            }
            if (ReturnIfErrorFound && ErrorList.Count > 0)
            {
                args[0] = ErrorList.Count;
                return
                    (new CommonStatusCode(CommonStatusCode.QUEUE_ERROR_FOUND, args, Config, ApplicationId));
            }
            StatusCode retVal = AddExecutionUnit(unit);

            return(retVal);
        }
示例#5
0
 public FlowDecision()
 {
     InitializeComponent();
     ExecutionUnit          = new ExecutionUnit(this, this.lblDecisionName.Text);
     lblDecisionName.Click += new EventHandler(lblDecisionName_Click);
     this.Click            += new EventHandler(lblDecisionName_Click);
 }
示例#6
0
        public void ExecutionUnitTest1()
        {
            ExecutionUnit unit = new ExecutionUnit(prog, 10, 10);

            Assert.IsInstanceOfType(unit, typeof(ExecutionUnit));
            Assert.AreEqual(unit.CurrentIndex, 10);
        }
示例#7
0
        private void ErrorProc(StatusCode retVal)
        {
            StatusCode retVal2 = StatusCode.SUCCEED_STATUS;

            try
            {
                retVal2 = ExecutionUnit.OnError();
            }
            catch (Exception ex)
            {
                retVal2 =
                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
            }
            try
            {
                Manager.RegisterError(retVal);
            }
            catch (Exception ex)
            {
                new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_MANAGER_ERROR, ex, Manager.Config, Manager.ApplicationId);
            }

            if (retVal2 != StatusCode.SUCCEED_STATUS)
            {
                try
                {
                    Manager.RegisterError(retVal2);
                }
                catch (Exception ex)
                {
                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_MANAGER_ERROR, ex, Manager.Config, Manager.ApplicationId);
                }
            }
        }
 public FlowStop()
 {
     InitializeComponent();
     this.button3.Left = (this.Width - this.button3.Width) / 2;
     ExecutionUnit     = new ExecutionUnit(this, this.label1.Text);
     label1.Click     += new EventHandler(lblDecisionName_Click);
     this.Click       += new EventHandler(lblDecisionName_Click);
 }
示例#9
0
 //Should be Synchronized
 public StatusCode AddExecutionUnit(ExecutionUnit unit)
 {
     lock (ExecutionUnitQueue)
     {
         ExecutionUnitQueue.Enqueue(unit);
     }
     UnitAdded?.Invoke(this, new ThreadPoolItemEventArg(unit));
     return(StatusCode.SUCCEED_STATUS);
 }
 public FlowProcessing()
 {
     InitializeComponent();
     this.button1.Left             = (this.Width - this.button1.Width) / 2;
     this.button3.Left             = (this.Width - this.button3.Width) / 2;
     ExecutionUnit                 = new ExecutionUnit(this, lblProcessingName.Text);
     this.lblProcessingName.Click += new EventHandler(lblDecisionName_Click);
     this.Click += new EventHandler(lblDecisionName_Click);
 }
示例#11
0
        public void Execute_IncrementProgramCounter()
        {
            // Arrange
            var executor = new ExecutionUnit(_defaultStack, null, _stopDecoder, null);
            var pc = executor.ProgramCounter;

            // Act
            executor.Execute();

            // Assert
            executor.ProgramCounter.Should().Be(pc + 1);
        }
示例#12
0
        public void Execute_InvalidInstructionThrowsException()
        {
            // Arrange
            var decoder = new Mock<IDecoder>();
            decoder.Setup(m => m.Decode(It.IsAny<UInt64>()))
                .Returns(new Instruction { Type = (InstructionType)12345 });

            // Act
            var executor = new ExecutionUnit(_defaultStack, null, decoder.Object, null);

            // Assert
            executor.Invoking(e => e.Execute()).ShouldThrow<InvalidOperationException>();
        }
示例#13
0
        /// <summary>
        ///     Tells the module to begin x86 execution at the specified Entry Point
        /// </summary>
        /// <param name="entryPoint">Entry Point where execution will begin</param>
        /// <param name="channelNumber">Channel Number calling for execution</param>
        /// <param name="simulateCallFar">Are we simulating a CALL FAR? This is usually when we're calling a local function pointer</param>
        /// <param name="bypassSetState">Should we bypass setting a startup state? This is true for execution of things like Text Variable processing</param>
        /// <param name="initialStackValues">Initial Stack Values to be pushed to the stack prior to executing (simulating parameters on a method call)</param>
        /// <param name="initialStackPointer">
        ///     Initial Stack Pointer Value. Because EU's share the same memory space, including stack space, we need to sometimes need to manually decrement the
        ///     stack pointer enough to where the stack on the nested call won't overlap with the stack on the parent caller.
        /// </param>
        /// <returns></returns>
        public CpuRegisters Execute(IntPtr16 entryPoint, ushort channelNumber, bool simulateCallFar = false, bool bypassSetState = false,
                                    Queue <ushort> initialStackValues = null, ushort initialStackPointer = CpuCore.STACK_BASE)
        {
            //Try to dequeue an execution unit, if one doesn't exist, create a new one
            if (!ExecutionUnits.TryDequeue(out var executionUnit))
            {
                _logger.Warn($"{ModuleIdentifier} exhausted execution Units, creating additional");
                executionUnit = new ExecutionUnit(Memory, ExportedModuleDictionary);
            }

            var resultRegisters = executionUnit.Execute(entryPoint, channelNumber, simulateCallFar, bypassSetState, initialStackValues, initialStackPointer);

            ExecutionUnits.Enqueue(executionUnit);
            return(resultRegisters);
        }
示例#14
0
        public CommandExecuteUnit CreateCommandExecuteUnit(DbConnection connection, ExecutionUnit executionUnit,
                                                           ConnectionModeEnum connectionMode)
        {
            var shardingParameters = executionUnit.GetSqlUnit().GetParameterContext().GetDbParameters().Select(o => (ShardingParameter)o).ToList();
            var dbCommand          = connection.CreateCommand();

            //TODO取消手动执行改成replay
            dbCommand.CommandText = executionUnit.GetSqlUnit().GetSql();
            foreach (var shardingParameter in shardingParameters)
            {
                var dbParameter = dbCommand.CreateParameter();
                dbParameter.ParameterName = shardingParameter.ParameterName;
                dbParameter.Value         = shardingParameter.Value;
                dbCommand.Parameters.Add(dbParameter);
            }
            return(new CommandExecuteUnit(executionUnit, dbCommand, connectionMode));
        }
        /**
         * To make sure SkyWalking will be available at the next release of ShardingSphere,
         * a new plugin should be provided to SkyWalking project if this API changed.
         *
         * @see <a href="https://github.com/apache/skywalking/blob/master/docs/en/guides/Java-Plugin-Development-Guide.md#user-content-plugin-development-guide">Plugin Development Guide</a>
         *
         * @param statementExecuteUnit statement execute unit
         * @param isTrunkThread is trunk thread
         * @param dataMap data map
         * @return result
         * @throws SQLException SQL exception
         */
        private T Execute0(CommandExecuteUnit commandExecuteUnit, bool isTrunkThread, IDictionary <string, object> dataMap)
        {
            ExecutorExceptionHandler.SetExceptionThrow(isExceptionThrown);
            IDataSourceMetaData dataSourceMetaData = GetDataSourceMetaData(commandExecuteUnit.Command);
            var hookManager = SqlExecutionHookManager.GetInstance();

            try
            {
                ExecutionUnit executionUnit = commandExecuteUnit.ExecutionUnit;
                hookManager.Start(executionUnit.GetDataSourceName(), executionUnit.GetSqlUnit().GetSql(), executionUnit.GetSqlUnit().GetParameterContext(), dataSourceMetaData, isTrunkThread, dataMap);
                T result = OnSqlExecute(executionUnit.GetSqlUnit().GetSql(), commandExecuteUnit.Command, commandExecuteUnit.ConnectionMode);
                hookManager.FinishSuccess();
                return(result);
            }
            catch (Exception ex)
            {
                hookManager.FinishFailure(ex);
                ExecutorExceptionHandler.HandleException(ex);
                return(default);
示例#16
0
        private void assignExecutionUnit()
        {
            ThreadPoolItem pool_item = null;

            lock (this)
            {
                if (ExecutionUnitQueue.Count > 0)
                {
                    pool_item = AvailablePoolItem;
                    if (pool_item != null)
                    {
                        lock (pool_item)
                        {
                            if (pool_item.ExecutionUnit == null && pool_item.IsAvailable)
                            {
                                lock (ExecutionUnitQueue)
                                {
                                    ExecutionUnit targetUnit = ExecutionUnitQueue.Dequeue();
                                    if (targetUnit != null)
                                    {
                                        pool_item.ExecutionUnit = targetUnit;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (pool_item != null && pool_item.Status == ThreadPoolItem.PoolItemStatus.UnitAttached)
            {
                lock (queueInvokeRequest)
                    queueInvokeRequest.Enqueue(pool_item);
                resetEvent.Set();
            }
            else
            {
                isTransitioning = false;
            }
        }
示例#17
0
#pragma warning disable IDE1006 // Naming Styles
        static void Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            Oscillator.InitClock();
            Oscillator.Tick += on_tick;
            RegisterSet      regs = new RegisterSet();
            BusInterfaceUnit biu  = new BusInterfaceUnit(regs);

            biu.SetMemory(0, 0b11000111);
            biu.SetMemory(1, 0b00000110);
            biu.SetMemory(2, 0x00);
            biu.SetMemory(3, 0x10);
            biu.SetMemory(4, 0x30);
            biu.SetMemory(5, 0x40);


            biu.WatchTicks();
            ExecutionUnit test = new ExecutionUnit(regs, biu);


            while (ticks < 40)
            {
            }
        }
示例#18
0
 public PlayerCommand(ExecutionUnit executionUnit)
 {
     this.executionUnit = executionUnit;
 }
 private bool Equals(ExecutionUnit other)
 {
     return(_dataSourceName == other._dataSourceName && Equals(_sqlUnit, other._sqlUnit));
 }
示例#20
0
        internal void ExecThreadItem()
        {
            StatusCode     retVal         = StatusCode.SUCCEED_STATUS;
            PoolItemStatus current_status = Status;

            while (current_status == PoolItemStatus.Active || current_status == PoolItemStatus.UnitAttached)
            {
                //System.Threading.Thread.Sleep(0);
                isReadyForEvent = true;
                auto_event.WaitOne();
                isReadyForEvent = false;
                if (ExecutionUnit != null)
                {
                    retVal = StatusCode.SUCCEED_STATUS;
                    ThreadPoolItemEventArg eventArg = new ThreadPoolItemEventArg(ExecutionUnit);

                    Status = PoolItemStatus.Running;
                    //new CommonStatusCode(CommonStatusCode.ITEM_STARTED, arg, Manager.Config, Manager.ApplicationId);
                    if (UnitStarted != null)
                    {
                        UnitStarted(this, eventArg);
                    }
                    try
                    {
                        retVal = ExecutionUnit.OnStart();
                    }
                    catch (Exception ex)
                    {
                        retVal =
                            new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                    }

                    if (retVal != StatusCode.SUCCEED_STATUS)
                    {
                        ErrorProc(retVal);
                    }
                    else
                    {
                        try
                        {
                            retVal = ExecutionUnit.OnExec();
                        }
                        catch (Exception ex)
                        {
                            retVal =
                                new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                        }
                        if (retVal != StatusCode.SUCCEED_STATUS)
                        {
                            ErrorProc(retVal);
                        }
                        else
                        {
                            try
                            {
                                retVal = ExecutionUnit.OnEnd();
                            }
                            catch (Exception ex)
                            {
                                retVal =
                                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                            }
                            if (retVal != StatusCode.SUCCEED_STATUS)
                            {
                                ErrorProc(retVal);
                            }
                        }
                    }
                    //new CommonStatusCode(CommonStatusCode.ITEM_FINISHED, arg, Manager.Config, Manager.ApplicationId);
                    ExecutionUnit = null;
                    Status        = PoolItemStatus.Active;

                    if (UnitFinished != null)
                    {
                        UnitFinished(this, eventArg);
                    }
                }
                else
                {
                    //object[] args= new object[2];
                    //args[0] = ItemId;
                    //args[1] = current_status;
                    //new CommonStatusCode(CommonStatusCode.ITEM_TRIGGERED_WITH_INVALID_STATUS, args, Manager.Config, Manager.ApplicationId);
                }
                current_status = Status;
                System.Threading.Thread.Sleep(0);
            }
        }
示例#21
0
        public void ExecutionUnitTest()
        {
            ExecutionUnit unit = new ExecutionUnit(prog, 10);

            Assert.IsInstanceOfType(unit, typeof(ExecutionUnit));
        }
示例#22
0
 internal ThreadPoolItemEventArg(ExecutionUnit unit)
 {
     Unit = unit;
 }