コード例 #1
0
ファイル: CPU.cs プロジェクト: bmatt468/GDBStub
 /// <summary>
 /// executes the decoded instruction
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="flags"></param>
 /// <returns></returns> 
 public bool[] Execute(Instruction cmd, bool[] flags)
 {            
     if (cmd.checkCond(flags))
     {
         for (int i = 0; i < _reg.Length; ++i)
         {
             //Console.WriteLine("Reg " + i + " = " + Convert.ToString(_reg[i].ReadWord(0),16));
         }
         cmd.Run(ref _reg, ref _ram);
         for (int i = 0; i < _reg.Length; ++i)
         {
             //Console.WriteLine("Reg " + i + " = " + Convert.ToString(_reg[i].ReadWord(0), 16));
         }
         if (flags[0] != cmd.N || flags[1] != cmd.Z || flags[2] != cmd.C || flags[3] != cmd.F)
         {
             flags[0] = cmd.N;
             flags[1] = cmd.Z;
             flags[2] = cmd.C;
             flags[3] = cmd.F;
             return flags;
         }                
     }
     return null;
 }
コード例 #2
0
ファイル: instruction.cs プロジェクト: bmatt468/GDBStub
        /// <summary>
        /// Decode the instruction
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        public static Instruction DecodeInstruction(Memory command)
        {
            Instruction i = new Instruction();
            uint type = 0;
            // get type            
            type = (uint)((command.ReadByte(3) & 0x0c) >> 2);
            //Console.WriteLine(Convert.ToString(command.ReadWord(0),2));
            switch (type)
            {                
                case 0:
                    // Data Processing  (00X)
                    if ((0x012FFF10 & command.ReadWord(0)) == 0x012FFF10)
                    {
                        i = new Branch();
                    }
                    else
                    {
                        i = new DataProcessing();
                    }                    
                    break;
                case 1:
                    // Load / Store (01X)
                    if (command.TestFlag(0, 24) || !command.TestFlag(0, 21))
                    {
                        i = new LoadStore();
                    }
                    break;
                case 2:
                    // Load / Store Multiple (100)
                    if (!command.TestFlag(0, 25))
                    {
                        //load store multiple
                        i = new LoadStoreMultiple();
                    }
                    // Branch Instruction (101)
                    else
                    {
                        if (command.TestFlag(0, 27) && !command.TestFlag(0, 26) && command.TestFlag(0, 25))
                        {
                            Logger.Instance.lastInstructionWasBranch = true;
                            i = new Branch();
                        }
                    }
                    break;
                case 3:
                    //11
                    //Coprocessor
                    if (command.TestFlag(0, 26) && command.TestFlag(0, 25))
                    {
                        //interupt
                    }
                    break;
                default:
                    break;
            }

            i.ParseCommand(command);
            // get condition
            i.Cond = (uint)command.ReadByte(3) >> 4;
            // get type
            i.Type = (uint)((command.ReadByte(3) & 0x0c) >> 2);
            //
            i.initialBytes = (uint)command.ReadWord(0);
            // source
            i.Rn = (uint)((command.ReadWord(0) & 0x000F0000) >> 16);
            // destination
            i.Rd = (uint)((command.ReadWord(0) & 0x0000F000) >> 12);
            return i;
        }