Пример #1
0
 public MachineRegister(string name, int code, int bits, MachineSpec spec)
 {
     Name = name;
     Code = code;
     Bits = bits;
     InstructionSets.Add(spec);
 }
Пример #2
0
 public MachineRegister(string name, int code, MachineRegisterType type, MachineSpec spec)
 {
     Name         = name;
     Code         = code;
     RegisterType = type;
     Bits         = type.Bits;
     InstructionSets.Add(spec);
 }
 public CoatingSchedule()
 {
     foreach (string line in StaticFactoryValuesManager.CoatingLines)
     {
         InstructionSets.Add(new CoatingLineInstructionSet(line));
     }
     CurrentSchedule = this;
 }
Пример #4
0
        private void CompileClassStmt(ClassStatement stmt, Scope scope)
        {
            scope = new Scope {
                Out = scope, LocalTable = new LocalTable(), Self = stmt, Line = 0
            };
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.LabelDefClass}:{stmt.Name.Value}");

            CompileBlockStatement(instructionSet, stmt.Body, scope, scope.LocalTable);
            instructionSet.Define(InstructionType.Leave);
            InstructionSets.Add(instructionSet);
        }
Пример #5
0
        private void CompileBlockArgExpression(int index, CallExpression exp, Scope scope, LocalTable table)
        {
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.Block}:{index}");

            for (int i = 0; i < exp.Arguments.Count; i++)
            {
                table.Set(exp.BlockArguments[i].Value);
            }

            CompileBlockStatement(instructionSet, exp.Block, scope, table);
            EndInstructions(instructionSet);
            InstructionSets.Add(instructionSet);
        }
Пример #6
0
        private void CompileStatements(List <IStatement> statements, Scope scope, LocalTable localTable)
        {
            var instructionSet = new InstructionSet {
                Label = new Label {
                    Name = InstructionType.Program
                }
            };

            foreach (var statement in statements)
            {
                CompileStatement(instructionSet, statement, scope, localTable);
            }

            EndInstructions(instructionSet);
            InstructionSets.Add(instructionSet);
        }
Пример #7
0
        public MethodReplacement(MethodBase method, Platform platform, InstructionSets instructionSet, byte[][] compiledData)
        {
            if (method == null)
                throw new ArgumentNullException("method");
            if (compiledData == null || compiledData.Length == 0)
                throw new ArgumentNullException("compiledData");

            foreach (var chunk in compiledData)
            {
                if (chunk == null || chunk.Length == 0)
                    throw new ArgumentException("Data chunk is null or empty.");
            }

            Method = method;
            Platform = platform;
            InstructionSet = instructionSet;
            CompiledData = compiledData;
        }
Пример #8
0
        private void CompileDefStmt(DefStatement stmt, Scope scope)
        {
            scope = new Scope {
                Out = scope, LocalTable = new LocalTable(), Self = stmt, Line = 0
            };
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.LabelDef}:{stmt.Name.Value}");

            for (int i = 0; i < stmt.Parameters.Count; i++)
            {
                scope.LocalTable.SetLCL(stmt.Parameters[i].Value, scope.LocalTable.Depth);
            }

            CompileBlockStatement(instructionSet, stmt.BlockStatement, scope, scope.LocalTable);
            EndInstructions(instructionSet);
            InstructionSets.Add(instructionSet);
        }
Пример #9
0
 public bool HasTarget(InstructionSets target)
 {
     return(NativeTargets.Contains(target));
 }
Пример #10
0
        static CpuInformation()
        {
            CPUInfo info = NativeMethods.cpuid(0);
            Manufacturer = Encoding.ASCII.GetString(BitConverter.GetBytes(info[1])) +
                Encoding.ASCII.GetString(BitConverter.GetBytes(info[3])) + Encoding.ASCII.GetString(BitConverter.GetBytes(info[2]));

            info = NativeMethods.cpuid(1);
            SteppingID = info[0] & 0xf;
            Model = (info[0] >> 4) & 0xf;
            Family = (info[0] >> 8) & 0xf;
            ProcessorType = (info[0] >> 12) & 0x3;
            ExtendedModel = (info[0] >> 16) & 0xf;
            ExtendedFamily = (info[0] >> 20) & 0xff;
            BrandIndex = info[1] & 0xff;
            CFLUSHCacheLineSize = ((info[1] >> 8) & 0xff) * 8;
            LogicalProcessorCount = ((info[1] >> 16) & 0xff);
            APICPhysicalID = (info[1] >> 24) & 0xff;
            Features = CpuFeatures.None;
            ExtraInstructions = ExtraInstructions.None;
            InstructionSets = InstructionSets.None;

            if ((info[2] & 0x1) != 0)
                InstructionSets |= InstructionSets.SSE3;
            if ((info[2] & 0x8) != 0)
                ExtraInstructions |= ExtraInstructions.MONITOR | ExtraInstructions.MWAIT;
            if ((info[2] & 0x10) != 0)
                Features |= CpuFeatures.CPLQualifiedDebugStore;
            if ((info[2] & 0x20) != 0)
                Features |= CpuFeatures.VirtualMachineExtensions;
            if ((info[2] & 0x40) != 0)
                Features |= CpuFeatures.SaferModeExtensions;
            if ((info[2] & 0x80) != 0)
                Features |= CpuFeatures.EnhancedIntelSpeedStepTechnology;
            if ((info[2] & 0x100) != 0)
                Features |= CpuFeatures.ThermalMonitor2;
            if ((info[2] & 0x200) != 0)
                InstructionSets |= InstructionSets.SSSE3;
            if ((info[2] & 0x300) != 0)
                Features |= CpuFeatures.L1ContextID;
            if ((info[2] & 0x1000) != 0)
                InstructionSets |= InstructionSets.FMA;
            if ((info[2] & 0x2000) != 0)
                ExtraInstructions |= ExtraInstructions.CMPXCHG16B;
            if ((info[2] & 0x4000) != 0)
                Features |= CpuFeatures.XtprUpdateControl;
            if ((info[2] & 0x8000) != 0)
                Features |= CpuFeatures.PerfDebugCapabilities;
            if ((info[2] & 0x40000) != 0)
                Features |= CpuFeatures.DirectCacheAccess;
            if ((info[2] & 0x80000) != 0)
                InstructionSets |= InstructionSets.SSE41;
            if ((info[2] & 0x100000) != 0)
                InstructionSets |= InstructionSets.SSE42;
            if ((info[2] & 0x200000) != 0)
                Features |= CpuFeatures.X2APIC;
            if ((info[2] & 0x400000) != 0)
                ExtraInstructions |= ExtraInstructions.MOVBE;
            if ((info[2] & 0x800000) != 0)
                ExtraInstructions |= ExtraInstructions.POPCNT;
            if ((info[2] & 0x2000000) != 0)
                InstructionSets |= InstructionSets.AES;
            if ((info[2] & 0x4000000) != 0)
                ExtraInstructions |= ExtraInstructions.XSAVE;
            if ((info[2] & 0x8000000) != 0)
                ExtraInstructions |= ExtraInstructions.OSXSAVE;
            if ((info[2] & 0x10000000) != 0)
                InstructionSets |= InstructionSets.AVX;

            int featureInfo = info[3];
            for (int i = 0; i < 32; i++)
            {
                int n = 1 << i;
                if ((featureInfo & n) != 0)
                {
                    switch (i)
                    {
                        case 5: ExtraInstructions |= ExtraInstructions.RDMSR | ExtraInstructions.WRMSR; break;
                        case 8: ExtraInstructions |= ExtraInstructions.CMPXCHG8B; break;
                        case 11: ExtraInstructions |= ExtraInstructions.SYSENTER | ExtraInstructions.SYSEXIT; break;
                        case 15: ExtraInstructions |= ExtraInstructions.CMOV; break;
                        case 19: ExtraInstructions |= ExtraInstructions.CFLUSH; break;
                        case 23: InstructionSets |= InstructionSets.MMX; break;
                        case 24: ExtraInstructions |= ExtraInstructions.FXSAVE | ExtraInstructions.FXRSTOR; break;
                        case 25: InstructionSets |= InstructionSets.SSE; break;
                        case 26: InstructionSets |= InstructionSets.SSE2; break;
                        default: Features |= (CpuFeatures)n; break;
                    }
                }
            }

            byte[] brand = new byte[64];
            info = NativeMethods.cpuid(0x80000000);
            long extendedIds = (uint)info[0];
            int index = 0;

            for (uint i = 0x80000000; i <= extendedIds; i++)
            {
                info = NativeMethods.cpuid(i);
                if (i >= 0x80000002 && i <= 0x80000004)
                {
                    Array.Copy(BitConverter.GetBytes(info[0]), 0, brand, index, 4); index += 4;
                    Array.Copy(BitConverter.GetBytes(info[1]), 0, brand, index, 4); index += 4;
                    Array.Copy(BitConverter.GetBytes(info[2]), 0, brand, index, 4); index += 4;
                    Array.Copy(BitConverter.GetBytes(info[3]), 0, brand, index, 4); index += 4;
                }
                else if (i == 0x80000001)
                {
                    if ((info[2] & 0x1) != 0)
                        Features |= CpuFeatures.LAHF_SAHFAvailableIn64Bit;
                    if ((info[2] & 0x2) != 0)
                        Features |= CpuFeatures.CoreMultiprocessingLegacyMode;
                    if ((info[2] & 0x4) != 0)
                        Features |= CpuFeatures.SecureVirtualMachine;
                    if ((info[2] & 0x8) != 0)
                        Features |= CpuFeatures.ExtendedAPICRegisterSpace;
                    if ((info[2] & 0x10) != 0)
                        ExtraInstructions |= ExtraInstructions.AltMovCr8;
                    if ((info[2] & 0x20) != 0)
                        ExtraInstructions |= ExtraInstructions.LZCNT;
                    if ((info[2] & 0x40) != 0)
                        InstructionSets |= InstructionSets.SSE4A;
                    if ((info[2] & 0x80) != 0)
                        Features |= CpuFeatures.MisalignedSSESupport;
                    if ((info[2] & 0x100) != 0)
                        ExtraInstructions |= ExtraInstructions.PREFETCH;
                    if ((info[2] & 0x1000) != 0)
                        ExtraInstructions |= ExtraInstructions.SKINIT | ExtraInstructions.DEV;
                    if ((info[3] & 0x800) != 0)
                        Features |= CpuFeatures.SyscallAvailableIn64Bit;
                    if ((info[3] & 0x10000) != 0)
                        Features |= CpuFeatures.ExecuteDisableBitAvailable;
                    if ((info[3] & 0x40000) != 0)
                        InstructionSets |= InstructionSets.MMXEx;
                    if ((info[3] & 0x200000) != 0)
                        ExtraInstructions |= ExtraInstructions.FFXSR;
                    if ((info[3] & 0x400000) != 0)
                        Features |= CpuFeatures.PageSupport1GB;
                    if ((info[3] & 0x8000000) != 0)
                        ExtraInstructions |= ExtraInstructions.RDTCSP;
                    if ((info[3] & 0x20000000) != 0)
                        Features |= CpuFeatures.Supports64Bit;
                    if ((info[3] & 0x40000000) != 0)
                        InstructionSets |= InstructionSets.Amd3DNowEx;
                    if ((info[3] & 0x80000000) != 0)
                        InstructionSets |= InstructionSets.Amd3DNow;
                }
            }

            if (index != 0)
                Brand = Encoding.ASCII.GetString(brand, 0, index);
        }