diff options
| author | 2015-05-15 09:44:39 -0400 | |
|---|---|---|
| committer | 2015-05-15 09:44:39 -0400 | |
| commit | 6abed88092f2791dfbca9ec30376e5f542035d05 (patch) | |
| tree | 26f8f809abb53d54c2629b53ff0a2259afdbd41b /src/core/arm/dyncom | |
| parent | Merge pull request #761 from Subv/resource_limits (diff) | |
| parent | dyncom: Remove duplicate enums/prototypes (diff) | |
| download | yuzu-6abed88092f2791dfbca9ec30376e5f542035d05.tar.gz yuzu-6abed88092f2791dfbca9ec30376e5f542035d05.tar.xz yuzu-6abed88092f2791dfbca9ec30376e5f542035d05.zip | |
Merge pull request #770 from lioncash/dyncom_clean
dyncom: Minor cleanup.
Diffstat (limited to 'src/core/arm/dyncom')
| -rw-r--r-- | src/core/arm/dyncom/arm_dyncom_interpreter.cpp | 407 |
1 files changed, 196 insertions, 211 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp index b79fd1719..034f4d570 100644 --- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp +++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "core/memory.h" | 13 | #include "core/memory.h" |
| 14 | #include "core/hle/svc.h" | 14 | #include "core/hle/svc.h" |
| 15 | #include "core/arm/disassembler/arm_disasm.h" | 15 | #include "core/arm/disassembler/arm_disasm.h" |
| 16 | #include "core/arm/dyncom/arm_dyncom_dec.h" | ||
| 16 | #include "core/arm/dyncom/arm_dyncom_interpreter.h" | 17 | #include "core/arm/dyncom/arm_dyncom_interpreter.h" |
| 17 | #include "core/arm/dyncom/arm_dyncom_thumb.h" | 18 | #include "core/arm/dyncom/arm_dyncom_thumb.h" |
| 18 | #include "core/arm/dyncom/arm_dyncom_run.h" | 19 | #include "core/arm/dyncom/arm_dyncom_run.h" |
| @@ -68,6 +69,67 @@ static void remove_exclusive(ARMul_State* state, ARMword addr){ | |||
| 68 | state->exclusive_tag = 0xFFFFFFFF; | 69 | state->exclusive_tag = 0xFFFFFFFF; |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 72 | static int CondPassed(ARMul_State* cpu, unsigned int cond) { | ||
| 73 | const u32 NFLAG = cpu->NFlag; | ||
| 74 | const u32 ZFLAG = cpu->ZFlag; | ||
| 75 | const u32 CFLAG = cpu->CFlag; | ||
| 76 | const u32 VFLAG = cpu->VFlag; | ||
| 77 | |||
| 78 | int temp = 0; | ||
| 79 | |||
| 80 | switch (cond) { | ||
| 81 | case 0x0: | ||
| 82 | temp = ZFLAG; | ||
| 83 | break; | ||
| 84 | case 0x1: // NE | ||
| 85 | temp = !ZFLAG; | ||
| 86 | break; | ||
| 87 | case 0x2: // CS | ||
| 88 | temp = CFLAG; | ||
| 89 | break; | ||
| 90 | case 0x3: // CC | ||
| 91 | temp = !CFLAG; | ||
| 92 | break; | ||
| 93 | case 0x4: // MI | ||
| 94 | temp = NFLAG; | ||
| 95 | break; | ||
| 96 | case 0x5: // PL | ||
| 97 | temp = !NFLAG; | ||
| 98 | break; | ||
| 99 | case 0x6: // VS | ||
| 100 | temp = VFLAG; | ||
| 101 | break; | ||
| 102 | case 0x7: // VC | ||
| 103 | temp = !VFLAG; | ||
| 104 | break; | ||
| 105 | case 0x8: // HI | ||
| 106 | temp = (CFLAG && !ZFLAG); | ||
| 107 | break; | ||
| 108 | case 0x9: // LS | ||
| 109 | temp = (!CFLAG || ZFLAG); | ||
| 110 | break; | ||
| 111 | case 0xa: // GE | ||
| 112 | temp = ((!NFLAG && !VFLAG) || (NFLAG && VFLAG)); | ||
| 113 | break; | ||
| 114 | case 0xb: // LT | ||
| 115 | temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG)); | ||
| 116 | break; | ||
| 117 | case 0xc: // GT | ||
| 118 | temp = ((!NFLAG && !VFLAG && !ZFLAG) || (NFLAG && VFLAG && !ZFLAG)); | ||
| 119 | break; | ||
| 120 | case 0xd: // LE | ||
| 121 | temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG)) || ZFLAG; | ||
| 122 | break; | ||
| 123 | case 0xe: // AL | ||
| 124 | temp = 1; | ||
| 125 | break; | ||
| 126 | case 0xf: | ||
| 127 | temp = 1; | ||
| 128 | break; | ||
| 129 | } | ||
| 130 | return temp; | ||
| 131 | } | ||
| 132 | |||
| 71 | static unsigned int DPO(Immediate)(ARMul_State* cpu, unsigned int sht_oper) { | 133 | static unsigned int DPO(Immediate)(ARMul_State* cpu, unsigned int sht_oper) { |
| 72 | unsigned int immed_8 = BITS(sht_oper, 0, 7); | 134 | unsigned int immed_8 = BITS(sht_oper, 0, 7); |
| 73 | unsigned int rotate_imm = BITS(sht_oper, 8, 11); | 135 | unsigned int rotate_imm = BITS(sht_oper, 8, 11); |
| @@ -224,14 +286,12 @@ static unsigned int DPO(RotateRightByRegister)(ARMul_State* cpu, unsigned int sh | |||
| 224 | 286 | ||
| 225 | typedef void (*get_addr_fp_t)(ARMul_State *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw); | 287 | typedef void (*get_addr_fp_t)(ARMul_State *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw); |
| 226 | 288 | ||
| 227 | typedef struct _ldst_inst { | 289 | struct ldst_inst { |
| 228 | unsigned int inst; | 290 | unsigned int inst; |
| 229 | get_addr_fp_t get_addr; | 291 | get_addr_fp_t get_addr; |
| 230 | } ldst_inst; | 292 | }; |
| 231 | #define DEBUG_MSG LOG_DEBUG(Core_ARM11, "inst is %x", inst); CITRA_IGNORE_EXIT(0) | 293 | #define DEBUG_MSG LOG_DEBUG(Core_ARM11, "inst is %x", inst); CITRA_IGNORE_EXIT(0) |
| 232 | 294 | ||
| 233 | int CondPassed(ARMul_State* cpu, unsigned int cond); | ||
| 234 | |||
| 235 | #define LnSWoUB(s) glue(LnSWoUB, s) | 295 | #define LnSWoUB(s) glue(LnSWoUB, s) |
| 236 | #define MLnS(s) glue(MLnS, s) | 296 | #define MLnS(s) glue(MLnS, s) |
| 237 | #define LdnStM(s) glue(LdnStM, s) | 297 | #define LdnStM(s) glue(LdnStM, s) |
| @@ -647,255 +707,248 @@ static void LnSWoUB(ScaledRegisterOffset)(ARMul_State* cpu, unsigned int inst, u | |||
| 647 | virt_addr = addr; | 707 | virt_addr = addr; |
| 648 | } | 708 | } |
| 649 | 709 | ||
| 650 | typedef struct _arm_inst { | 710 | struct arm_inst { |
| 651 | unsigned int idx; | 711 | unsigned int idx; |
| 652 | unsigned int cond; | 712 | unsigned int cond; |
| 653 | int br; | 713 | int br; |
| 654 | int load_r15; | 714 | int load_r15; |
| 655 | char component[0]; | 715 | char component[0]; |
| 656 | } arm_inst; | 716 | }; |
| 657 | 717 | ||
| 658 | typedef struct generic_arm_inst { | 718 | struct generic_arm_inst { |
| 659 | u32 Ra; | 719 | u32 Ra; |
| 660 | u32 Rm; | 720 | u32 Rm; |
| 661 | u32 Rn; | 721 | u32 Rn; |
| 662 | u32 Rd; | 722 | u32 Rd; |
| 663 | u8 op1; | 723 | u8 op1; |
| 664 | u8 op2; | 724 | u8 op2; |
| 665 | } generic_arm_inst; | 725 | }; |
| 666 | 726 | ||
| 667 | typedef struct _adc_inst { | 727 | struct adc_inst { |
| 668 | unsigned int I; | 728 | unsigned int I; |
| 669 | unsigned int S; | 729 | unsigned int S; |
| 670 | unsigned int Rn; | 730 | unsigned int Rn; |
| 671 | unsigned int Rd; | 731 | unsigned int Rd; |
| 672 | unsigned int shifter_operand; | 732 | unsigned int shifter_operand; |
| 673 | shtop_fp_t shtop_func; | 733 | shtop_fp_t shtop_func; |
| 674 | } adc_inst; | 734 | }; |
| 675 | 735 | ||
| 676 | typedef struct _add_inst { | 736 | struct add_inst { |
| 677 | unsigned int I; | 737 | unsigned int I; |
| 678 | unsigned int S; | 738 | unsigned int S; |
| 679 | unsigned int Rn; | 739 | unsigned int Rn; |
| 680 | unsigned int Rd; | 740 | unsigned int Rd; |
| 681 | unsigned int shifter_operand; | 741 | unsigned int shifter_operand; |
| 682 | shtop_fp_t shtop_func; | 742 | shtop_fp_t shtop_func; |
| 683 | } add_inst; | 743 | }; |
| 684 | 744 | ||
| 685 | typedef struct _orr_inst { | 745 | struct orr_inst { |
| 686 | unsigned int I; | 746 | unsigned int I; |
| 687 | unsigned int S; | 747 | unsigned int S; |
| 688 | unsigned int Rn; | 748 | unsigned int Rn; |
| 689 | unsigned int Rd; | 749 | unsigned int Rd; |
| 690 | unsigned int shifter_operand; | 750 | unsigned int shifter_operand; |
| 691 | shtop_fp_t shtop_func; | 751 | shtop_fp_t shtop_func; |
| 692 | } orr_inst; | 752 | }; |
| 693 | 753 | ||
| 694 | typedef struct _and_inst { | 754 | struct and_inst { |
| 695 | unsigned int I; | 755 | unsigned int I; |
| 696 | unsigned int S; | 756 | unsigned int S; |
| 697 | unsigned int Rn; | 757 | unsigned int Rn; |
| 698 | unsigned int Rd; | 758 | unsigned int Rd; |
| 699 | unsigned int shifter_operand; | 759 | unsigned int shifter_operand; |
| 700 | shtop_fp_t shtop_func; | 760 | shtop_fp_t shtop_func; |
| 701 | } and_inst; | 761 | }; |
| 702 | 762 | ||
| 703 | typedef struct _eor_inst { | 763 | struct eor_inst { |
| 704 | unsigned int I; | 764 | unsigned int I; |
| 705 | unsigned int S; | 765 | unsigned int S; |
| 706 | unsigned int Rn; | 766 | unsigned int Rn; |
| 707 | unsigned int Rd; | 767 | unsigned int Rd; |
| 708 | unsigned int shifter_operand; | 768 | unsigned int shifter_operand; |
| 709 | shtop_fp_t shtop_func; | 769 | shtop_fp_t shtop_func; |
| 710 | } eor_inst; | 770 | }; |
| 711 | 771 | ||
| 712 | typedef struct _bbl_inst { | 772 | struct bbl_inst { |
| 713 | unsigned int L; | 773 | unsigned int L; |
| 714 | int signed_immed_24; | 774 | int signed_immed_24; |
| 715 | unsigned int next_addr; | 775 | unsigned int next_addr; |
| 716 | unsigned int jmp_addr; | 776 | unsigned int jmp_addr; |
| 717 | } bbl_inst; | 777 | }; |
| 718 | 778 | ||
| 719 | typedef struct _bx_inst { | 779 | struct bx_inst { |
| 720 | unsigned int Rm; | 780 | unsigned int Rm; |
| 721 | } bx_inst; | 781 | }; |
| 722 | 782 | ||
| 723 | typedef struct _blx_inst { | 783 | struct blx_inst { |
| 724 | union { | 784 | union { |
| 725 | int32_t signed_immed_24; | 785 | int32_t signed_immed_24; |
| 726 | uint32_t Rm; | 786 | uint32_t Rm; |
| 727 | } val; | 787 | } val; |
| 728 | unsigned int inst; | 788 | unsigned int inst; |
| 729 | } blx_inst; | 789 | }; |
| 730 | 790 | ||
| 731 | typedef struct _clz_inst { | 791 | struct clz_inst { |
| 732 | unsigned int Rm; | 792 | unsigned int Rm; |
| 733 | unsigned int Rd; | 793 | unsigned int Rd; |
| 734 | } clz_inst; | 794 | }; |
| 735 | 795 | ||
| 736 | typedef struct _cps_inst { | 796 | struct cps_inst { |
| 737 | unsigned int imod0; | 797 | unsigned int imod0; |
| 738 | unsigned int imod1; | 798 | unsigned int imod1; |
| 739 | unsigned int mmod; | 799 | unsigned int mmod; |
| 740 | unsigned int A, I, F; | 800 | unsigned int A, I, F; |
| 741 | unsigned int mode; | 801 | unsigned int mode; |
| 742 | } cps_inst; | 802 | }; |
| 743 | 803 | ||
| 744 | typedef struct _clrex_inst { | 804 | struct clrex_inst { |
| 745 | } clrex_inst; | 805 | }; |
| 746 | 806 | ||
| 747 | typedef struct _cpy_inst { | 807 | struct cpy_inst { |
| 748 | unsigned int Rm; | 808 | unsigned int Rm; |
| 749 | unsigned int Rd; | 809 | unsigned int Rd; |
| 750 | } cpy_inst; | 810 | }; |
| 751 | 811 | ||
| 752 | typedef struct _bic_inst { | 812 | struct bic_inst { |
| 753 | unsigned int I; | 813 | unsigned int I; |
| 754 | unsigned int S; | 814 | unsigned int S; |
| 755 | unsigned int Rn; | 815 | unsigned int Rn; |
| 756 | unsigned int Rd; | 816 | unsigned int Rd; |
| 757 | unsigned int shifter_operand; | 817 | unsigned int shifter_operand; |
| 758 | shtop_fp_t shtop_func; | 818 | shtop_fp_t shtop_func; |
| 759 | } bic_inst; | 819 | }; |
| 760 | 820 | ||
| 761 | typedef struct _sub_inst { | 821 | struct sub_inst { |
| 762 | unsigned int I; | 822 | unsigned int I; |
| 763 | unsigned int S; | 823 | unsigned int S; |
| 764 | unsigned int Rn; | 824 | unsigned int Rn; |
| 765 | unsigned int Rd; | 825 | unsigned int Rd; |
| 766 | unsigned int shifter_operand; | 826 | unsigned int shifter_operand; |
| 767 | shtop_fp_t shtop_func; | 827 | shtop_fp_t shtop_func; |
| 768 | } sub_inst; | 828 | }; |
| 769 | 829 | ||
| 770 | typedef struct _tst_inst { | 830 | struct tst_inst { |
| 771 | unsigned int I; | 831 | unsigned int I; |
| 772 | unsigned int S; | 832 | unsigned int S; |
| 773 | unsigned int Rn; | 833 | unsigned int Rn; |
| 774 | unsigned int Rd; | 834 | unsigned int Rd; |
| 775 | unsigned int shifter_operand; | 835 | unsigned int shifter_operand; |
| 776 | shtop_fp_t shtop_func; | 836 | shtop_fp_t shtop_func; |
| 777 | } tst_inst; | 837 | }; |
| 778 | 838 | ||
| 779 | typedef struct _cmn_inst { | 839 | struct cmn_inst { |
| 780 | unsigned int I; | 840 | unsigned int I; |
| 781 | unsigned int Rn; | 841 | unsigned int Rn; |
| 782 | unsigned int shifter_operand; | 842 | unsigned int shifter_operand; |
| 783 | shtop_fp_t shtop_func; | 843 | shtop_fp_t shtop_func; |
| 784 | } cmn_inst; | 844 | }; |
| 785 | 845 | ||
| 786 | typedef struct _teq_inst { | 846 | struct teq_inst { |
| 787 | unsigned int I; | 847 | unsigned int I; |
| 788 | unsigned int Rn; | 848 | unsigned int Rn; |
| 789 | unsigned int shifter_operand; | 849 | unsigned int shifter_operand; |
| 790 | shtop_fp_t shtop_func; | 850 | shtop_fp_t shtop_func; |
| 791 | } teq_inst; | 851 | }; |
| 792 | 852 | ||
| 793 | typedef struct _stm_inst { | 853 | struct stm_inst { |
| 794 | unsigned int inst; | 854 | unsigned int inst; |
| 795 | } stm_inst; | 855 | }; |
| 796 | 856 | ||
| 797 | struct bkpt_inst { | 857 | struct bkpt_inst { |
| 798 | u32 imm; | 858 | u32 imm; |
| 799 | }; | 859 | }; |
| 800 | 860 | ||
| 801 | struct blx1_inst { | 861 | struct stc_inst { |
| 802 | unsigned int addr; | ||
| 803 | }; | 862 | }; |
| 804 | 863 | ||
| 805 | struct blx2_inst { | 864 | struct ldc_inst { |
| 806 | unsigned int Rm; | ||
| 807 | }; | 865 | }; |
| 808 | 866 | ||
| 809 | typedef struct _stc_inst { | 867 | struct swi_inst { |
| 810 | } stc_inst; | ||
| 811 | |||
| 812 | typedef struct _ldc_inst { | ||
| 813 | } ldc_inst; | ||
| 814 | |||
| 815 | typedef struct _swi_inst { | ||
| 816 | unsigned int num; | 868 | unsigned int num; |
| 817 | } swi_inst; | 869 | }; |
| 818 | 870 | ||
| 819 | typedef struct _cmp_inst { | 871 | struct cmp_inst { |
| 820 | unsigned int I; | 872 | unsigned int I; |
| 821 | unsigned int Rn; | 873 | unsigned int Rn; |
| 822 | unsigned int shifter_operand; | 874 | unsigned int shifter_operand; |
| 823 | shtop_fp_t shtop_func; | 875 | shtop_fp_t shtop_func; |
| 824 | } cmp_inst; | 876 | }; |
| 825 | 877 | ||
| 826 | typedef struct _mov_inst { | 878 | struct mov_inst { |
| 827 | unsigned int I; | 879 | unsigned int I; |
| 828 | unsigned int S; | 880 | unsigned int S; |
| 829 | unsigned int Rd; | 881 | unsigned int Rd; |
| 830 | unsigned int shifter_operand; | 882 | unsigned int shifter_operand; |
| 831 | shtop_fp_t shtop_func; | 883 | shtop_fp_t shtop_func; |
| 832 | } mov_inst; | 884 | }; |
| 833 | 885 | ||
| 834 | typedef struct _mvn_inst { | 886 | struct mvn_inst { |
| 835 | unsigned int I; | 887 | unsigned int I; |
| 836 | unsigned int S; | 888 | unsigned int S; |
| 837 | unsigned int Rd; | 889 | unsigned int Rd; |
| 838 | unsigned int shifter_operand; | 890 | unsigned int shifter_operand; |
| 839 | shtop_fp_t shtop_func; | 891 | shtop_fp_t shtop_func; |
| 840 | } mvn_inst; | 892 | }; |
| 841 | 893 | ||
| 842 | typedef struct _rev_inst { | 894 | struct rev_inst { |
| 843 | unsigned int Rd; | 895 | unsigned int Rd; |
| 844 | unsigned int Rm; | 896 | unsigned int Rm; |
| 845 | unsigned int op1; | 897 | unsigned int op1; |
| 846 | unsigned int op2; | 898 | unsigned int op2; |
| 847 | } rev_inst; | 899 | }; |
| 848 | 900 | ||
| 849 | typedef struct _rsb_inst { | 901 | struct rsb_inst { |
| 850 | unsigned int I; | 902 | unsigned int I; |
| 851 | unsigned int S; | 903 | unsigned int S; |
| 852 | unsigned int Rn; | 904 | unsigned int Rn; |
| 853 | unsigned int Rd; | 905 | unsigned int Rd; |
| 854 | unsigned int shifter_operand; | 906 | unsigned int shifter_operand; |
| 855 | shtop_fp_t shtop_func; | 907 | shtop_fp_t shtop_func; |
| 856 | } rsb_inst; | 908 | }; |
| 857 | 909 | ||
| 858 | typedef struct _rsc_inst { | 910 | struct rsc_inst { |
| 859 | unsigned int I; | 911 | unsigned int I; |
| 860 | unsigned int S; | 912 | unsigned int S; |
| 861 | unsigned int Rn; | 913 | unsigned int Rn; |
| 862 | unsigned int Rd; | 914 | unsigned int Rd; |
| 863 | unsigned int shifter_operand; | 915 | unsigned int shifter_operand; |
| 864 | shtop_fp_t shtop_func; | 916 | shtop_fp_t shtop_func; |
| 865 | } rsc_inst; | 917 | }; |
| 866 | 918 | ||
| 867 | typedef struct _sbc_inst { | 919 | struct sbc_inst { |
| 868 | unsigned int I; | 920 | unsigned int I; |
| 869 | unsigned int S; | 921 | unsigned int S; |
| 870 | unsigned int Rn; | 922 | unsigned int Rn; |
| 871 | unsigned int Rd; | 923 | unsigned int Rd; |
| 872 | unsigned int shifter_operand; | 924 | unsigned int shifter_operand; |
| 873 | shtop_fp_t shtop_func; | 925 | shtop_fp_t shtop_func; |
| 874 | } sbc_inst; | 926 | }; |
| 875 | 927 | ||
| 876 | typedef struct _mul_inst { | 928 | struct mul_inst { |
| 877 | unsigned int S; | 929 | unsigned int S; |
| 878 | unsigned int Rd; | 930 | unsigned int Rd; |
| 879 | unsigned int Rs; | 931 | unsigned int Rs; |
| 880 | unsigned int Rm; | 932 | unsigned int Rm; |
| 881 | } mul_inst; | 933 | }; |
| 882 | 934 | ||
| 883 | typedef struct _smul_inst { | 935 | struct smul_inst { |
| 884 | unsigned int Rd; | 936 | unsigned int Rd; |
| 885 | unsigned int Rs; | 937 | unsigned int Rs; |
| 886 | unsigned int Rm; | 938 | unsigned int Rm; |
| 887 | unsigned int x; | 939 | unsigned int x; |
| 888 | unsigned int y; | 940 | unsigned int y; |
| 889 | } smul_inst; | 941 | }; |
| 890 | 942 | ||
| 891 | typedef struct _umull_inst { | 943 | struct umull_inst { |
| 892 | unsigned int S; | 944 | unsigned int S; |
| 893 | unsigned int RdHi; | 945 | unsigned int RdHi; |
| 894 | unsigned int RdLo; | 946 | unsigned int RdLo; |
| 895 | unsigned int Rs; | 947 | unsigned int Rs; |
| 896 | unsigned int Rm; | 948 | unsigned int Rm; |
| 897 | } umull_inst; | 949 | }; |
| 898 | typedef struct _smlad_inst { | 950 | |
| 951 | struct smlad_inst { | ||
| 899 | unsigned int m; | 952 | unsigned int m; |
| 900 | unsigned int Rm; | 953 | unsigned int Rm; |
| 901 | unsigned int Rd; | 954 | unsigned int Rd; |
| @@ -903,58 +956,58 @@ typedef struct _smlad_inst { | |||
| 903 | unsigned int Rn; | 956 | unsigned int Rn; |
| 904 | unsigned int op1; | 957 | unsigned int op1; |
| 905 | unsigned int op2; | 958 | unsigned int op2; |
| 906 | } smlad_inst; | 959 | }; |
| 907 | 960 | ||
| 908 | typedef struct _smla_inst { | 961 | struct smla_inst { |
| 909 | unsigned int x; | 962 | unsigned int x; |
| 910 | unsigned int y; | 963 | unsigned int y; |
| 911 | unsigned int Rm; | 964 | unsigned int Rm; |
| 912 | unsigned int Rd; | 965 | unsigned int Rd; |
| 913 | unsigned int Rs; | 966 | unsigned int Rs; |
| 914 | unsigned int Rn; | 967 | unsigned int Rn; |
| 915 | } smla_inst; | 968 | }; |
| 916 | 969 | ||
| 917 | typedef struct smlalxy_inst { | 970 | struct smlalxy_inst { |
| 918 | unsigned int x; | 971 | unsigned int x; |
| 919 | unsigned int y; | 972 | unsigned int y; |
| 920 | unsigned int RdLo; | 973 | unsigned int RdLo; |
| 921 | unsigned int RdHi; | 974 | unsigned int RdHi; |
| 922 | unsigned int Rm; | 975 | unsigned int Rm; |
| 923 | unsigned int Rn; | 976 | unsigned int Rn; |
| 924 | } smlalxy_inst; | 977 | }; |
| 925 | 978 | ||
| 926 | typedef struct ssat_inst { | 979 | struct ssat_inst { |
| 927 | unsigned int Rn; | 980 | unsigned int Rn; |
| 928 | unsigned int Rd; | 981 | unsigned int Rd; |
| 929 | unsigned int imm5; | 982 | unsigned int imm5; |
| 930 | unsigned int sat_imm; | 983 | unsigned int sat_imm; |
| 931 | unsigned int shift_type; | 984 | unsigned int shift_type; |
| 932 | } ssat_inst; | 985 | }; |
| 933 | 986 | ||
| 934 | typedef struct umaal_inst { | 987 | struct umaal_inst { |
| 935 | unsigned int Rn; | 988 | unsigned int Rn; |
| 936 | unsigned int Rm; | 989 | unsigned int Rm; |
| 937 | unsigned int RdHi; | 990 | unsigned int RdHi; |
| 938 | unsigned int RdLo; | 991 | unsigned int RdLo; |
| 939 | } umaal_inst; | 992 | }; |
| 940 | 993 | ||
| 941 | typedef struct _umlal_inst { | 994 | struct umlal_inst { |
| 942 | unsigned int S; | 995 | unsigned int S; |
| 943 | unsigned int Rm; | 996 | unsigned int Rm; |
| 944 | unsigned int Rs; | 997 | unsigned int Rs; |
| 945 | unsigned int RdHi; | 998 | unsigned int RdHi; |
| 946 | unsigned int RdLo; | 999 | unsigned int RdLo; |
| 947 | } umlal_inst; | 1000 | }; |
| 948 | 1001 | ||
| 949 | typedef struct _smlal_inst { | 1002 | struct smlal_inst { |
| 950 | unsigned int S; | 1003 | unsigned int S; |
| 951 | unsigned int Rm; | 1004 | unsigned int Rm; |
| 952 | unsigned int Rs; | 1005 | unsigned int Rs; |
| 953 | unsigned int RdHi; | 1006 | unsigned int RdHi; |
| 954 | unsigned int RdLo; | 1007 | unsigned int RdLo; |
| 955 | } smlal_inst; | 1008 | }; |
| 956 | 1009 | ||
| 957 | typedef struct smlald_inst { | 1010 | struct smlald_inst { |
| 958 | unsigned int RdLo; | 1011 | unsigned int RdLo; |
| 959 | unsigned int RdHi; | 1012 | unsigned int RdHi; |
| 960 | unsigned int Rm; | 1013 | unsigned int Rm; |
| @@ -962,17 +1015,17 @@ typedef struct smlald_inst { | |||
| 962 | unsigned int swap; | 1015 | unsigned int swap; |
| 963 | unsigned int op1; | 1016 | unsigned int op1; |
| 964 | unsigned int op2; | 1017 | unsigned int op2; |
| 965 | } smlald_inst; | 1018 | }; |
| 966 | 1019 | ||
| 967 | typedef struct _mla_inst { | 1020 | struct mla_inst { |
| 968 | unsigned int S; | 1021 | unsigned int S; |
| 969 | unsigned int Rn; | 1022 | unsigned int Rn; |
| 970 | unsigned int Rd; | 1023 | unsigned int Rd; |
| 971 | unsigned int Rs; | 1024 | unsigned int Rs; |
| 972 | unsigned int Rm; | 1025 | unsigned int Rm; |
| 973 | } mla_inst; | 1026 | }; |
| 974 | 1027 | ||
| 975 | typedef struct _mrc_inst { | 1028 | struct mrc_inst { |
| 976 | unsigned int opcode_1; | 1029 | unsigned int opcode_1; |
| 977 | unsigned int opcode_2; | 1030 | unsigned int opcode_2; |
| 978 | unsigned int cp_num; | 1031 | unsigned int cp_num; |
| @@ -980,9 +1033,9 @@ typedef struct _mrc_inst { | |||
| 980 | unsigned int crm; | 1033 | unsigned int crm; |
| 981 | unsigned int Rd; | 1034 | unsigned int Rd; |
| 982 | unsigned int inst; | 1035 | unsigned int inst; |
| 983 | } mrc_inst; | 1036 | }; |
| 984 | 1037 | ||
| 985 | typedef struct _mcr_inst { | 1038 | struct mcr_inst { |
| 986 | unsigned int opcode_1; | 1039 | unsigned int opcode_1; |
| 987 | unsigned int opcode_2; | 1040 | unsigned int opcode_2; |
| 988 | unsigned int cp_num; | 1041 | unsigned int cp_num; |
| @@ -990,77 +1043,77 @@ typedef struct _mcr_inst { | |||
| 990 | unsigned int crm; | 1043 | unsigned int crm; |
| 991 | unsigned int Rd; | 1044 | unsigned int Rd; |
| 992 | unsigned int inst; | 1045 | unsigned int inst; |
| 993 | } mcr_inst; | 1046 | }; |
| 994 | 1047 | ||
| 995 | typedef struct mcrr_inst { | 1048 | struct mcrr_inst { |
| 996 | unsigned int opcode_1; | 1049 | unsigned int opcode_1; |
| 997 | unsigned int cp_num; | 1050 | unsigned int cp_num; |
| 998 | unsigned int crm; | 1051 | unsigned int crm; |
| 999 | unsigned int rt; | 1052 | unsigned int rt; |
| 1000 | unsigned int rt2; | 1053 | unsigned int rt2; |
| 1001 | } mcrr_inst; | 1054 | }; |
| 1002 | 1055 | ||
| 1003 | typedef struct _mrs_inst { | 1056 | struct mrs_inst { |
| 1004 | unsigned int R; | 1057 | unsigned int R; |
| 1005 | unsigned int Rd; | 1058 | unsigned int Rd; |
| 1006 | } mrs_inst; | 1059 | }; |
| 1007 | 1060 | ||
| 1008 | typedef struct _msr_inst { | 1061 | struct msr_inst { |
| 1009 | unsigned int field_mask; | 1062 | unsigned int field_mask; |
| 1010 | unsigned int R; | 1063 | unsigned int R; |
| 1011 | unsigned int inst; | 1064 | unsigned int inst; |
| 1012 | } msr_inst; | 1065 | }; |
| 1013 | 1066 | ||
| 1014 | typedef struct _pld_inst { | 1067 | struct pld_inst { |
| 1015 | } pld_inst; | 1068 | }; |
| 1016 | 1069 | ||
| 1017 | typedef struct _sxtb_inst { | 1070 | struct sxtb_inst { |
| 1018 | unsigned int Rd; | 1071 | unsigned int Rd; |
| 1019 | unsigned int Rm; | 1072 | unsigned int Rm; |
| 1020 | unsigned int rotate; | 1073 | unsigned int rotate; |
| 1021 | } sxtb_inst; | 1074 | }; |
| 1022 | 1075 | ||
| 1023 | typedef struct _sxtab_inst { | 1076 | struct sxtab_inst { |
| 1024 | unsigned int Rd; | 1077 | unsigned int Rd; |
| 1025 | unsigned int Rn; | 1078 | unsigned int Rn; |
| 1026 | unsigned int Rm; | 1079 | unsigned int Rm; |
| 1027 | unsigned rotate; | 1080 | unsigned rotate; |
| 1028 | } sxtab_inst; | 1081 | }; |
| 1029 | 1082 | ||
| 1030 | typedef struct _sxtah_inst { | 1083 | struct sxtah_inst { |
| 1031 | unsigned int Rd; | 1084 | unsigned int Rd; |
| 1032 | unsigned int Rn; | 1085 | unsigned int Rn; |
| 1033 | unsigned int Rm; | 1086 | unsigned int Rm; |
| 1034 | unsigned int rotate; | 1087 | unsigned int rotate; |
| 1035 | } sxtah_inst; | 1088 | }; |
| 1036 | 1089 | ||
| 1037 | typedef struct _sxth_inst { | 1090 | struct sxth_inst { |
| 1038 | unsigned int Rd; | 1091 | unsigned int Rd; |
| 1039 | unsigned int Rm; | 1092 | unsigned int Rm; |
| 1040 | unsigned int rotate; | 1093 | unsigned int rotate; |
| 1041 | } sxth_inst; | 1094 | }; |
| 1042 | 1095 | ||
| 1043 | typedef struct _uxtab_inst { | 1096 | struct uxtab_inst { |
| 1044 | unsigned int Rn; | 1097 | unsigned int Rn; |
| 1045 | unsigned int Rd; | 1098 | unsigned int Rd; |
| 1046 | unsigned int rotate; | 1099 | unsigned int rotate; |
| 1047 | unsigned int Rm; | 1100 | unsigned int Rm; |
| 1048 | } uxtab_inst; | 1101 | }; |
| 1049 | 1102 | ||
| 1050 | typedef struct _uxtah_inst { | 1103 | struct uxtah_inst { |
| 1051 | unsigned int Rn; | 1104 | unsigned int Rn; |
| 1052 | unsigned int Rd; | 1105 | unsigned int Rd; |
| 1053 | unsigned int rotate; | 1106 | unsigned int rotate; |
| 1054 | unsigned int Rm; | 1107 | unsigned int Rm; |
| 1055 | } uxtah_inst; | 1108 | }; |
| 1056 | 1109 | ||
| 1057 | typedef struct _uxth_inst { | 1110 | struct uxth_inst { |
| 1058 | unsigned int Rd; | 1111 | unsigned int Rd; |
| 1059 | unsigned int Rm; | 1112 | unsigned int Rm; |
| 1060 | unsigned int rotate; | 1113 | unsigned int rotate; |
| 1061 | } uxth_inst; | 1114 | }; |
| 1062 | 1115 | ||
| 1063 | typedef struct _cdp_inst { | 1116 | struct cdp_inst { |
| 1064 | unsigned int opcode_1; | 1117 | unsigned int opcode_1; |
| 1065 | unsigned int CRn; | 1118 | unsigned int CRn; |
| 1066 | unsigned int CRd; | 1119 | unsigned int CRd; |
| @@ -1068,56 +1121,56 @@ typedef struct _cdp_inst { | |||
| 1068 | unsigned int opcode_2; | 1121 | unsigned int opcode_2; |
| 1069 | unsigned int CRm; | 1122 | unsigned int CRm; |
| 1070 | unsigned int inst; | 1123 | unsigned int inst; |
| 1071 | }cdp_inst; | 1124 | }; |
| 1072 | 1125 | ||
| 1073 | typedef struct _uxtb_inst { | 1126 | struct uxtb_inst { |
| 1074 | unsigned int Rd; | 1127 | unsigned int Rd; |
| 1075 | unsigned int Rm; | 1128 | unsigned int Rm; |
| 1076 | unsigned int rotate; | 1129 | unsigned int rotate; |
| 1077 | } uxtb_inst; | 1130 | }; |
| 1078 | 1131 | ||
| 1079 | typedef struct _swp_inst { | 1132 | struct swp_inst { |
| 1080 | unsigned int Rn; | 1133 | unsigned int Rn; |
| 1081 | unsigned int Rd; | 1134 | unsigned int Rd; |
| 1082 | unsigned int Rm; | 1135 | unsigned int Rm; |
| 1083 | } swp_inst; | 1136 | }; |
| 1084 | 1137 | ||
| 1085 | typedef struct setend_inst { | 1138 | struct setend_inst { |
| 1086 | unsigned int set_bigend; | 1139 | unsigned int set_bigend; |
| 1087 | } setend_inst; | 1140 | }; |
| 1088 | 1141 | ||
| 1089 | typedef struct _b_2_thumb { | 1142 | struct b_2_thumb { |
| 1090 | unsigned int imm; | 1143 | unsigned int imm; |
| 1091 | }b_2_thumb; | 1144 | }; |
| 1092 | typedef struct _b_cond_thumb { | 1145 | struct b_cond_thumb { |
| 1093 | unsigned int imm; | 1146 | unsigned int imm; |
| 1094 | unsigned int cond; | 1147 | unsigned int cond; |
| 1095 | }b_cond_thumb; | 1148 | }; |
| 1096 | 1149 | ||
| 1097 | typedef struct _bl_1_thumb { | 1150 | struct bl_1_thumb { |
| 1098 | unsigned int imm; | 1151 | unsigned int imm; |
| 1099 | }bl_1_thumb; | 1152 | }; |
| 1100 | typedef struct _bl_2_thumb { | 1153 | struct bl_2_thumb { |
| 1101 | unsigned int imm; | 1154 | unsigned int imm; |
| 1102 | }bl_2_thumb; | 1155 | }; |
| 1103 | typedef struct _blx_1_thumb { | 1156 | struct blx_1_thumb { |
| 1104 | unsigned int imm; | 1157 | unsigned int imm; |
| 1105 | unsigned int instr; | 1158 | unsigned int instr; |
| 1106 | }blx_1_thumb; | 1159 | }; |
| 1107 | 1160 | ||
| 1108 | typedef struct _pkh_inst { | 1161 | struct pkh_inst { |
| 1109 | unsigned int Rm; | 1162 | unsigned int Rm; |
| 1110 | unsigned int Rn; | 1163 | unsigned int Rn; |
| 1111 | unsigned int Rd; | 1164 | unsigned int Rd; |
| 1112 | unsigned char imm; | 1165 | unsigned char imm; |
| 1113 | } pkh_inst; | 1166 | }; |
| 1114 | 1167 | ||
| 1115 | typedef arm_inst * ARM_INST_PTR; | 1168 | typedef arm_inst * ARM_INST_PTR; |
| 1116 | 1169 | ||
| 1117 | #define CACHE_BUFFER_SIZE (64 * 1024 * 2000) | 1170 | #define CACHE_BUFFER_SIZE (64 * 1024 * 2000) |
| 1118 | char inst_buf[CACHE_BUFFER_SIZE]; | 1171 | static char inst_buf[CACHE_BUFFER_SIZE]; |
| 1119 | int top = 0; | 1172 | static int top = 0; |
| 1120 | inline void *AllocBuffer(unsigned int size) { | 1173 | static inline void *AllocBuffer(unsigned int size) { |
| 1121 | int start = top; | 1174 | int start = top; |
| 1122 | top += size; | 1175 | top += size; |
| 1123 | if (top > CACHE_BUFFER_SIZE) { | 1176 | if (top > CACHE_BUFFER_SIZE) { |
| @@ -1127,74 +1180,6 @@ inline void *AllocBuffer(unsigned int size) { | |||
| 1127 | return (void *)&inst_buf[start]; | 1180 | return (void *)&inst_buf[start]; |
| 1128 | } | 1181 | } |
| 1129 | 1182 | ||
| 1130 | int CondPassed(ARMul_State* cpu, unsigned int cond) { | ||
| 1131 | #define NFLAG cpu->NFlag | ||
| 1132 | #define ZFLAG cpu->ZFlag | ||
| 1133 | #define CFLAG cpu->CFlag | ||
| 1134 | #define VFLAG cpu->VFlag | ||
| 1135 | |||
| 1136 | int temp = 0; | ||
| 1137 | |||
| 1138 | switch (cond) { | ||
| 1139 | case 0x0: | ||
| 1140 | temp = ZFLAG; | ||
| 1141 | break; | ||
| 1142 | case 0x1: // NE | ||
| 1143 | temp = !ZFLAG; | ||
| 1144 | break; | ||
| 1145 | case 0x6: // VS | ||
| 1146 | temp = VFLAG; | ||
| 1147 | break; | ||
| 1148 | case 0x7: // VC | ||
| 1149 | temp = !VFLAG; | ||
| 1150 | break; | ||
| 1151 | case 0x4: // MI | ||
| 1152 | temp = NFLAG; | ||
| 1153 | break; | ||
| 1154 | case 0x5: // PL | ||
| 1155 | temp = !NFLAG; | ||
| 1156 | break; | ||
| 1157 | case 0x2: // CS | ||
| 1158 | temp = CFLAG; | ||
| 1159 | break; | ||
| 1160 | case 0x3: // CC | ||
| 1161 | temp = !CFLAG; | ||
| 1162 | break; | ||
| 1163 | case 0x8: // HI | ||
| 1164 | temp = (CFLAG && !ZFLAG); | ||
| 1165 | break; | ||
| 1166 | case 0x9: // LS | ||
| 1167 | temp = (!CFLAG || ZFLAG); | ||
| 1168 | break; | ||
| 1169 | case 0xa: // GE | ||
| 1170 | temp = ((!NFLAG && !VFLAG) || (NFLAG && VFLAG)); | ||
| 1171 | break; | ||
| 1172 | case 0xb: // LT | ||
| 1173 | temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG)); | ||
| 1174 | break; | ||
| 1175 | case 0xc: // GT | ||
| 1176 | temp = ((!NFLAG && !VFLAG && !ZFLAG) || (NFLAG && VFLAG && !ZFLAG)); | ||
| 1177 | break; | ||
| 1178 | case 0xd: // LE | ||
| 1179 | temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG)) || ZFLAG; | ||
| 1180 | break; | ||
| 1181 | case 0xe: // AL | ||
| 1182 | temp = 1; | ||
| 1183 | break; | ||
| 1184 | case 0xf: | ||
| 1185 | temp = 1; | ||
| 1186 | break; | ||
| 1187 | } | ||
| 1188 | return temp; | ||
| 1189 | } | ||
| 1190 | |||
| 1191 | enum DECODE_STATUS { | ||
| 1192 | DECODE_SUCCESS, | ||
| 1193 | DECODE_FAILURE | ||
| 1194 | }; | ||
| 1195 | |||
| 1196 | int decode_arm_instr(uint32_t instr, int32_t *idx); | ||
| 1197 | |||
| 1198 | static shtop_fp_t get_shtop(unsigned int inst) { | 1183 | static shtop_fp_t get_shtop(unsigned int inst) { |
| 1199 | if (BIT(inst, 25)) { | 1184 | if (BIT(inst, 25)) { |
| 1200 | return DPO(Immediate); | 1185 | return DPO(Immediate); |