Пример #1
0
        // Constructor
        internal Timer8254LegacyPC(PnpConfig config, Pic pic)
        {
#if VERBOSE
            Tracing.Log(Tracing.Debug, "Timer8254: create");
#endif

            // /pnp/08/02/01/PNP0100 0003 cfg dis : ISA 8254 Timer : AT Timer
            // IRQ mask=0001 type=47
            // I/O Port inf=01 min=0040 max=0040 aln=01 len=04 0040..0043
            this.config = config;
            this.pic    = pic;
            this.irq    = ((IoIrqRange)config.DynamicRanges[1]).Irq;
            IoPortRange ioPorts = (IoPortRange)config.DynamicRanges[0];
            C0Port = ioPorts.PortAtOffset(i8254_C0, 1, Access.ReadWrite);
            C2Port = ioPorts.PortAtOffset(i8254_C2, 1, Access.ReadWrite);
            CWPort = ioPorts.PortAtOffset(i8254_CW, 1, Access.ReadWrite);

            // Enable Timer2
            // Lower 2 bits of port 61 are described in:
            // The Indispensable PC Hardware Book (3rd Edition) p.724
            ioPorts = (IoPortRange)config.FixedRanges[0];
            IoPort p = ioPorts.PortAtOffset(0, 1, Access.ReadWrite);

            //
            // Also clear the NMI RAM parity error to enable the PCI card
            // to generate NMI if the button is depressed
            //

            p.Write8((byte)((p.Read8() & 0xf8) | 0x01));
        }
Пример #2
0
        // Constructor
        internal RTClockApic(PnpConfig config, Apic apic)
        {
            int cpuId;

            Microsoft.Singularity.Hal.Platform p = Microsoft.Singularity.Hal.Platform.ThePlatform;
            cpuId = p.ApicId;

            DebugStub.Print("RTClock: create\n");

            // /pnp/08/03/01/PNP0B00 0003 cfg dis : ISA RTC Controller : AT RTC
            // IRQ mask=0100 type=47
            // I/O Port inf=01 min=0070 max=0070 aln=01 len=02 0070..0071

            this.config      = config;
            this.irq         = ((IoIrqRange)config.DynamicRanges[1]).Irq;
            this.apic        = apic;
            this.rtcSpinLock = new SpinLock(SpinLock.Types.RTClock);

            rtcadd = ((IoPortRange)config.DynamicRanges[0])
                     .PortAtOffset(0, 1, Access.ReadWrite);
            rtcdat = ((IoPortRange)config.DynamicRanges[0])
                     .PortAtOffset(1, 1, Access.ReadWrite);

            if (cpuId == 0)
            {
                this.interrupt = Initialize();
                DebugStub.Print("RTClock: interrupt {0:x2}\n",
                                __arglist(this.interrupt));
            }
        }
Пример #3
0
            public uint Read32(AcpiObject.RegionSpace regionSpace, ulong offset)
            {
                uint result;

                switch (regionSpace)
                {
                case AcpiObject.RegionSpace.SystemMemory:
                    IoMemory region = IoMemory.MapPhysicalMemory(offset, 4, true /*readable*/, false /*writable*/);
                    result = region.Read32(0);
                    break;

                case AcpiObject.RegionSpace.SystemIO:
                    IoPort port = new IoPort((ushort)offset, 4, Access.Read);
                    result = port.Read32();
                    break;

                case AcpiObject.RegionSpace.PCI_Config:
                    pciConfigAddressPort.Write32(PciConfigEnableMask | (uint)offset);
                    result = pciConfigDataPort.Read32();
                    break;

                default:
                    throw new Exception("Unimplemented operation region type" + regionSpace);
                }
#if DUMP_RAW_READ_WRITES
                DebugStub.WriteLine("ACPI read: space: " + regionSpace + ", offset: " + offset + ", bytes: " + 4 + ", result: " + result.ToString("X"));
#endif
                return(result);
            }
Пример #4
0
            public void Write32(AcpiObject.RegionSpace regionSpace, ulong offset, uint value)
            {
#if DUMP_RAW_READ_WRITES
                DebugStub.WriteLine("ACPI write: space: " + regionSpace + ", offset: " + offset + ", bytes: " + 4 + ", value: " + value.ToString("X"));
#endif
                switch (regionSpace)
                {
                case AcpiObject.RegionSpace.SystemMemory:
                    IoMemory region = IoMemory.MapPhysicalMemory(offset, 4, true /*readable*/, true /*writable*/);
                    region.Write32(0, value);
                    break;

                case AcpiObject.RegionSpace.SystemIO:
                    IoPort port = new IoPort((ushort)offset, 4, Access.ReadWrite);
                    port.Write32(value);
                    break;

                case AcpiObject.RegionSpace.PCI_Config:
                    pciConfigAddressPort.Write32(PciConfigEnableMask | (uint)offset);
                    pciConfigDataPort.Write32(value);
                    break;

                default:
                    throw new Exception("Unimplemented operation region type" + regionSpace);
                }
            }
Пример #5
0
            public OperationRegionAccessor()
            {
                IoPortRange pciConfigPorts = new IoPortRange(PciAddressPort, 8, Access.ReadWrite);

                pciConfigAddressPort = pciConfigPorts.PortAtOffset(0, 4, Access.Write);
                pciConfigDataPort    = pciConfigPorts.PortAtOffset(4, 4, Access.ReadWrite);
            }
Пример #6
0
            public ushort Read16(AcpiObject.RegionSpace regionSpace, ulong offset)
            {
                ushort result;

                switch (regionSpace)
                {
                case AcpiObject.RegionSpace.SystemMemory:
                    // TODO: This is a first stab - ideally the AcpiObject.OperationRegion
                    // ought to be holding onto an IoMemoryRange and passing it in.
                    IoMemory region = IoMemory.MapPhysicalMemory(offset, 2, true /*readable*/, false /*writable*/);
                    result = region.Read16(0);
                    break;

                case AcpiObject.RegionSpace.SystemIO:
                    IoPort port = new IoPort((ushort)offset, 2, Access.Read);
                    result = port.Read16();
                    break;

                case AcpiObject.RegionSpace.PCI_Config:
                    pciConfigAddressPort.Write32(PciConfigEnableMask | (uint)offset);
                    result = pciConfigDataPort.Read16();
                    break;

                default:
                    throw new Exception("Unimplemented operation region type" + regionSpace);
                }

#if DUMP_RAW_READ_WRITES
                DebugStub.WriteLine("ACPI read: space: " + regionSpace + ", offset: " + offset + ", bytes: " + 2 + ", result: " + result.ToString("X"));
#endif
                return(result);
            }
Пример #7
0
        // Constructor
        internal Timer8254Apic(PnpConfig config)
        {
            // /pnp/08/02/01/PNP0100 0003 cfg dis : ISA 8254 Timer : AT Timer
            // IRQ mask=0001 type=47
            // I/O Port inf=01 min=0040 max=0040 aln=01 len=04 0040..0043
            this.config = config;
            this.irq    = ((IoIrqRange)config.DynamicRanges[1]).Irq;

            IoPortRange ioPorts = (IoPortRange)config.DynamicRanges[0];

            C2Port = ioPorts.PortAtOffset(i8254_C2, 1, Access.ReadWrite);
            CWPort = ioPorts.PortAtOffset(i8254_CW, 1, Access.ReadWrite);

            // Use Timer2 as it's not connected as interrupt source.
            //
            // Lower 2 bits of port 61 are described in:
            // The Indispensable PC Hardware Book (3rd Edition) p.724
            ioPorts = (IoPortRange)config.FixedRanges[0];
            IoPort p = ioPorts.PortAtOffset(0, 1, Access.ReadWrite);

            //
            // Also clear the NMI RAM parity error to enable the PCI card
            // to generate NMI if the button is depressed
            //

            p.Write8((byte)((p.Read8() & 0xf8) | 0x01));
        }
Пример #8
0
 private void AtcOut(IoPort port, byte[] values)
 {
     for (byte i = 0; i < values.Length; i++) {
         port.Write8(i);
         port.Write8(values[i]);
     }
 }
Пример #9
0
        internal void Initialize(byte baseVector)
        {
            DebugStub.Assert(255 - baseVector >= 48);
            this.baseVector = baseVector;

            Write(ApicOffset.LvtTimer, LvtFlags.Masked);
            Write(ApicOffset.LvtThermalSensor, LvtFlags.Masked);
            Write(ApicOffset.LvtPerfCounts, LvtFlags.Masked);
            Write(ApicOffset.LvtError, LvtFlags.Masked);
            Write(ApicOffset.SpuriousIntVector, 0xdfu);

            // set task priority to 0 so that it can
            // receive all interrupts from IPI
            // Write(ApicOffset.TaskPriority, 0x20u);
            Write(ApicOffset.TaskPriority, 0);

            Write(ApicOffset.LvtLint0, LvtFlags.Masked);
            Write(ApicOffset.LvtLint1, LvtFlags.Masked);

            SetId((byte)Processor.GetCurrentProcessorId());

            if (this.IsBsp)
            {
                InitializeRouteableEntries();
                InitializeMpResourceEntries();
            }

            // Enable in s/w
            SetEnabled(true);

            // Enable in h/w
            Isa.WriteMsr(ApicMSR, Isa.ReadMsr(ApicMSR) | (1 << 11));

            // Watch out for the uniprocessor case where the
            // FloatingPointer may be null.
            MpFloatingPointer floatingPointer = MpResources.FloatingPointer;

            if (floatingPointer != null && floatingPointer.ImcrPresent && this.IsBsp)
            {
                IoPort addrPort = new IoPort(ImcrAddressPort, 1, Access.Write);
                IoPort dataPort = new IoPort(ImcrDataPort, 1, Access.Write);
                addrPort.Write8(ImcrAddressSelect);
                dataPort.Write8(ImcrDataApic);
            }

            Write(ApicOffset.LvtLint0, LvtFlags.Level | LvtFlags.ExtInt);
            Write(ApicOffset.LvtLint1, LvtFlags.NMI | 0x02);

            for (int z = 0; z <= maxIrq; z++)
            {
                byte m = IrqToInterrupt((byte)z);
                byte n = InterruptToIrq(m);
                DebugStub.Assert((byte)z == n);
            }
        }
Пример #10
0
 private PMTimer(uint offset, int width)
 {
     if (offset < 0xffffu)
     {
         this.io = new IoPort((ushort)offset, 4, Access.Read);
     }
     else
     {
         this.mem = IoMemory.MapPhysicalMemory(new UIntPtr(offset),
                                               4, true, false);
     }
     this.width = width;
 }
Пример #11
0
        public BusMasterDma(IdeConfig !ideConfig)
        {
            ideConfigHandle = ideConfig;

            // Set up BusMaster ports for this controller
            // <command, status, PRD table>
            commandPort = ideConfig.DmaBase.PortAtOffset(0, 1, Access.ReadWrite);
            statusPort  = ideConfig.DmaBase.PortAtOffset(2, 1, Access.ReadWrite);
            prdPort     = ideConfig.DmaBase.PortAtOffset(4, 4, Access.ReadWrite);
            // PRD needs to be 4-byte aligned and within one 4k page.
            prdRegion =
                IoMemory.AllocatePhysical(PRD_MAX_ENTRIES * PRD_BYTES_PER_ENTRY,
                                          PRD_ALIGNMENT);
        } // BusMasterInitialize
Пример #12
0
 public HalScreenDirect(IoConfig config)
 {
     indexRegister =
         ((IoPortRange)config.FixedRanges[0]).PortAtOffset(
             0, 1, Access.Write);
     dataRegister =
         ((IoPortRange)config.FixedRanges[1]).PortAtOffset(
             0, 1, Access.Write);
     screenBuffer =
         ((IoMemoryRange)config.FixedRanges[2]).MemoryAtOffset(
             0, ScreenSize * 2, Access.ReadWrite);
     Clear();
     WriteLine("Singularity HAL Console Driver.");
     UpdateCursor(true);
 }
Пример #13
0
        // Constructor
        internal RTClockLegacyPC(PnpConfig config, Pic pic, Timer8254LegacyPC timer)
        {
            DebugStub.Print("RTClock: create\n");

            // /pnp/08/03/01/PNP0B00 0003 cfg dis : ISA RTC Controller : AT RTC
            // IRQ mask=0100 type=47
            // I/O Port inf=01 min=0070 max=0070 aln=01 len=02 0070..0071

            this.config = config;
            this.pic    = pic;
            this.irq    = ((IoIrqRange)config.DynamicRanges[1]).Irq;
            this.timer  = timer;

            rtcadd = ((IoPortRange)config.DynamicRanges[0])
                     .PortAtOffset(0, 1, Access.ReadWrite);
            rtcdat = ((IoPortRange)config.DynamicRanges[0])
                     .PortAtOffset(1, 1, Access.ReadWrite);
        }
Пример #14
0
        internal Pic(PnpConfig config)
        {
            // /pnp/08/00/01/PNP0000 0003 cfg dis
            // I/O Port inf=01 min=0020 max=0020 aln=01 len=02 0020..0021
            // I/O Port inf=01 min=00a0 max=00a0 aln=01 len=02 00a0..00a1
            // IRQ mask=0004 type=79

            // Range[0]: 0x20; // PIC0
            // Range[1]: 0xA0; // PIC1

            pic0CtrlPort = ((IoPortRange)config.DynamicRanges[0])
                           .PortAtOffset(0, 1, Access.ReadWrite);
            pic0MaskPort = ((IoPortRange)config.DynamicRanges[0])
                           .PortAtOffset(1, 1, Access.ReadWrite);
            pic1CtrlPort = ((IoPortRange)config.DynamicRanges[1])
                           .PortAtOffset(0, 1, Access.ReadWrite);
            pic1MaskPort = ((IoPortRange)config.DynamicRanges[1])
                           .PortAtOffset(1, 1, Access.ReadWrite);
        }
Пример #15
0
 private void IndxOut(IoPort port, byte[] values)
 {
     for (ushort i = 0; i < values.Length; i++) {
         port.Write16((ushort)(i + ((ushort)values[i] << 8)));
     }
 }
Пример #16
0
        } // BusMasterInitialize

        public void Uninitialize()
        {
            commandPort = null; //???
        }