@@ -2726,6 +2726,9 @@ class MipsArchitecture: public Architecture
27262726 return registers;
27272727 }
27282728
2729+ MipsVersion GetMIPSVersion () {
2730+ return m_version;
2731+ }
27292732};
27302733
27312734class MipsO32CallingConvention : public CallingConvention
@@ -2789,6 +2792,77 @@ class MipsO32CallingConvention: public CallingConvention
27892792 }
27902793};
27912794
2795+ class MipsPS2CallingConvention : public CallingConvention
2796+ {
2797+ public:
2798+ MipsPS2CallingConvention (Architecture* arch): CallingConvention(arch, " ps2" )
2799+ {
2800+ }
2801+ virtual uint32_t GetIntegerReturnValueRegister () override
2802+ {
2803+ return REG_V0;
2804+ }
2805+
2806+ virtual uint32_t GetHighIntegerReturnValueRegister () override
2807+ {
2808+ return REG_V1;
2809+ }
2810+
2811+ virtual vector<uint32_t > GetIntegerArgumentRegisters () override
2812+ {
2813+ return vector<uint32_t >{ REG_A0, REG_A1, REG_A2, REG_A3, REG_T0, REG_T1, REG_T2, REG_T3 };
2814+ }
2815+
2816+ virtual vector<uint32_t > GetFloatArgumentRegisters () override
2817+ {
2818+ return vector<uint32_t >{ FPREG_F12, FPREG_F13, FPREG_F14, FPREG_F15, FPREG_F16, FPREG_F17, FPREG_F18, FPREG_F19 };
2819+ }
2820+
2821+ virtual uint32_t GetFloatReturnValueRegister () override
2822+ {
2823+ return FPREG_F0;
2824+ }
2825+
2826+ virtual bool IsStackReservedForArgumentRegisters () override
2827+ {
2828+ return true ;
2829+ }
2830+
2831+ virtual vector<uint32_t > GetCallerSavedRegisters () override
2832+ {
2833+ return vector<uint32_t > { REG_AT, REG_V0, REG_V1, REG_A0, REG_A1, REG_A2, REG_A3, REG_T0, REG_T1,
2834+ REG_T2, REG_T3, REG_T4, REG_T5, REG_T6, REG_T7, REG_T8, REG_T9 };
2835+ }
2836+
2837+ virtual vector<uint32_t > GetCalleeSavedRegisters () override
2838+ {
2839+ return vector<uint32_t > { REG_S0, REG_S1, REG_S2, REG_S3, REG_S4, REG_S5, REG_S6, REG_S7,
2840+ REG_GP, REG_FP, FPREG_F20, FPREG_F21, FPREG_F22, FPREG_F23, FPREG_F24, FPREG_F25,
2841+ FPREG_F26, FPREG_F27, FPREG_F28, FPREG_F29, FPREG_F30, FPREG_F31 };
2842+ }
2843+
2844+ virtual uint32_t GetGlobalPointerRegister () override
2845+ {
2846+ return REG_GP;
2847+ }
2848+
2849+ virtual vector<uint32_t > GetImplicitlyDefinedRegisters () override
2850+ {
2851+ return vector<uint32_t > { REG_T9 };
2852+ }
2853+
2854+ virtual RegisterValue GetIncomingRegisterValue (uint32_t reg, Function* func) override
2855+ {
2856+ RegisterValue result;
2857+ if (reg == REG_T9)
2858+ {
2859+ result.state = ConstantPointerValue;
2860+ result.value = func->GetStart ();
2861+ }
2862+ return result;
2863+ }
2864+ };
2865+
27922866class MipsN64CallingConvention : public CallingConvention
27932867{
27942868public:
@@ -3336,7 +3410,8 @@ class MipsElfRelocationHandler: public RelocationHandler
33363410 uint32_t inst2 = *(uint32_t *)(cur->relocationDataCache );
33373411 Instruction instruction;
33383412 memset (&instruction, 0 , sizeof (instruction));
3339- if (mips_decompose (&inst2, sizeof (uint32_t ), &instruction, m_version, cur->address , arch->GetEndianness (), DECOMPOSE_FLAGS_PSEUDO_OP))
3413+ MipsArchitecture& march = dynamic_cast <MipsArchitecture&>(*arch);
3414+ if (mips_decompose (&inst2, sizeof (uint32_t ), &instruction, march.GetMIPSVersion (), cur->address , arch->GetEndianness (), DECOMPOSE_FLAGS_PSEUDO_OP))
33403415 break ;
33413416
33423417 int32_t immediate = swap (inst2) & 0xffff ;
@@ -3616,15 +3691,13 @@ extern "C"
36163691 MipsN64CallingConvention* n64LE = new MipsN64CallingConvention (mips64el);
36173692 MipsN64CallingConvention* n64BE = new MipsN64CallingConvention (mips64eb);
36183693 MipsN64CallingConvention* n64BEc = new MipsN64CallingConvention (cnmips64eb);
3694+ MipsPS2CallingConvention* ps2LE = new MipsPS2CallingConvention (r5900l);
3695+ MipsPS2CallingConvention* ps2BE = new MipsPS2CallingConvention (r5900b);
36193696
36203697 mipseb->RegisterCallingConvention (o32BE);
36213698 mipseb->SetDefaultCallingConvention (o32BE);
36223699 mipsel->RegisterCallingConvention (o32LE);
36233700 mipsel->SetDefaultCallingConvention (o32LE);
3624- r5900l->RegisterCallingConvention (o32LE);
3625- r5900l->SetDefaultCallingConvention (o32LE);
3626- r5900b->RegisterCallingConvention (o32BE);
3627- r5900b->SetDefaultCallingConvention (o32BE);
36283701 mips3->RegisterCallingConvention (o32BE);
36293702 mips3->SetDefaultCallingConvention (o32BE);
36303703 mips3el->RegisterCallingConvention (o32LE);
@@ -3635,6 +3708,10 @@ extern "C"
36353708 mips64eb->SetDefaultCallingConvention (n64BE);
36363709 cnmips64eb->RegisterCallingConvention (n64BEc);
36373710 cnmips64eb->SetDefaultCallingConvention (n64BEc);
3711+ r5900l->RegisterCallingConvention (ps2LE);
3712+ r5900l->SetDefaultCallingConvention (ps2LE);
3713+ r5900b->RegisterCallingConvention (ps2BE);
3714+ r5900b->SetDefaultCallingConvention (ps2BE);
36383715
36393716 MipsLinuxSyscallCallingConvention* linuxSyscallBE = new MipsLinuxSyscallCallingConvention (mipseb);
36403717 MipsLinuxSyscallCallingConvention* linuxSyscallLE = new MipsLinuxSyscallCallingConvention (mipsel);
0 commit comments