aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx/Cpu/Instruction/AInstEmitSystem.cs
blob: 23a0b6b2d3ed9450e3d34e56958a110fec9d7817 (plain)
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
using ChocolArm64.Decoder;
using ChocolArm64.State;
using ChocolArm64.Translation;
using System.Reflection.Emit;

namespace ChocolArm64.Instruction
{
    static partial class AInstEmit
    {
        public static void Mrs(AILEmitterCtx Context)
        {
            AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;

            Context.EmitLdarg(ATranslatedSub.RegistersArgIdx);

            Context.EmitLdc_I4(Op.Op0);
            Context.EmitLdc_I4(Op.Op1);
            Context.EmitLdc_I4(Op.CRn);
            Context.EmitLdc_I4(Op.CRm);
            Context.EmitLdc_I4(Op.Op2);

            Context.EmitCall(typeof(ARegisters), nameof(ARegisters.GetSystemReg));

            Context.EmitStintzr(Op.Rt);
        }

        public static void Msr(AILEmitterCtx Context)
        {
            AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;

            Context.EmitLdarg(ATranslatedSub.RegistersArgIdx);

            Context.EmitLdc_I4(Op.Op0);
            Context.EmitLdc_I4(Op.Op1);
            Context.EmitLdc_I4(Op.CRn);
            Context.EmitLdc_I4(Op.CRm);
            Context.EmitLdc_I4(Op.Op2);
            Context.EmitLdintzr(Op.Rt);

            Context.EmitCall(typeof(ARegisters), nameof(ARegisters.SetSystemReg));
        }

        public static void Nop(AILEmitterCtx Context)
        {
            //Do nothing.
        }

        public static void Sys(AILEmitterCtx Context)
        {
            //This instruction is used to do some operations on the CPU like cache invalidation,
            //address translation and the like.
            //We treat it as no-op here since we don't have any cache being emulated anyway.
            AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;

            int Id;

            Id  = Op.Op2 << 0;
            Id |= Op.CRm << 3;
            Id |= Op.CRn << 7;
            Id |= Op.Op1 << 11;

            switch (Id)
            {
                case 0b011_0111_0100_001:
                {
                    //DC ZVA
                    for (int Offs = 0; Offs < 64; Offs += 8)
                    {
                        Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
                        Context.EmitLdint(Op.Rt);
                        Context.EmitLdc_I(Offs);

                        Context.Emit(OpCodes.Add);

                        Context.EmitLdc_I8(0);

                        AInstEmitMemoryHelper.EmitWriteCall(Context, 3);
                    }
                    break;
                }
            }
        }
    }
}