Пример #1
0
        public static bool TransferIn(byte channel, void *source, uint count)
        {
            if (count > (1024 * 64))
            {
                return(false);
            }

            uint address = (uint)GetDMATranserAddress(channel);

            if (address == 0x00)
            {
                return(false);
            }

            MemoryUtil.MemCopy((uint)source, address, count);

            return(true);
        }
Пример #2
0
        public static bool TransferOut(byte channel, void *destination, uint count)
        {
            if (count > (1024 * 64))
            {
                return(false);
            }

            uint address = (uint)GetDMATranserAddress(channel);

            if (address == 0x00)
            {
                return(false);
            }

            MemoryUtil.MemCopy(address, (uint)destination, count);

            return(true);
        }
Пример #3
0
        private static unsafe void TimerHandler(IDT.ISRData data)
        {
            ticks++;

            for (int x = 0; x < EntryModule.MaxEventHandlers; ++x)
            {
                if (timerEvent[x] == 0)
                {
                    continue;
                }

                MemoryUtil.Call(timerEvent[x], ticks);
            }


            SharpOS.Kernel.ADC.Thread thread = Dispatcher.Dispatch((void *)data.Stack);
            if (thread != null)
            {
                IDT.Stack *newStack = (IDT.Stack *)thread.StackPointer;
                newStack->IrqIndex = data.Stack->IrqIndex;
                data.Stack         = newStack;
            }
        }
Пример #4
0
        public static PageAllocator.Errors Setup(uint totalMem, byte *pagemap, uint pagemapLen, PageAllocator.Errors *error)
        {
            if (pagemap == null ||
                pagemapLen < ComputeControlReq(totalMem))
            {
                *error = PageAllocator.Errors.UnusablePageControlBuffer;
                return(*error);
            }

            uint totalBytes = totalMem * 1024;                  // more intuitive to think in bytes than in kibibytes

            PageDirectory = (uint *)pagemap;
            PageTables    = (uint *)(((byte *)PageDirectory) + 4096);

            uint  addr  = 0;
            uint *table = (uint *)PageTables;

            // Page directory needs to span all 4 GBs
            // FIXME: What about PAE support might different implementation
            // uint totalPages = UInt32.MaxValue / 4096; // Each page spans of memory 4MB
            uint totalTables = 1024;             // 1024 * 4MB = 4GB

            MemoryUtil.MemSet32(0, (uint)PageDirectory, 1024);

            for (int x = 0; x < totalTables; ++x)
            {
                bool needsDirectoryPresent = false;

                for (int i = 0; i < 1024; ++i)
                {
                    uint val = (addr & (uint)PageAttr.FrameMask) |
                               (uint)(PageAttr.ReadWrite);

                    if (addr <= totalBytes)
                    {
                        val |= (uint)PageAttr.Present;
                        needsDirectoryPresent = true;
                    }

                    table[i] = val;
                    addr    += 4096;
                }

                // top-level page directory (level-1)
                uint pageAddress = (uint)table & (uint)PageAttr.FrameMask;

                // Make direcory read/write enabled
                pageAddress |= (uint)PageAttr.ReadWrite;

                if (needsDirectoryPresent)
                {
                    // Make directory present if its point to a physical memory already
                    pageAddress |= (uint)PageAttr.Present;
                }

                PageDirectory[x] = pageAddress;

                table += 1024;                  // 1024 x sizeof(int) = 4k
            }

            DMA.Setup((byte *)((uint)pagemap) + pagemapLen);

            *error = PageAllocator.Errors.Success;
            return(*error);
        }
Пример #5
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();
        }
Пример #6
0
        static unsafe void KeyboardHandler(IDT.ISRData data)
        {
            // Read from the keyboard's data buffer
            byte input;
            uint scancode;
            bool pressed;

            input = IO.ReadByte(IO.Port.KB_data_port);

            /* XXX: why is this commented out?
             *
             * if (input == KeyboardMessages.Too_Many_Keys ||
             *      input == KeyboardMessages.Keyboard_Error)
             * {
             *      // TODO: do something usefull here..
             *      return;
             * }
             *
             */

            if (input == 0xe0)
            {
                input    = IO.ReadByte(IO.Port.KB_data_port);
                scancode = (uint)((input & 0x7F) >> 8) | 0xe0;
                pressed  = (input & 0x80) == 0;
            }
            else if (input == 0xe1)
            {
                input    = IO.ReadByte(IO.Port.KB_data_port);
                scancode = (uint)(input & 0x7F);
                pressed  = (input & 0x80) == 0;
                return;
            }
            else
            {
                scancode = (uint)(input & 0x7F);
                pressed  = (input & 0x80) == 0;
            }

            if (scancode == (uint)Keys.CapsLock)                                                // CapsLock
            {
                if (pressed)
                {
                    if (capsLockReleased)
                    {
                        capsLock = !capsLock;
                    }
                    capsLockReleased = false;
                    SetLEDs();
                }
                else
                {
                    capsLockReleased = true;
                }
                return;
            }
            else if (scancode == (uint)Keys.NumLock)                                    // NumLock
            {
                if (pressed)
                {
                    if (numLockReleased)
                    {
                        numLock = !numLock;
                    }
                    numLockReleased = false;
                    SetLEDs();
                }
                else
                {
                    numLockReleased = true;
                }
                return;
            }
            else if (scancode == (uint)Keys.ScrollLock)                                         // ScrollLock
            {
                if (pressed)
                {
                    if (scrollLockReleased)
                    {
                        scrollLock = !scrollLock;
                    }
                    scrollLockReleased = false;
                    SetLEDs();
                }
                else
                {
                    scrollLockReleased = true;
                }
                return;
            }
            else if (scancode == (uint)Keys.LeftControl)                                 // left control
            {
                leftControl = pressed;
                return;
            }
            else if (scancode == (uint)Keys.LeftShift)                   // left shift
            {
                leftShift = pressed;
                return;
            }
            else if (scancode == (uint)Keys.LeftAlt)                     // left alt
            {
                leftAlt = pressed;
                return;
            }
            else if (scancode == (uint)Keys.RightAlt)                  // right alt
            {
                rightAlt = pressed;
                return;
            }
            else if (scancode == (uint)Keys.RightControl)                  // right control
            {
                rightControl = pressed;
                return;
            }
            else if (scancode == (uint)Keys.RightShift)                  // right shift
            {
                rightShift = pressed;
                return;
            }

            if (pressed)
            {
                for (int x = 0; x < EntryModule.MaxEventHandlers; ++x)
                {
                    if (keyDownEvent [x] == 0)
                    {
                        continue;
                    }

                    MemoryUtil.Call(keyDownEvent [x], scancode);
                }
            }
            else
            {
                for (int x = 0; x < EntryModule.MaxEventHandlers; ++x)
                {
                    if (keyUpEvent [x] == 0)
                    {
                        continue;
                    }

                    MemoryUtil.Call(keyUpEvent [x], scancode);
                }
            }
        }