aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Tests/Cpu/CpuTestT32Flow.cs
blob: 01159afc66de67799c549e01be1f3166d95b318d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using ARMeilleure.State;
using NUnit.Framework;

namespace Ryujinx.Tests.Cpu
{
    [Category("T32Flow")]
    public sealed class CpuTestT32Flow : CpuTest32
    {
        [Test]
        public void TestT32B1()
        {
            // BNE label
            ThumbOpcode(0xf040);
            ThumbOpcode(0x8240);
            for (int i = 0; i < 576; i++)
            {
                ThumbOpcode(0xe7fe);
            }
            // label: BX LR
            ThumbOpcode(0x4770);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);
        }

        [Test]
        public void TestT32B2()
        {
            // BNE label1
            ThumbOpcode(0xf040);
            ThumbOpcode(0x8242);
            // label2: BNE label3
            ThumbOpcode(0xf040);
            ThumbOpcode(0x8242);
            for (int i = 0; i < 576; i++)
            {
                ThumbOpcode(0xe7fe);
            }
            // label1: BNE label2
            ThumbOpcode(0xf47f);
            ThumbOpcode(0xadbc);
            // label3: BX LR
            ThumbOpcode(0x4770);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);
        }

        [Test]
        public void TestT32B3()
        {
            // B.W label
            ThumbOpcode(0xf000);
            ThumbOpcode(0xba40);
            for (int i = 0; i < 576; i++)
            {
                ThumbOpcode(0xe7fe);
            }
            // label: BX LR
            ThumbOpcode(0x4770);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);
        }

        [Test]
        public void TestT32B4()
        {
            // B.W label1
            ThumbOpcode(0xf000);
            ThumbOpcode(0xba42);
            // label2: B.W label3
            ThumbOpcode(0xf000);
            ThumbOpcode(0xba42);
            for (int i = 0; i < 576; i++)
            {
                ThumbOpcode(0xe7fe);
            }
            // label1: B.W label2
            ThumbOpcode(0xf7ff);
            ThumbOpcode(0xbdbc);
            // label3: BX LR
            ThumbOpcode(0x4770);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);
        }

        [Test]
        public void TestT32Bl()
        {
            // BL label
            ThumbOpcode(0xf000);
            ThumbOpcode(0xf840);
            for (int i = 0; i < 64; i++)
            {
                ThumbOpcode(0xe7fe);
            }
            ThumbOpcode(0x4670); // label: MOV R0, LR
            ThumbOpcode(0x2100); //        MOVS R1, #0
            ThumbOpcode(0x468e); //        MOV LR, R1
            ThumbOpcode(0x4770); //        BX LR

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);

            Assert.That(GetContext().GetX(0), Is.EqualTo(CodeBaseAddress + 0x5));
        }

        [Test]
        public void TestT32Blx1()
        {
            // BLX label
            ThumbOpcode(0xf000);
            ThumbOpcode(0xe840);
            for (int i = 0; i < 64; i++)
            {
                ThumbOpcode(0x4770);
            }
            // .arm ; label: MOV R0, LR
            Opcode(0xe1a0000e);
            // MOV LR, #0
            Opcode(0xe3a0e000);
            // BX LR
            Opcode(0xe12fff1e);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);

            Assert.That(GetContext().GetX(0), Is.EqualTo(CodeBaseAddress + 0x5));
            Assert.That(GetContext().GetPstateFlag(PState.TFlag), Is.EqualTo(false));
        }

        [Test]
        public void TestT32Blx2()
        {
            // NOP
            ThumbOpcode(0xbf00);
            // BLX label
            ThumbOpcode(0xf000);
            ThumbOpcode(0xe840);
            for (int i = 0; i < 63; i++)
            {
                ThumbOpcode(0x4770);
            }
            // .arm ; label: MOV R0, LR
            Opcode(0xe1a0000e);
            // MOV LR, #0
            Opcode(0xe3a0e000);
            // BX LR
            Opcode(0xe12fff1e);

            GetContext().SetPstateFlag(PState.TFlag, true);

            ExecuteOpcodes(runUnicorn: false);

            Assert.That(GetContext().GetX(0), Is.EqualTo(CodeBaseAddress + 0x7));
            Assert.That(GetContext().GetPstateFlag(PState.TFlag), Is.EqualTo(false));
        }
    }
}