Esempio n. 1
0
        public List <JAL_CALL> findJALsInFunction(uint RAMFunc, uint RAMtoROM)
        {
            List <JAL_CALL>    calls = new List <JAL_CALL>();
            List <Instruction> inst = ReadFunction(RAMFunc, RAMtoROM);
            uint a0 = 0, a1 = 0, a2 = 0, a3 = 0;
            uint jal_addr    = 0;
            bool addNextTime = false;

            for (int i = 0; i < inst.Count; i++)
            {
                bool addJAL = addNextTime;
                switch (inst[i].opCode)
                {
                case OPCODE.LUI:
                    if (inst[i].gp_dest == GP_REGISTER.A0)
                    {
                        a0 = (uint)(inst[i].immediate << 16);
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A1)
                    {
                        a1 = (uint)(inst[i].immediate << 16);
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A2)
                    {
                        a2 = (uint)(inst[i].immediate << 16);
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A3)
                    {
                        a3 = (uint)(inst[i].immediate << 16);
                    }
                    break;

                case OPCODE.ADDIU:
                    if (inst[i].gp_dest == GP_REGISTER.A0 && inst[i].gp_1 == GP_REGISTER.A0)
                    {
                        a0 += (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A1 && inst[i].gp_1 == GP_REGISTER.A1)
                    {
                        a1 += (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A2 && inst[i].gp_1 == GP_REGISTER.A2)
                    {
                        a2 += (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A3 && inst[i].gp_1 == GP_REGISTER.A3)
                    {
                        a3 += (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A0 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a0 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A1 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a1 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A2 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a2 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A3 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a3 = (uint)inst[i].immediate;
                    }
                    else
                    {
                        if (inst[i].gp_dest == GP_REGISTER.A0)
                        {
                            a0 = (uint)(inst[i].immediate + gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A1)
                        {
                            a1 = (uint)(inst[i].immediate + gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A2)
                        {
                            a2 = (uint)(inst[i].immediate + gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A3)
                        {
                            a3 = (uint)(inst[i].immediate + gp_register_values[(int)inst[i].gp_1]);
                        }
                    }

                    break;

                case OPCODE.ORI:
                    if (inst[i].gp_dest == GP_REGISTER.A0 && inst[i].gp_1 == GP_REGISTER.A0)
                    {
                        a0 |= (ushort)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A1 && inst[i].gp_1 == GP_REGISTER.A1)
                    {
                        a1 |= (ushort)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A2 && inst[i].gp_1 == GP_REGISTER.A2)
                    {
                        a2 |= (ushort)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A3 && inst[i].gp_1 == GP_REGISTER.A3)
                    {
                        a3 |= (ushort)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A0 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a0 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A1 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a1 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A2 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a2 = (uint)inst[i].immediate;
                    }
                    else if (inst[i].gp_dest == GP_REGISTER.A3 && inst[i].gp_1 == GP_REGISTER.R0)
                    {
                        a3 = (uint)inst[i].immediate;
                    }
                    else
                    {
                        if (inst[i].gp_dest == GP_REGISTER.A0)
                        {
                            uint immediate_unsigned = (uint)inst[i].immediate;
                            a0 = (uint)(immediate_unsigned | gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A1)
                        {
                            uint immediate_unsigned = (uint)inst[i].immediate;
                            a1 = (uint)(immediate_unsigned | gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A2)
                        {
                            uint immediate_unsigned = (uint)inst[i].immediate;
                            a2 = (uint)(immediate_unsigned | gp_register_values[(int)inst[i].gp_1]);
                        }
                        else if (inst[i].gp_dest == GP_REGISTER.A3)
                        {
                            uint immediate_unsigned = (uint)inst[i].immediate;
                            a3 = (uint)(immediate_unsigned | gp_register_values[(int)inst[i].gp_1]);
                        }
                    }
                    break;

                case OPCODE.JAL:
                    jal_addr    = inst[i].jump_to_func;
                    addNextTime = true;
                    break;
                }

                if (addJAL)
                {
                    JAL_CALL newCall = new JAL_CALL();
                    newCall.a0          = a0;
                    newCall.a1          = a1;
                    newCall.a2          = a2;
                    newCall.a3          = a3;
                    newCall.JAL_ADDRESS = jal_addr;
                    calls.Add(newCall);
                    //Console.WriteLine(newCall.ToString());
                    addNextTime = false;
                }
            }

            return(calls);
        }
Esempio n. 2
0
        public void findJALsInFunction(uint RAMFunc, uint RAMtoROM, ref StructList <JAL_CALL> calls)
        {
            calls.Clear();
            StructList <Instruction> inst_list = new StructList <Instruction>();
            Instruction inst = default(Instruction);

            ReadFunction(RAMFunc, RAMtoROM, ref inst_list);
            JAL_CALL jal = default(JAL_CALL);

            bool addNextTime = false;

            while (inst_list.Dequeue(ref inst))
            {
                bool addJAL = addNextTime;
                switch (inst.opCode)
                {
                case OPCODE.LUI:
                    if (inst.gp_dest == GP_REGISTER.A0)
                    {
                        jal.a0 = (uint)(inst.immediate << 16);
                    }
                    else if (inst.gp_dest == GP_REGISTER.A1)
                    {
                        jal.a1 = (uint)(inst.immediate << 16);
                    }
                    else if (inst.gp_dest == GP_REGISTER.A2)
                    {
                        jal.a2 = (uint)(inst.immediate << 16);
                    }
                    else if (inst.gp_dest == GP_REGISTER.A3)
                    {
                        jal.a3 = (uint)(inst.immediate << 16);
                    }
                    break;

                case OPCODE.ADDIU:
                    if (inst.gp_dest == GP_REGISTER.A0 && inst.gp_1 == GP_REGISTER.A0)
                    {
                        jal.a0 += (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A1 && inst.gp_1 == GP_REGISTER.A1)
                    {
                        jal.a1 += (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A2 && inst.gp_1 == GP_REGISTER.A2)
                    {
                        jal.a2 += (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A3 && inst.gp_1 == GP_REGISTER.A3)
                    {
                        jal.a3 += (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A0 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a0 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A1 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a1 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A2 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a2 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A3 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a3 = (uint)inst.immediate;
                    }
                    break;

                case OPCODE.ORI:
                    if (inst.gp_dest == GP_REGISTER.A0 && inst.gp_1 == GP_REGISTER.A0)
                    {
                        jal.a0 |= (ushort)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A1 && inst.gp_1 == GP_REGISTER.A1)
                    {
                        jal.a1 |= (ushort)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A2 && inst.gp_1 == GP_REGISTER.A2)
                    {
                        jal.a2 |= (ushort)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A3 && inst.gp_1 == GP_REGISTER.A3)
                    {
                        jal.a3 |= (ushort)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A0 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a0 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A1 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a1 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A2 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a2 = (uint)inst.immediate;
                    }
                    else if (inst.gp_dest == GP_REGISTER.A3 && inst.gp_1 == GP_REGISTER.R0)
                    {
                        jal.a3 = (uint)inst.immediate;
                    }
                    break;

                case OPCODE.JAL:
                    jal.JAL_ADDRESS = inst.jump_to_func;
                    addNextTime     = true;
                    break;
                }

                if (addJAL)
                {
                    calls.Add(ref jal);
                    //Console.WriteLine(newCall.ToString());
                    addNextTime = false;
                }
            }
        }