예제 #1
0
 public OpCode(InstructionType type, OpCodeFlag flag, int argument1Type, int argument2Type)
 {
     Type          = type;
     Flag          = flag;
     Argument1Type = argument1Type;
     Argument2Type = argument2Type;
 }
예제 #2
0
        public static MaskedOpCode SetSource(this MaskedOpCode opCode, OpCodeFlag sourceFlag)
        {
            var code = (ushort)opCode;

            code &= 0xf3ff;
            var result = code | ((ushort)sourceFlag << 10);

            return((MaskedOpCode)result);
        }
예제 #3
0
        public void Enqueue(DeviceId deviceId, ProcessContextBlock pcb, OpCodeFlag flag = OpCodeFlag.Register, uint arg1 = 0)
        {
            var blockingProcess = new BlockingProcess
            {
                Process  = pcb,
                Flag     = flag,
                Argument = arg1,
                DeviceId = deviceId
            };

            _deviceQueue[deviceId].Enqueue(blockingProcess);
        }
예제 #4
0
파일: Cpu.cs 프로젝트: andy-uq/TinyOS
 public void Input(DeviceId deviceId, OpCodeFlag flag, uint rX)
 {
     if (Enum.IsDefined(typeof(DeviceId), deviceId))
     {
         DeviceReadQueue.Enqueue(deviceId, CurrentProcess, flag, rX);
         CurrentProcess = null;
     }
     else
     {
         CurrentProcess.Zf = true;
     }
 }
예제 #5
0
        public static MaskedOpCode SetDest(this MaskedOpCode opCode, OpCodeFlag destFlag)
        {
            if (destFlag == OpCodeFlag.Constant)
            {
                throw new InvalidOperationException("Cannot set constant as destination vector");
            }

            var code = (ushort)opCode;

            code &= 0xfcff;
            var result = code | ((ushort)destFlag << 8);

            return((MaskedOpCode )result);
        }
예제 #6
0
        private string Format(OpCodeFlag opCodeFlag)
        {
            switch (opCodeFlag)
            {
                case OpCodeFlag.Constant:
                    return Signed ? "+0" : "0x0";

                case OpCodeFlag.Register:
                    return Signed ? "+rX" : "rX";

                case OpCodeFlag.MemoryAddress:
                    return Signed ? "+[rX]" : "[rX]";
            }

            throw new ArgumentOutOfRangeException(nameof(opCodeFlag));
        }
예제 #7
0
        private static void WriteValue(Cpu cpu, OpCodeFlag flag, uint param, uint value)
        {
            switch (flag)
            {
            case OpCodeFlag.Register:
                cpu.Registers[param] = value;
                break;

            case OpCodeFlag.MemoryAddress:
                cpu.Write(cpu.Registers[param], value);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(flag));
            }
        }
예제 #8
0
        private string Format(OpCodeFlag opCodeFlag)
        {
            switch (opCodeFlag)
            {
            case OpCodeFlag.Constant:
                return(Signed ? "+0" : "0x0");

            case OpCodeFlag.Register:
                return(Signed ? "+rX" : "rX");

            case OpCodeFlag.MemoryAddress:
                return(Signed ? "+[rX]" : "[rX]");
            }

            throw new ArgumentOutOfRangeException(nameof(opCodeFlag));
        }
예제 #9
0
        private static uint ReadValue(Cpu cpu, OpCodeFlag flag, uint param)
        {
            switch (flag)
            {
            case OpCodeFlag.Register:
                return(cpu.Registers[param]);

            case OpCodeFlag.MemoryAddress:
                return(cpu.Read(cpu.Registers[param]));

            case OpCodeFlag.Constant:
                return(param);

            default:
                throw new ArgumentOutOfRangeException(nameof(flag));
            }
        }
예제 #10
0
 private byte Dest(OpCodeFlag flag)
 {
     return (byte) flag;
 }
예제 #11
0
        public static MaskedOpCode SetSource(this MaskedOpCode opCode, OpCodeFlag sourceFlag)
        {
            var code = (ushort)opCode;
            code &= 0xf3ff;
            var result = code | ((ushort)sourceFlag << 10);

            return (MaskedOpCode)result;
        }
예제 #12
0
        public static MaskedOpCode SetDest(this MaskedOpCode opCode, OpCodeFlag destFlag)
        {
            if (destFlag == OpCodeFlag.Constant)
                throw new InvalidOperationException("Cannot set constant as destination vector");

            var code = (ushort) opCode;
            code &= 0xfcff;
            var result = code | ((ushort)destFlag << 8);

            return (MaskedOpCode )result;
        }
예제 #13
0
 private byte Source(OpCodeFlag flag)
 {
     return (byte)((byte)flag << 0x2);
 }
예제 #14
0
 private byte Source(OpCodeFlag flag)
 {
     return((byte)((byte)flag << 0x2));
 }
예제 #15
0
        private static void ParseArgument([NotNull] IInstructionFetcher fetcher, OpCodeFlag flag, out int argument, out int argumentValue, out int argumentDisplacement, int argumentType, byte modrm)
        {
            var mod = (byte)((modrm >> 6) & 7);
            var reg = (byte)((modrm >> 3) & 7);
            var rm  = (byte)(modrm & 7);

            switch (argumentType)
            {
            case ARG_AX:
            case ARG_CX:
            case ARG_DX:
            case ARG_BX:
            case ARG_SP:
            case ARG_BP:
            case ARG_SI:
            case ARG_DI:
            case ARG_IP:
            case ARG_CS:
            case ARG_DS:
            case ARG_ES:
            case ARG_SS:
            case ARG_FLAGS:
                argument             = argumentType;
                argumentValue        = ARG_NONE;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_AL:
            case ARG_CL:
            case ARG_DL:
            case ARG_BL:
            case ARG_AH:
            case ARG_CH:
            case ARG_DH:
            case ARG_BH:
                argument             = ARG_BYTE_REGISTER;
                argumentValue        = argumentType;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_1:
                argument             = ARG_CONSTANT;
                argumentValue        = 1;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_3:
                argument             = ARG_CONSTANT;
                argumentValue        = 3;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_IB:
                argument             = ARG_CONSTANT;
                argumentValue        = fetcher.FetchU8();
                argumentDisplacement = ARG_NONE;
                if (flag.Has(OpCodeFlag.Signed))
                {
                    argumentValue = (sbyte)(byte)argumentValue;
                }
                break;

            case ARG_IW:
                argument             = ARG_CONSTANT;
                argumentValue        = fetcher.FetchU16();
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_JB:
                argument             = ARG_CONSTANT;
                argumentValue        = (sbyte)fetcher.FetchU8();
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_JW:
                argument             = ARG_CONSTANT;
                argumentValue        = fetcher.FetchU16();
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_S:
                Debug.Assert(reg < 4);
                argument             = reg + ARG_ES;
                argumentValue        = ARG_NONE;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_GB:
                argument             = ARG_BYTE_REGISTER;
                argumentValue        = ARG_AL + reg;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_GW:
                argument             = reg;
                argumentValue        = ARG_NONE;
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_OB:
            case ARG_OW:
                argument             = ARG_MEMORY;
                argumentValue        = fetcher.FetchU16();
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_A:
                argument = ARG_FAR_MEMORY;
                var address = fetcher.FetchU16();
                var segment = fetcher.FetchU16();
                argumentValue        = (int)(((uint)segment << 16) | address);
                argumentDisplacement = ARG_NONE;
                break;

            case ARG_EB:
            case ARG_EW:
            case ARG_M:
                switch (mod)
                {
                case 0:
                    if (rm == 6)
                    {
                        argument             = ARG_MEMORY;
                        argumentValue        = fetcher.FetchU16();
                        argumentDisplacement = ARG_NONE;
                    }
                    else
                    {
                        argument             = ARG_DEREFERENCE;
                        argumentValue        = rm;
                        argumentDisplacement = 0;
                    }
                    break;

                case 1:
                    argument             = ARG_DEREFERENCE;
                    argumentValue        = rm;
                    argumentDisplacement = (sbyte)fetcher.FetchU8();
                    break;

                case 2:
                    argument             = ARG_DEREFERENCE;
                    argumentValue        = rm;
                    argumentDisplacement = fetcher.FetchU16();
                    break;

                case 3:
                    Debug.Assert(argumentType != ARG_M);
                    if (argumentType == ARG_EB)
                    {
                        argument      = ARG_BYTE_REGISTER;
                        argumentValue = ARG_AL + rm;
                    }
                    else
                    {
                        argument      = rm;
                        argumentValue = ARG_NONE;
                    }
                    argumentDisplacement = ARG_NONE;
                    break;

                default:
                    throw new NotImplementedException();
                }
                break;

            case ARG_NONE:
                argument             = ARG_NONE;
                argumentValue        = ARG_NONE;
                argumentDisplacement = ARG_NONE;
                break;

            default:
                throw new NotImplementedException();
            }
        }
예제 #16
0
 private static void WriteValue(Cpu cpu, OpCodeFlag flag, uint param, uint value)
 {
     switch (flag)
     {
         case OpCodeFlag.Register:
             cpu.Registers[param] = value;
             break;
         case OpCodeFlag.MemoryAddress:
             cpu.Write(cpu.Registers[param], value);
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(flag));
     }
 }
예제 #17
0
 private static uint ReadValue(Cpu cpu, OpCodeFlag flag, uint param)
 {
     switch (flag)
     {
         case OpCodeFlag.Register:
             return cpu.Registers[param];
         case OpCodeFlag.MemoryAddress:
             return cpu.Read(cpu.Registers[param]);
         case OpCodeFlag.Constant:
             return param;
         default:
             throw new ArgumentOutOfRangeException(nameof(flag));
     }
 }
예제 #18
0
 private byte Dest(OpCodeFlag flag)
 {
     return((byte)flag);
 }
예제 #19
0
파일: Cpu.cs 프로젝트: andy-uq/TinyOS
 public void Input(DeviceId deviceId, OpCodeFlag flag, uint rX)
 {
     if (Enum.IsDefined(typeof (DeviceId), deviceId))
     {
         DeviceReadQueue.Enqueue(deviceId, CurrentProcess, flag, rX);
         CurrentProcess = null;
     }
     else
     {
         CurrentProcess.Zf = true;
     }
 }
예제 #20
0
 private byte Flags(OpCodeFlag dest, OpCodeFlag source)
 {
     return (byte) (((byte) source << 0x2) | (byte) dest);
 }
예제 #21
0
 private byte Flags(OpCodeFlag dest, OpCodeFlag source)
 {
     return((byte)(((byte)source << 0x2) | (byte)dest));
 }