示例#1
0
文件: Mouse.cs 项目: zer09/Cosmos
        /// <summary>
        /// This is the required call to start
        /// the mouse receiving interrupts.
        /// </summary>
        public void Initialize(uint screenWidth, uint screenHeight)
        {
            ScreenWidth  = screenWidth;
            ScreenHeight = screenHeight;

            ////enable mouse
            WaitSignal();
            BaseIOGroups.Mouse.p64.Byte = (byte)0xA8;

            //// enable interrupt
            WaitSignal();
            BaseIOGroups.Mouse.p64.Byte = (byte)0x20;
            WaitData();
            //byte status1 = (byte)(BaseIOGroups.Mouse.p60.Byte);
            byte status = (byte)(BaseIOGroups.Mouse.p60.Byte | 2);

            WaitSignal();
            BaseIOGroups.Mouse.p64.Byte = (byte)0x60;
            WaitSignal();
            BaseIOGroups.Mouse.p60.Byte = (byte)status;

            ////default
            Write(0xF6);
            Read();  //Acknowledge

            ////Enable the mouse
            Write(0xF4);
            Read();  //Acknowledge

            //Set the IRQ 12, to the method HandleMouse
            INTs.SetIrqHandler(12, HandleMouse);
        }
示例#2
0
        /// <summary>
        /// This is the required call to start
        /// the mouse receiving interrupts.
        /// </summary>
        public override void Initialize()
        {
            SendCommand(Command.Reset);
            mPS2Controller.WaitForDeviceReset();

            if (mMouseID == 0)
            {
                mMouseID = TryToEnableScrollWheel();

                mDebugger.SendInternal("(PS/2 Mouse) Mouse ID: " + mMouseID);

                if (mMouseID == 3)
                {
                    mMouseID = TryToEnableAdditionalButtons();
                }

                mDebugger.SendInternal("(PS/2 Mouse) Mouse ID: " + mMouseID);
            }

            //SendCommand(Command.SetDefaults);
            //mPS2Controller.WaitForAck();

            INTs.SetIrqHandler(12, HandleMouse);

            SendCommand(Command.EnablePacketStreaming);
            mPS2Controller.WaitForAck();
        }
示例#3
0
        // Bootstrap is a class designed only to get the essentials done.
        // ie the stuff needed to "pre boot". Do only the very minimal here.
        // IDT, PIC, and Float
        // Note: This is changing a bit GDT (already) and IDT are moving to a real preboot area.
        public static void Init()
        {
            // Drag this stuff in to the compiler manually until we add the always include attrib
            INTs.Dummy();

            PIC = new PIC();
            CPU.UpdateIDT(true);

            /* TODO check using CPUID that SSE2 is supported */
            CPU.InitSSE();

            /*
             * We liked to use SSE for all floating point operation and end to mix SSE / x87 in Cosmos code
             * but sadly in x86 this resulte impossible as Intel not implemented some needed instruction (for example conversion
             * for long to double) so - in some rare cases - x87 continue to be used. I hope passing to the x32 or x64 IA will solve
             * definively this problem.
             */
            CPU.InitFloat();

            header = (Multiboot.Header *)Multiboot.GetMBIAddress();

            modeinfo       = (Core.VBE.ModeInfo *)header->vbeModeInfo;
            controllerinfo = (Core.VBE.ControllerInfo *)header->vbeControlInfo;

            // Managed_Memory_System.ManagedMemory.Initialize();
            // Managed_Memory_System.ManagedMemory.SetUpMemoryArea();
        }
        /// <summary>
        /// This is the required call to start
        /// the mouse receiving interrupts.
        /// </summary>
        public static void Initialize()
        {
            ////enable mouse
            WaitSignal();
            g.p64.Byte = (byte)0xA8;

            //// enable interrupt
            WaitSignal();
            g.p64.Byte = (byte)0x20;
            WaitData();
            //byte status1 = (byte)(g.p60.Byte);
            byte status = (byte)(g.p60.Byte | 2);

            WaitSignal();
            g.p64.Byte = (byte)0x60;
            WaitSignal();
            g.p60.Byte = (byte)status;

            ////default
            Write(0xF6);
            Read();  //Acknowledge

            ////Enable the mouse
            Write(0xF4);
            Read();  //Acknowledge

            INTs.SetIrqHandler(12, HandleMouse);
            //Console.WriteLine("INSTALLED");
        }
示例#5
0
文件: ATAPI.cs 项目: nifanfa/Cosmos
        /// <summary>
        /// Check if ATAPI-speclevel device is on Primary or Secondary channel,
        /// and register the appropriate interrupt
        /// </summary>
        public void Init()
        {
            if (Primary)
            {
                INTs.SetIrqHandler(0x0E, HandleIRQ);
            }
            else
            {
                INTs.SetIrqHandler(0x0F, HandleIRQ);
            }

            IO.Control.Byte = 0; //Enable IRQs
        }
示例#6
0
        public override void Initialize()
        {
            SendCommand(Command.Reset);
            mPS2Controller.WaitForDeviceReset();

            //VMWare doesn't support the Get/SetScanCode command
            //mDebugger.SendInternal("(PS/2 Keyboard) Current scan code set: " + GetScanCodeSet());
            //SetScanCodeSet(1);
            //mDebugger.SendInternal("(PS/2 Keyboard) Current scan code set: " + GetScanCodeSet());

            INTs.SetIrqHandler(1, HandleIRQ);

            SendCommand(Command.EnableScanning);

            Global.mDebugger.SendInternal("(PS/2 Keyboard) Initialized");
        }
示例#7
0
        public Intel8254X(PCIDevice dev)
        {
            this.dev = dev;
            dev.EnableDevice();
            BAR0 = (uint)(dev.BAR0 & (~3));
            INTs.SetIrqHandler(dev.InterruptLine, HandleIRQ);

            var HasEEPROM = DetectEEPROM();

            //Read the mac address
            if (!HasEEPROM)
            {
                address = new MACAddress(new byte[] { Read1ByteRegister(BAR0 + 0x5400), Read1ByteRegister(BAR0 + 0x5401), Read1ByteRegister(BAR0 + 0x5402), Read1ByteRegister(BAR0 + 0x5403), Read1ByteRegister(BAR0 + 0x5404), Read1ByteRegister(BAR0 + 0x5405) });
            }
            else
            {
                var firstWord  = ReadROM(0);
                var secondWord = ReadROM(1);
                var thirdWord  = ReadROM(2);
                address = new MACAddress(new byte[] {
                    (byte)(firstWord & 0xFF),
                    (byte)(firstWord >> 8),
                    (byte)(secondWord & 0xFF),
                    (byte)(secondWord >> 8),
                    (byte)(thirdWord & 0xFF),
                    (byte)(thirdWord >> 8)
                });
            }

            LinkUp();

            //zero out the MTA (multicast tabel array)
            for (int i = 0; i < 0x80; i++)
            {
                WriteRegister((ushort)(0x5200 + i * 4), 0);
            }

            //Enable interupts
            WriteRegister(REG_IMASK, 0x1F6DC);
            WriteRegister(REG_IMASK, 0xFF & ~4);
            ReadRegister(0xC0);

            RXInitialize();
            TXInitialize();
        }
示例#8
0
        public override void Initialize()
        {
            SendCommand(Command.Reset);
            mPS2Controller.WaitForDeviceReset();

            if (PCI.GetDevice((VendorID)0x80EE, (DeviceID)0xBEEF) == null && PCI.GetDevice((VendorID)0x15AD, (DeviceID)0x0405) == null)
            {
                SetScanCodeSet(1);
            }
            //VMware doesn't support the Get/SetScanCode command
            //mDebugger.SendInternal("(PS/2 Keyboard) Current scan code set: " + GetScanCodeSet());
            //SetScanCodeSet(1);
            //mDebugger.SendInternal("(PS/2 Keyboard) Current scan code set: " + GetScanCodeSet());

            INTs.SetIrqHandler(1, HandleIRQ);

            SendCommand(Command.EnableScanning);

            Global.mDebugger.SendInternal("(PS/2 Keyboard) Initialized");
        }
示例#9
0
        public void Enable()
        {
            MouseManager.X = 0;
            MouseManager.Y = 0;
            INTs.SetIrqHandler(0x0C, HandleInterrupt);

            commandPort.Byte = 0xA8;
            commandPort.Byte = 0x20;
            byte status = (byte)(dataPort.Byte | 2);

            commandPort.Byte = 0x60;
            dataPort.Byte    = status;

            commandPort.Byte = 0xD4;
            dataPort.Byte    = 0xF4;
            _ = dataPort.Byte;
            for (int i = 0; i < 3; i++)
            {
                buffer.Add(0x00);
            }
        }
示例#10
0
文件: RTL8139.cs 项目: nifanfa/Cosmos
 public RTL8139(PCIDevice device)
 {
     if (device == null)
     {
         throw new ArgumentException("PCI Device is null. Unable to get Realtek 8139 card");
     }
     pciCard = device;
     Base    = device.BaseAddressBar[0].BaseAddress;
     // We are handling this device
     pciCard.Claimed = true;
     // Setup interrupt handling
     INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
     // Get IO Address from PCI Bus
     // Enable the card
     pciCard.EnableDevice();
     // Turn on the card
     OutB(Base + 0x52, 0x01);
     //Do a software reset
     SoftwareReset();
     // Get the MAC Address
     byte[] eeprom_mac = new byte[6];
     for (uint b = 0; b < 6; b++)
     {
         eeprom_mac[b] = Inb(Base + b);
     }
     this.mac = new MACAddress(eeprom_mac);
     // Get a receive buffer and assign it to the card
     rxBuffer        = new ManagedMemoryBlock(RxBufferSize + 2048 + 16, 4);
     RBStartRegister = rxBuffer.Offset;
     // Setup receive Configuration
     RecvConfigRegister = 0xF381;
     // Setup Transmit Configuration
     TransmitConfigRegister = 0x3000300;
     // Setup Interrupts
     IntMaskRegister   = 0x7F;
     IntStatusRegister = 0xFFFF;
     // Setup our Receive and Transmit Queues
     mRecvBuffer     = new Queue <byte[]>();
     mTransmitBuffer = new Queue <byte[]>();
 }
        public void ReadBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData)
        {
            //Partially working. When i read data it fails but in the ATA registers the DRQ bit is set to 1. so the device knows that data must be transfered!.
            //Maybe the problem is in the Interupt management (still don't know ho to do it)
            Statuses s = GetStatus();

            SelectDrive(currentDevice, 0);
            s = GetStatus();
            UsedBus.Feature.Byte = 0x00;
            UsedBus.LBA2.Byte    = (byte)((mBlockSize / 2) & 0xFF);
            UsedBus.LBA3.Byte    = (byte)((mBlockSize / 2) >> 8);
            SendCommand(Commands.Packet);
            Byte[] cmd = new Byte[] { (byte)ATAPICommands.Read2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            cmd[9] = (byte)aBlockCount;
            cmd[2] = (byte)((aBlockNo & 0xFF000000) >> 24);
            cmd[3] = (byte)((aBlockNo & 0xFF0000) >> 16);
            cmd[4] = (byte)((aBlockNo & 0xFF00) >> 8);
            cmd[5] = (byte)(aBlockNo & 0xFF);
            for (int i = 0; i < cmd.Length / 2; i += 2)
            {
                UsedBus.Data.Word = (byte)(cmd[i] << 8 | cmd[i + 1]);
            }
            //Aurora: WON'T WORK - interrupts are locked by cosmos anyway.
            Cosmos.Core.INTs.IRQContext c = new Cosmos.Core.INTs.IRQContext();
            INTs.HandleInterrupt_2E(ref c);
            INTs.HandleInterrupt_2F(ref c);
            uint xD = c.Interrupt;

            s = GetStatus();
            s = GetStatus();
            s = GetStatus();
            uint size = (uint)(UsedBus.LBA3.Byte << 8 | UsedBus.LBA2.Byte);

            UsedBus.Data.Read8(aData);
            c = new Cosmos.Core.INTs.IRQContext();
            INTs.HandleInterrupt_2E(ref c);
            INTs.HandleInterrupt_2F(ref c);
            xD = c.Interrupt;
        }
示例#12
0
        public static unsafe void Init()
        {
            INTs.SetIntHandler(0x48, (ref INTs.IRQContext ctx) => {
                Console.WriteLine("Wow! You actually triggered a syscall!");

                CPU.DisableInterrupts();

                var syscallCode = ctx.EAX;
                var arg1        = ctx.EBX;
                var arg2        = ctx.ECX;
                var arg3        = ctx.EDX;
                switch (syscallCode)
                {
                case 1:
                    Write((byte *)arg1, arg2);
                    break;

                case 2:

                    // TODO
                    break;

                case 3:
                    CreateProcess((byte *)arg1, (byte *)arg2, arg3);
                    break;

                case 4:
                    ProcessTerminate(arg1);
                    break;

                case 5:
                    Console.WriteLine("Greetings from syscall!");
                    break;
                }
                CPU.EnableInterrupts();
            });
        }
示例#13
0
 public PIT()
 {
     INTs.SetIrqHandler(0x00, HandleIRQ);
     T0Countdown = 65535;
 }
示例#14
0
 protected override void Initialize()
 {
     INTs.SetIrqHandler(0x01, HandleIRQ);
 }
示例#15
0
 public static void Init()
 {
     INTs.SetIrqHandler(0x07, HandleIRQ2);
     SoftReset();
     InitRxBuffer();
 }
示例#16
0
        /// <summary>
        /// Creates a new instance of the <see cref="AC97"/> class, with the
        /// given buffer size.
        /// </summary>
        /// <param name="bufferSize">The buffer size in samples to use. This value cannot be an odd number, as per the AC97 specification.</param>
        /// <exception cref="ArgumentException">Thrown when the given buffer size is invalid.</exception>
        /// <exception cref="InvalidOperationException">Thrown when no AC97-compatible sound card is present.</exception>
        private AC97(ushort bufferSize)
        {
            if (bufferSize % 2 != 0)
            {
                // As per the AC97 specification, the buffer size cannot be odd.
                // (1.2.4.2 PCM Buffer Restrictions, Intel document 302349-003)
                throw new ArgumentException("The buffer size must be an even number.", nameof(bufferSize));
            }

            PCIDevice pci = Cosmos.HAL.PCI.GetDeviceClass(
                ClassID.MultimediaDevice, // 0x04
                (SubclassID)0x01          // 0x01
                );

            if (pci == null || !pci.DeviceExists || pci.InterruptLine > 0xF)
            {
                throw new InvalidOperationException("No AC97-compatible device could be found.");
            }

            PCI = pci; // Expose PCI device to the public API

            pci.EnableBusMaster(true);
            pci.EnableMemory(true);
            pci.EnableDevice(); // enable I/O space

            INTs.SetIrqHandler(pci.InterruptLine, HandleInterrupt);

            ushort NAMbar  = (ushort)pci.BaseAddressBar[0].BaseAddress; // Native Audio Mixer
            ushort NABMbar = (ushort)pci.BaseAddressBar[1].BaseAddress; // Native Audio Bus Master

            pTransferControl   = new IOPort((ushort)(NABMbar + 0x1B));
            pMasterVolume      = new IOPort((ushort)(NAMbar + 0x02));
            pPCMOutVolume      = new IOPort((ushort)(NAMbar + 0x18));
            pBufferDescriptors = new IOPort((ushort)(NABMbar + 0x10));
            pTransferStatus    = new IOPort((ushort)(NABMbar + 0x16));
            pLastValidEntry    = new IOPort((ushort)(NABMbar + 0x15));
            pGlobalControl     = new IOPort((ushort)(NABMbar + 0x2C));
            pResetRegister     = new IOPort((ushort)(NAMbar + 0x00));

            // Reset device
            pGlobalControl.Byte  = 0x2;
            pResetRegister.DWord = 0xDEADBEEF; // any value will do here

            // Reset PCM out
            uint polls = 0; // The amount we polled the device for a reset

            pTransferControl.Byte = (byte)(pTransferControl.Byte | TC_TRANSFER_RESET);
            while ((pTransferControl.Byte & TC_TRANSFER_RESET) != 0 && polls < RESET_POLL_LIMIT)
            {
                // Wait until the byte is cleared
                polls++;
            }

            // The device hasn't responded to our reset request. Probably not a fully-compatible AC97 card.
            if (polls >= RESET_POLL_LIMIT)
            {
                throw new InvalidOperationException("No AC97-compatible device could be found - the reset timeout has expired.");
            }

            // Volume
            pMasterVolume.Word = CreateMixerVolumeValue(AC97_VOLUME_MAX, AC97_VOLUME_MAX, false);
            pPCMOutVolume.Word = CreateMixerVolumeValue(AC97_VOLUME_MAX, AC97_VOLUME_MAX, false);

            // Create all needed buffers
            CreateBuffers(bufferSize);

            // Initialization done - driver can now be activated by using Enable()
        }
示例#17
0
        public AMDPCNetII(PCIDevice device)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get AMD PCNet card");
            }

            this.pciCard         = device;
            this.pciCard.Claimed = true;
            this.pciCard.EnableDevice();

            this.io = new AMDPCNetIIIOGroup((ushort)this.pciCard.BaseAddressBar[0].BaseAddress);
            this.io.RegisterData.DWord = 0;

            // Get the EEPROM MAC Address and set it as the devices MAC
            byte[] eeprom_mac = new byte[6];
            UInt32 result     = io.MAC1.DWord;

            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result        = io.MAC2.DWord;
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            mInitBlock    = new ManagedMemoryBlock(28, 4);
            mRxDescriptor = new ManagedMemoryBlock(256, 16);
            mTxDescriptor = new ManagedMemoryBlock(256, 16);

            mInitBlock.Write32(0x00, (0x4 << 28) | (0x4 << 20));
            mInitBlock.Write32(0x04,
                               (UInt32)(eeprom_mac[0] | (eeprom_mac[1] << 8) | (eeprom_mac[2] << 16) | (eeprom_mac[3] << 24)));
            mInitBlock.Write32(0x08, (UInt32)(eeprom_mac[4] | (eeprom_mac[5] << 8)));
            mInitBlock.Write32(0x0C, 0x0);
            mInitBlock.Write32(0x10, 0x0);
            mInitBlock.Write32(0x14, mRxDescriptor.Offset);
            mInitBlock.Write32(0x18, mTxDescriptor.Offset);

            InitializationBlockAddress = mInitBlock.Offset;
            SoftwareStyleRegister      = 0x03;

            mRxBuffers = new List <ManagedMemoryBlock>();
            mTxBuffers = new List <ManagedMemoryBlock>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mRxDescriptor.Write32(xOffset + 8, buffer.Offset);
                UInt16 buffer_len = (UInt16)(~buffer.Size);
                buffer_len++;
                UInt32 flags = (UInt32)(buffer_len & 0x0FFF) | 0xF000 | 0x80000000;
                mRxDescriptor.Write32(xOffset + 4, flags);
                mRxBuffers.Add(buffer);
            }
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mTxDescriptor.Write32(xOffset + 8, buffer.Offset);
                mTxBuffers.Add(buffer);
            }

            mNextTXDesc = 0;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue <byte[]>();
            mRecvBuffer     = new Queue <byte[]>();

            INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
        }