示例#1
0
        /// <summary>
        /// Freezes the system.
        /// Usually used after a crash to display information after which the user
        /// can turn of the machine.
        /// </summary>
        public static void Freeze()
        {
            // Disable interrupts
            Asm.CLI();

            // Halt the system
            Asm.HLT();
        }
示例#2
0
        /// <summary>
        /// Puts the system into sleep mode.
        /// </summary>
        public static void Sleep()
        {
            // TODO: eventually implement this..

            // Disable interrupts
            Asm.CLI();

            // Halt the system
            Asm.HLT();
        }
示例#3
0
        /// <summary>
        /// Powers down the system.
        /// </summary>
        public static void PowerOff()
        {
            // TODO: turn off system here..

            // Disable interrupts
            Asm.CLI();

            // Halt the system
            Asm.HLT();
        }
示例#4
0
        public static byte Read(Address address)
        {
            Asm.CLI();
            IO.WriteByte(IO.Port.RTC_CommandPort, (byte)(0x80 | (byte)address));
            Asm.NOP();
            Asm.NOP();
            Asm.NOP();
            byte result = IO.ReadByte(IO.Port.RTC_DataPort);

            Asm.STI();
            return(result);
        }
示例#5
0
        /*
         * private static uint ReadCR0()
         * {
         *      uint val = 0;
         *
         *      Asm.PUSH (R32.EAX);
         *      Asm.MOV (R32.EAX, CR.CR0);
         *      Asm.MOV (&val, R32.EAX);
         *      Asm.POP (R32.EAX);
         *
         *      return val;
         * }
         *
         * private static void *ReadCR3()
         * {
         *      uint val = 0;
         *
         *      Asm.PUSH (R32.EAX);
         *      Asm.MOV (R32.EAX, CR.CR3);
         *      Asm.MOV (&val, R32.EAX);
         *      Asm.POP (R32.EAX);
         *
         *      return (void*)val;
         * }
         *
         * private unsafe static void WriteCR0 (uint value)
         * {
         *      Asm.PUSH (R32.EAX);
         *      Asm.MOV (R32.EAX, &value);
         *      Asm.MOV (CR.CR0, R32.EAX);
         *      Asm.POP (R32.EAX);
         * }
         *
         * private static void WriteCR3 (uint ptr)
         * {
         *      Asm.PUSH (R32.EAX);
         *      Asm.MOV (R32.EAX, &ptr);
         *      Asm.MOV (CR.CR3, R32.EAX);
         *      Asm.POP (R32.EAX);
         * }
         */

        private static void SetDirectory(uint page)
        {
            Asm.CLI();

            Asm.PUSH(R32.EAX);
            Asm.PUSH(R32.ECX);

            Asm.MOV(R32.EAX, &page);

            Asm.MOV(R32.ECX, CR.CR0);
            Asm.OR(R32.ECX, (uint)CR0Flags.PG);

            Asm.MOV(CR.CR3, R32.EAX);
            Asm.MOV(CR.CR0, R32.ECX);

            Asm.POP(R32.ECX);
            Asm.POP(R32.EAX);

            Asm.STI();
        }
示例#6
0
        /// <summary>
        /// Reboot the system.
        /// We can reset the system, oddly enough, through the keyboard IO port
        /// </summary>
        public static void Reboot()
        {
            // Disable interrupts
            Asm.CLI();

            // Clear all keyboard buffers (output and command buffers)
            byte temp;

            do
            {
                temp = IO.ReadByte(IO.Port.KB_controller_commands);
                if ((temp & 0x01) != 0)
                {
                    IO.ReadByte(IO.Port.KB_data_port);                      // Empty keyboard buffer
                }
            } while ((temp & 0x02) != 0);

            // Reset the system
            IO.WriteByte(IO.Port.KB_controller_commands, 0xFE);

            // Halt the system (in case reset didn't work)
            Asm.HLT();
        }
示例#7
0
 /// <summary>
 ///		Starts the barrier, no other threads can run untill Exit is called
 /// </summary>
 /// <remarks>
 ///		This function should be made "inline" by the AOT
 /// </remarks>
 public static void Enter()
 {
     Asm.CLI();
 }
示例#8
0
        internal Processor(uint _index)
        {
            Asm.CLI();

            index = _index;

            bool haveCPU = HaveCPUID();

            if (!haveCPU)
            {
                archType   = ProcessorType.IA32;
                vendorName = CString8.Copy("Unknown");
                brandName  = CString8.Copy("Unknown");
                familyName = CString8.Copy("Unknown");
                modelName  = CString8.Copy("Unknown");
            }
            if (haveCPU)
            {
                UInt32 stepping;
                UInt32 family;
                UInt32 model;

                textBuffer = StringBuilder.CREATE((uint)(20));
                vendorName = GetVendorName();

                if (vendorName->Compare("GenuineIntel", 12) == 0)
                {
                    SetIntel();
                }
                else
                if (vendorName->Compare("AuthenticAMD", 12) == 0)
                {
                    SetAMD();
                }
                else
                {
                    brandName  = GetBrandName();
                    familyName = CString8.Copy("Not implemented yet");
                    modelName  = CString8.Copy("Not implemented yet");
                }

                GetProcessorInfo(out stepping, out family, out model, out featureFlags);

                if (0 != (featureFlags & ProcessorFeatureFlags.IA64))
                {
                    archType = ProcessorType.IA64;
                }
                else
                {
                    archType = ProcessorType.IA32;
                }

                ulong flags        = ((ulong)featureFlags) & ((ulong)ProcessorFeatureFlags.ReservedFlagsMask);
                uint  featureCount = MemoryUtil.BitCount(flags);

                features     = new ProcessorFeature[featureCount];
                featureCount = 0;

                // TODO: this could be improved upon if we had:
                //	constructor support
                //	enum.ToString support
                // etc.
                if (0 != (flags & (ulong)ProcessorFeatureFlags.FPU))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("FPU"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.VME))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("VME"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.DE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("DE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PSE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PSE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.TSC))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("TSC"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MSR))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MSR"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PAE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PAE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MCE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MCE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.CX8))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("CX8"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.APIC))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("APIC"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SEP))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SEP"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MTRR))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MTRR"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PGE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PGE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MCA))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MCA"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.CMOV))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("CMOV"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PAT))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PAT"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PSE36))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PSE36"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PSN))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PSN"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.CLFSH))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("CLFSH"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.DTES))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("DTES"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.ACPI))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("ACPI"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MMX))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MMX"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.FXSR))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("FXSR"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSE2))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSE2"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SS))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SS"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.HTT))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("HTT"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.TM1))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("TM1"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.IA64))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("IA64"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PBE))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PBE"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSE3))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSE3"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.DTSE64))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("DTSE64"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.MON))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("MON"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.DSCPL))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("DSCPL"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.VMX))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("VMX"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SMX))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SMX"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.EST))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("EST"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.TM2))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("TM2"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSSE3))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSSE3"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.CID))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("CID"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.CX16))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("CX16"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.ETPRD))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("ETPRD"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.PDCM))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("PDCM"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.DCA))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("DCA"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSE4_1))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSE4.1"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.SSE4_2))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("SSE4.2"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.X2APIC))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("X2APIC"); featureCount++;
                }
                if (0 != (flags & (ulong)ProcessorFeatureFlags.POPCNT))
                {
                    features[featureCount] = new ProcessorFeature(); features[featureCount].FeatureName = ("POPCNT"); featureCount++;
                }
            }
            Asm.STI();
        }