aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Decoders/OpCodeT16MemImm5.cs
blob: 20ef31e273b2233102d2d4212cb85c2abba110a2 (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
using ARMeilleure.Instructions;
using System;

namespace ARMeilleure.Decoders
{
    class OpCodeT16MemImm5 : OpCodeT16, IOpCode32Mem
    {
        public int Rt { get; }
        public int Rn { get; }

        public bool WBack => false;
        public bool IsLoad { get; }
        public bool Index => true;
        public bool Add => true;

        public int Immediate { get; }

        public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeT16MemImm5(inst, address, opCode);

        public OpCodeT16MemImm5(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
        {
            Rt = (opCode >> 0) & 7;
            Rn = (opCode >> 3) & 7;

            switch (inst.Name)
            {
                case InstName.Ldr:
                case InstName.Ldrb:
                case InstName.Ldrh:
                    IsLoad = true;
                    break;
                case InstName.Str:
                case InstName.Strb:
                case InstName.Strh:
                    IsLoad = false;
                    break;
            }

            switch (inst.Name)
            {
                case InstName.Str:
                case InstName.Ldr:
                    Immediate = ((opCode >> 6) & 0x1f) << 2;
                    break;
                case InstName.Strb:
                case InstName.Ldrb:
                    Immediate = ((opCode >> 6) & 0x1f);
                    break;
                case InstName.Strh:
                case InstName.Ldrh:
                    Immediate = ((opCode >> 6) & 0x1f) << 1;
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
    }
}