about summary refs log tree commit diff stats
path: root/test/arch/mep/ir/test_coprocessor.py
blob: bd8fd39cf9606b917e7a5ced9560d2cb20de1630 (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
# Toshiba MeP-c4 - Coprocessor instructions unit tests
# Guillaume Valadon <guillaume@valadon.net>

from ut_helpers_ir import exec_instruction

from miasm.expression.expression import ExprId, ExprMem, ExprInt


class TestCoprocessor(object):

    def test_swcp(self):
        """Test SWCP execution"""

        # SWCP CRn,(Rm)
        exec_instruction("SWCP C1, (R2)",
                         [(ExprId("C1", 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x11, 32))],
                         [(ExprMem(ExprInt(0x10, 32), 32), ExprInt(0x28071010, 32))])

        # SWCP CRn,disp16(Rm)
        exec_instruction("SWCP C10, 0xF800(R2)",
                         [(ExprId("C10", 32), ExprInt(0xABC7, 32)),
                          (ExprId("R2", 32), ExprInt(0x11, 32))],
                         [(ExprMem(ExprInt(0xFFFFF810, 32), 32), ExprInt(0xABC7, 32))])

    def test_lwcp(self):
        """Test LWCP execution"""

        # LWCP CRn[0-15],(Rm)
        exec_instruction("LWCP C1, (R2)",
                         [(ExprId("R2", 32), ExprInt(0x11, 32)),
                          (ExprMem(ExprInt(0x10, 32), 32), ExprInt(0xABCD, 32))],
                         [(ExprId("C1", 32), ExprInt(0xABCD, 32))])

        # LWCP CRn[0-15],disp16(Rm)
        exec_instruction("LWCP C9, 0xF000(R2)",
                         [(ExprId("R2", 32), ExprInt(0x42, 32)),
                          (ExprMem(ExprInt(0xFFFFF040, 32), 32), ExprInt(0x10, 32))],
                         [(ExprId("C9", 32), ExprInt(0x10, 32))])

    def test_smcp(self):
        """Test SMCP execution"""

        # SMCP CRn,(Rm)
        exec_instruction("SMCP C1, (R2)",
                         [(ExprId("C1", 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x17, 32))],
                         [(ExprMem(ExprInt(0x10, 32), 32), ExprInt(0x28071010, 32))])

        # SMCP CRn,disp16(Rm)
        exec_instruction("SMCP C10, 0xF800(R2)",
                         [(ExprId("C10", 32), ExprInt(0xABC7, 32)),
                          (ExprId("R2", 32), ExprInt(0x17, 32))],
                         [(ExprMem(ExprInt(0xFFFFF810, 32), 32), ExprInt(0xABC7, 32))])

    def test_lmcp(self):
        """Test LMCP execution"""

        # LMCP CRn[0-15],(Rm)
        exec_instruction("LMCP C1, (R2)",
                         [(ExprId("R2", 32), ExprInt(0x10, 32)),
                          (ExprMem(ExprInt(0x10, 32), 32), ExprInt(0xABCD, 32))],
                         [(ExprId("C1", 32), ExprInt(0xABCD, 32))])

        # LMCP CRn[0-15],disp16(Rm)
        exec_instruction("LMCP C9, 0xF000(R2)",
                         [(ExprId("R2", 32), ExprInt(0x17, 32)),
                          (ExprMem(ExprInt(0xFFFFF010, 32), 32), ExprInt(0x10, 32))],
                         [(ExprId("C9", 32), ExprInt(0x10, 32))])

    def test_swcpi(self):
        """Test SWCPI execution"""

        # SWCPI CRn[0-15],(Rm+)
        exec_instruction("SWCPI C1, (R2+)",
                         [(ExprId("C1", 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x11, 32))],
                         [(ExprMem(ExprInt(0x10, 32), 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x15, 32))])

    def test_lwcpi(self):
        """Test LWCPI execution"""

        # LWCPI CRn[0-15],(Rm+)
        exec_instruction("LWCPI C1, (R2+)",
                         [(ExprId("R2", 32), ExprInt(0x11, 32)),
                          (ExprMem(ExprInt(0x10, 32), 32), ExprInt(0xABCD, 32))],
                         [(ExprId("C1", 32), ExprInt(0xABCD, 32)),
                          (ExprId("R2", 32), ExprInt(0x15, 32))])

    def test_smcpi(self):
        """Test SMCPI execution"""

        # SMCPI CRn[0-15],(Rm+)
        exec_instruction("SMCPI C1, (R2+)",
                         [(ExprId("C1", 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x17, 32))],
                         [(ExprMem(ExprInt(0x10, 32), 32), ExprInt(0x28071010, 32)),
                          (ExprId("R2", 32), ExprInt(0x1F, 32))])

    def test_lmcpi(self):
        """Test LMCPI execution"""

        # LMCPI CRn[0-15],(Rm+)
        exec_instruction("LMCPI C1, (R2+)",
                         [(ExprId("R2", 32), ExprInt(0x11, 32)),
                          (ExprMem(ExprInt(0x10, 32), 32), ExprInt(0xABCD, 32))],
                         [(ExprId("C1", 32), ExprInt(0xABCD, 32)),
                          (ExprId("R2", 32), ExprInt(0x19, 32))])