Exemplo n.º 1
0
        static Mmu()
        {
            ttb = GetTTB();

            // NB Table is 1MB section and 1MB aligned to avoid modifying page table entries on
            // page containing pool of

            l2TablePool = IoMemory.AllocatePhysical(L1SectionSize, L1SectionSize);
            DebugStub.Assert(RangeIsPageAligned(l2TablePool.VirtualAddress,
                                                (uint)l2TablePool.Length,
                                                L1SectionSize));

            MaxL2Tables = L1SectionSize / L2TableSize;

            l2UsedBitmap = new uint [MaxL2Tables / 32];
        }
Exemplo n.º 2
0
        private static AmlParser.ParseSuccess ParseAndLoadRegion(IoMemory region, AcpiObject.IOperationRegionAccessor operationRegionAccessor)
        {
            AmlParser.AMLCode result;
            int       offset = 0;
            AmlParser parser = new AmlParser(new IoMemoryAmlStreamAdapter(region), null, null);

            AmlParser.ParseSuccess parseSuccess =
                parser.ParseAMLCode(out result, ref offset, region.Length);

            if (parseSuccess == AmlParser.ParseSuccess.Success)
            {
                AmlLoader loader = new AmlLoader(acpiNamespace, operationRegionAccessor);
                loader.Load(result);
            }
            return(parseSuccess);
        }
Exemplo n.º 3
0
        internal static MpIoApicEntry Parse(IoMemory region,
                                            int length,
                                            ref int offset)
        {
            Debug.Assert(length >= offset + Length);
            Debug.Assert(region.Read8(offset + 0) == EntryType);

            MpIoApicEntry e = new MpIoApicEntry();

            e.Id          = region.Read8(offset + 1);
            e.Version     = region.Read8(offset + 2);
            e.Flags       = region.Read8(offset + 3);
            e.BaseAddress = region.Read32(offset + 4);
            e.DebugPrint();
            offset += Length;
            return(e);
        }
Exemplo n.º 4
0
        public static Rsdp Parse(UIntPtr regionAddress,
                                 uint regionBytes)
        {
            if (regionBytes >= 20)
            {
                IoMemory region = IoMemory.MapPhysicalMemory(regionAddress,
                                                             regionBytes,
                                                             true, false);

                if (AcpiChecksum.Compute(region, 0, 20) == 0 &&
                    region.ReadAsciiZeroString(0, 8) == Rsdp.Id)
                {
                    return(new Rsdp(region));
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        static public PnpBiosInfo GetPnpBiosInfo()
        {
            Platform    bi  = Platform.ThePlatform;
            PnpBiosInfo pbi = new PnpBiosInfo();

            if (bi.PnpNodesAddr32 != UIntPtr.Zero)
            {
                Tracing.Log(Tracing.Debug, "PnpBiosRegion {0:x8}..{1:x8}",
                            bi.PnpNodesAddr32, bi.PnpNodesAddr32 + bi.PnpNodesSize32);
                pbi.pnpRegion = IoMemory.MapPhysicalMemory(
                    bi.PnpNodesAddr32, bi.PnpNodesSize32, true, false);
            }

            pbi.isaReadPort = new IoPort((ushort)bi.IsaReadPort, 1, Access.Read);;
            pbi.isaCsns     = bi.IsaCsns;
            return(pbi);
        }
Exemplo n.º 6
0
        public IoApic(UIntPtr memoryBase, uint interruptBase)
        {
            ioRegSel = IoMemory.MapPhysicalMemory(memoryBase,
                                                  new UIntPtr(4u), true, true);
            ioWin = IoMemory.MapPhysicalMemory(memoryBase + new UIntPtr(0x10u),
                                               new UIntPtr(4u), true, true);
            entries = ((ReadRegister(1) & 0xff0000u) >> 16) + 1;

            for (uint i = 0; i < entries; i++)
            {
                SetEntryMask(i, true);
            }

            ioLock = new SpinLock(SpinLock.Types.IoApic);

            this.interruptBase = interruptBase;
        }
Exemplo n.º 7
0
        public static void InitializeMpAbi()
        {
            // Note: When mapping the abi stub (MpSyscalls.x86), we must
            // map it with writable flag! as we want to resolve the stub's
            // imports
            IoMemory mpPages = IoMemory.MapPhysicalMemory(Platform.MP_ABI_BASE, 4096, true, true);

            mpAbi        = new PEImage(mpPages);
            mpPages      = IoMemory.MapPhysicalMemory(Platform.MP_ABI_BASE, mpAbi.loadedSize, true, true);
            mpAbiExports = mpAbi.GetExportTable(mpPages);

            // Resolve imports in abi shim dll with the kernel exports
            // which are the real stub that will do IPI stuffs
            ImportTable mpAbiIt = mpAbi.GetImportTable(mpPages);

            DebugStub.WriteLine("HSG: ** Resolving Imports");
            mpAbiIt.ResolveImports(kernelExports);
        }
Exemplo n.º 8
0
        // Constructor
        internal Tpm(/*TpmResources! res*/)
        {
            Tracing.Log(Tracing.Debug, "Tpm: Initialize() called\n");

            DebugStub.WriteLine("Tpm: Initialize() called");

            tpmIoMemory = IoMemory.MapPhysicalMemory(new UIntPtr(0xfed40000),
                                                     new UIntPtr(0x4000),
                                                     true,
                                                     true);

            if (tpmIoMemory == null)
            {
                DebugStub.WriteLine("Tpm: Initialize(), MapPhysicalMemory failed");
            }

            minResponse = new byte[minResponseLen];
        }
Exemplo n.º 9
0
        internal static MpProcessorEntry Parse(IoMemory region,
                                               int length,
                                               ref int offset)
        {
            Debug.Assert(length >= offset + Length);
            Debug.Assert(region.Read8(offset + 0) == EntryType);

            MpProcessorEntry e = new MpProcessorEntry();

            e.LocalApicId      = region.Read8(offset + 1);
            e.LocalApicVersion = region.Read8(offset + 2);
            e.CpuFlags         = region.Read8(offset + 3);
            e.CpuSignature     = region.Read32(offset + 4);
            e.FeatureFlags     = region.Read32(offset + 8);
            e.DebugPrint();
            offset += Length;
            return(e);
        }
Exemplo n.º 10
0
        uint flags;             // Values per MadtFlags

        private Madt(IoMemory region, SystemTableHeader header)
        {
            this.region = region;
            this.header = header;

            localApicAddress = region.Read32(0);
            flags            = region.Read32(4);

            // XXX Just for debugging
            GetLocalApics();
            GetIoApics();
            GetInterruptSourceOverrides();
            GetNmis();
            GetApicNmis();
            GetLocalApicAddressOverrides();
            GetIoSApics();
            GetLocalSApics();
            GetPlatformInterruptSources();
        }
Exemplo n.º 11
0
        public Vga()
        {
            IoPortRange dev = new IoPortRange(0x3c0, 0x20, Access.ReadWrite);

            atcAddrPort = dev.PortAtOffset(ATC_ADDR_PORT, 2, Access.ReadWrite);
            miscOutputRegWritePort = dev.PortAtOffset(MISC_OUTPUT_REG_WRITE_PORT, 2, Access.ReadWrite);
            seqAddrPort = dev.PortAtOffset(SEQ_ADDR_PORT, 2, Access.Write);
            seqDataPort = dev.PortAtOffset(SEQ_DATA_PORT, 2, Access.ReadWrite);
            dacPixelMaskPort = dev.PortAtOffset(DAC_PIXEL_MASK_PORT, 2, Access.Write);
            dacAddressWritePort = dev.PortAtOffset(DAC_ADDR_WRITE_PORT, 2, Access.Write);
            dacDataRegPort = dev.PortAtOffset(DAC_DATA_REG_PORT, 2, Access.Write);
            graphAddrPort = dev.PortAtOffset(GRAPH_ADDR_PORT, 2, Access.Write);
            graphDataPort = dev.PortAtOffset(GRAPH_DATA_PORT, 2, Access.ReadWrite);
            crtcAddressColorPort = dev.PortAtOffset(CRTC_ADDR_COLOR_PORT, 2, Access.ReadWrite);
            inputStatusColorPort = dev.PortAtOffset(INPUT_STATUS_COLOR_PORT, 2, Access.ReadWrite);

            screenBuffer = IoMemory.AllocateIo(0xa0000, 0x20000, true, true);
            textBuffer = IoMemory.AllocateIo(0xb8000, 0x8000, true, true);
        }
Exemplo n.º 12
0
        internal LocalSApic(IoMemory region, int offset)
        {
            Debug.Assert(region.Read8(offset + 0) == TypeId);

            byte length = region.Read8(offset + 1);

            Debug.Assert(length >= MinLength);

            AcpiProcessorId = region.Read8(offset + 2);
            LocalSApicId    = region.Read8(offset + 3);
            LocalSApicEid   = region.Read8(offset + 4);
            // reserved            = region.Read24(offset + 5);
            Flags = region.Read32(offset + 8);
            AcpiProcessorUidValue  = region.Read32(offset + 12);
            AcpiProcessorUidString = region.ReadString(offset + 16,
                                                       (int)length - 17);

            // DebugStub.Print("{0:x04}:{1:x04} type {2:x01} AcpiProcId {3:x02} LocalSApicId {4:x02} LocalSApicEid {5:x02} Flags {6:x08} AcpiProcUid {7:x04} AcpiProcUid \"{8}\" (LocalSApic)\n", __arglist(offset, offset + length, TypeId, AcpiProcessorId, LocalSApicId, LocalSApicEid, Flags, AcpiProcessorUidValue, AcpiProcessorUidString));
        }
Exemplo n.º 13
0
        internal static void Parse(IoMemory region,
                                   int length,
                                   uint entryCount)
        {
            int offset = 0;

            for (int i = 0; i < entryCount; i++)
            {
                switch (region.Read8(offset))
                {
                case MpProcessorEntry.EntryType:
                    ProcessorEntries.Add(
                        MpProcessorEntry.Parse(region, length, ref offset)
                        );
                    break;

                case MpBusEntry.EntryType:
                    BusEntries.Add(
                        MpBusEntry.Parse(region, length, ref offset)
                        );
                    break;

                case MpIoApicEntry.EntryType:
                    IoApicEntries.Add(
                        MpIoApicEntry.Parse(region, length, ref offset)
                        );
                    break;

                case MpInterruptEntry.IoEntryType:
                    IoInterruptEntries.Add(
                        MpInterruptEntry.Parse(region, length, ref offset)
                        );
                    break;

                case MpInterruptEntry.LocalEntryType:
                    LocalInterruptEntries.Add(
                        MpInterruptEntry.Parse(region, length, ref offset)
                        );
                    break;
                }
            }
        }
Exemplo n.º 14
0
            internal readonly uint AddressOfOrdinals;       // RVA from base of image

            internal ExportDirectory(IoMemory mem, int offset)
            {
                if (offset + 40 > mem.Length)
                {
                    Error.AccessOutOfRange();
                }
                Characteristics    = mem.Read32Unchecked(offset + 0);
                NumberOfFunctions  = mem.Read32Unchecked(offset + 20);
                NumberOfNames      = mem.Read32Unchecked(offset + 24);
                AddressOfFunctions = mem.Read32Unchecked(offset + 28);
                AddressOfNames     = mem.Read32Unchecked(offset + 32);
                AddressOfOrdinals  = mem.Read32Unchecked(offset + 36);

                if (AddressOfFunctions + 4 * NumberOfFunctions > mem.Length ||
                    AddressOfOrdinals + 2 * NumberOfFunctions > mem.Length ||
                    AddressOfNames + 4 * NumberOfFunctions > mem.Length)
                {
                    Error.AccessOutOfRange();
                }
            }
Exemplo n.º 15
0
        private static void UuencodeDumpRegion(string filename, IoMemory region)
        {
            DebugStub.Print("\nbegin 777 {0}\n", __arglist(filename));

            StringBuilder line             = new StringBuilder();
            int           inputBytesOnLine = 0;

            for (int i = 0; i < region.Length; i += 3)
            {
                byte b1 = (byte)0, b2 = (byte)0, b3 = (byte)0;

                b1 = region.Read8(i);
                inputBytesOnLine++;

                if (i + 1 < region.Length)
                {
                    b2 = region.Read8(i + 1);
                    inputBytesOnLine++;
                }

                if (i + 2 < region.Length)
                {
                    b3 = region.Read8(i + 2);
                    inputBytesOnLine++;
                }

                line.Append((char)(32 + (b1 >> 2)));
                line.Append((char)(32 + (((b1 << 4) | (b2 >> 4)) & 0x3F)));
                line.Append((char)(32 + (((b2 << 2) | (b3 >> 6)) & 0x3F)));
                line.Append((char)(32 + (b3 & 0x3F)));

                if (line.Length >= 60 || i + 3 >= region.Length)
                {
                    DebugStub.Print("{0}{1}\n", __arglist((char)(inputBytesOnLine + 32), line.ToString()));
                    line.Remove(0, line.Length);
                    inputBytesOnLine = 0;
                }
            }

            DebugStub.Print("end\n\n");
        }
Exemplo n.º 16
0
        internal static MpFloatingPointer Parse(IoMemory region)
        {
            uint signature = region.Read32(0);

            if (signature != Signature)
            {
                return(null);
            }

            int length = region.Read8(8) * 16;

            if (length != 16)
            {
                return(null);
            }

            byte checksum = 0;

            for (int i = 0; i < length; i++)
            {
                checksum += region.Read8((int)i);
            }

            if (checksum != 0)
            {
                return(null);
            }

            MpFloatingPointer m = new MpFloatingPointer();

            m.ConfTableBase = region.Read32(4);
            m.Revision      = region.Read8(9);
            m.Feature       = new byte [5];
            for (int i = 0; i < m.Feature.Length; i++)
            {
                m.Feature[i] = region.Read8(0xb + i);
            }

            return(m);
        }
Exemplo n.º 17
0
        internal static MpInterruptEntry Parse(IoMemory region,
                                               int length,
                                               ref int offset)
        {
            Debug.Assert(length >= offset + Length);
            byte entry = region.Read8(offset + 0);

            Debug.Assert(entry == IoEntryType || entry == LocalEntryType);

            MpInterruptEntry e = new MpInterruptEntry();

            e.EntryType = entry;
            e.Interrupt = region.Read8(offset + 1);
            e.Flags     = region.Read16(offset + 2);
            e.BusId     = region.Read8(offset + 4);
            e.BusIrq    = region.Read8(offset + 5);
            e.ApicId    = region.Read8(offset + 6);
            e.ApicLine  = region.Read8(offset + 7);
            e.DebugPrint();
            offset += Length;
            return(e);
        }
Exemplo n.º 18
0
        // Constructor
        internal TimerOmap3430(PnpConfig config, Pic pic)
        {
#if VERBOSE
            DebugStub.WriteLine("TimerOmap3430: create");
#endif
            TimerResources tr = new TimerResources(config);

            this.config = config;
            this.pic    = pic;
            this.irq    = tr.irq.Irq;

            IoMemory timerRegisters = tr.registers
                                      .MemoryAtOffset(0, Omap3430_TIMER1_RegisterSize, Access.ReadWrite);

            tisr = timerRegisters.MappedPortAtOffset(Omap3430_TISR, 4, Access.ReadWrite);
            tier = timerRegisters.MappedPortAtOffset(Omap3430_TIER, 4, Access.ReadWrite);
            tclr = timerRegisters.MappedPortAtOffset(Omap3430_TCLR, 4, Access.ReadWrite);
            tcrr = timerRegisters.MappedPortAtOffset(Omap3430_TCRR, 4, Access.ReadWrite);
            tldr = timerRegisters.MappedPortAtOffset(Omap3430_TLDR, 4, Access.ReadWrite);

            // _ARM_ERRATA problem with how functional clock is unstuck
            tcrr.Write32(0, 0);
        }
Exemplo n.º 19
0
        internal ExportTable(IoMemory mem, UIntPtr imageBase, DirectoryEntry entry)
        {
            this.mem   = mem;
            this.entry = entry;

            try {
                exports = new ExportDirectory(mem, (int)entry.virtualAddress);

                if (exports.NumberOfFunctions > 0)
                {
                    addresses = new UIntPtr[exports.NumberOfFunctions];
                    for (uint i = 0; i < exports.NumberOfFunctions; i++)
                    {
                        addresses[i] = imageBase
                                       + mem.Read32Unchecked((int)(exports.AddressOfFunctions + 4 * i));
                    }
                }

                if (exports.NumberOfNames > 0)
                {
                    names    = new string[exports.NumberOfNames];
                    ordinals = new ushort[exports.NumberOfNames];
                    for (uint i = 0; i < exports.NumberOfNames; i++)
                    {
                        ordinals[i]
                            = mem.Read16Unchecked((int)(exports.AddressOfOrdinals + 2 * i));
                        uint addrOfName
                                 = mem.Read32Unchecked((int)(exports.AddressOfNames + 4 * i));
                        names[i] = mem.ReadAsciiZeroString((int)addrOfName);
                    }
                }
            }
            catch (Exception e) {
                DebugStub.Print("Caught exception: {0}\n",
                                __arglist(e.ToString()));
            }
        }
Exemplo n.º 20
0
        internal static MpConfTable Parse(IoMemory region)
        {
            if (region.Read32(0) != Signature)
            {
                return(null);
            }

            int length = region.Read16(4);

            DebugStub.Print("MP Conf Table length {0}\n", __arglist(length));

#if NOTYET
            byte checksum = 0;
            for (int i = 0; i < length; i++)
            {
                checksum += region.Read8(i);
            }

            if (checksum != 0)
            {
                return(null);
            }
#endif

            MpConfTable confTable = new MpConfTable();
            confTable.BaseTableLength       = region.Read16(4);
            confTable.Revision              = region.Read8(7);
            confTable.OemTableBase          = region.Read32(0x1c);
            confTable.OemTableSize          = region.Read16(0x20);
            confTable.EntryCount            = region.Read16(0x22);
            confTable.LocalApicBase         = region.Read32(0x24);
            confTable.ExtendedTableLength   = region.Read16(0x28);
            confTable.ExtendedTableChecksum = region.Read8(0x2a);
            confTable.OemId     = region.ReadAsciiZeroString(8, 8);
            confTable.ProductId = region.ReadAsciiZeroString(0x10, 0x0c);
            return(confTable);
        }
Exemplo n.º 21
0
        ////////////////////////////////////////////////////// Static Methods.
        //
        public static unsafe void Initialize()
        {
            Platform p     = Platform.ThePlatform;
            IoMemory pages = IoMemory.MapPhysicalMemory((UIntPtr)p.KernelDllFirstPage,
                                                        4096, true, false);

            kernel = new PEImage(pages);
            pages  = IoMemory.MapPhysicalMemory((UIntPtr)p.KernelDllBase,
                                                kernel.loadedSize, true, false);

            kernelExports = kernel.GetExportTable(pages);

            DebugStub.WriteLine("PEImage.Initialize: Notify KD of kernel load.");
            DebugStub.LoadedBinary(pages.VirtualAddress,
                                   kernel.sizeOfImage,
#if ISA_ARM
                                   "kernel.arm",
#elif ISA_IX64
                                   "kernel.x64",
#elif ISA_IX86
                                   "kernel.x86",
#endif
                                   kernel.checkSum,
                                   kernel.timeDateStamp,
                                   false);

            // This breakpoint is triggered by a "-d" to windbg.
            if (DebugStub.PollForBreak())
            {
                DebugStub.Break();
            }

#if GENERATE_ABI_SHIM
            DebugStub.WriteLine("    InitializeMpAbi() *****");
            InitializeMpAbi();
#endif
        }
Exemplo n.º 22
0
 protected Rsdt(IoMemory region, SystemTableHeader header)
 {
     this.region = region;
     this.header = header;
 }
Exemplo n.º 23
0
 public Ssdt(IoMemory region, SystemTableHeader header)
 {
     this.region = region;
     this.header = header;
 }
Exemplo n.º 24
0
 private Xsdt(IoMemory region, SystemTableHeader header)
     : base(region, header)
 {
     // Nothing to do
 }
Exemplo n.º 25
0
        //
        // Someone must arrange to call this from *within* the
        // Protection Domain for us to have an opportunity to finish
        // initializing.
        //
        internal unsafe void InitHook()
        {
            // If paging is disabled then just return immediately
            if (!MemoryManager.UseAddressTranslation)
            {
                return;
            }

            DebugStub.Assert(AddressSpace.CurrentAddressSpace == this.AddressSpace);

            if (this.initialized)
            {
                // Someone else has already set up the space
                return;
            }

            bool iflag = initSpin.Lock();

            try {
                if (this.initialized)
                {
                    // Someone else snuck in and initialized
                    return;
                }

                //
                // We're first into this space, so set it up.
                //
#if VERBOSE
                DebugStub.WriteLine("Setting up protection domain \"{0}\"",
                                    __arglist(this.name));
#endif

                userRange = new VirtualMemoryRange(VMManager.UserHeapBase,
                                                   VMManager.UserHeapLimit,
                                                   this);
#if PAGING
                if (kernelMode)
                {
                    // This will be a ring-0, trusted domain, so just
                    // point the userSharedHeap at the kernel's comm heap.
                    userSharedHeap = SharedHeap.KernelSharedHeap;

                    this.initialized = true;
                }
                else
                {
                    // Create a new shared heap that lives in
                    // user-land.
                    userSharedHeap = new SharedHeap(this, userRange);
#if VERBOSE
                    DebugStub.WriteLine("  ...Created a shared heap");
#endif

                    //
                    // N.B.: this is kind of tricky. Loading an
                    // executable image involves allocating memory,
                    // which goes through this object. So, before
                    // attempting the load, mark ourselves as initialized.
                    //
                    // ---- DON'T PUT GENUINE INITIALIZATION
                    //      CODE BELOW HERE! ---------
                    this.initialized = true;

                    // Load our own, protection-domain-private copy of the
                    // ABI stubs. These will get shared by all apps in
                    // this domain.
                    IoMemory syscallsMemory = Binder.LoadRawImage("/init", "syscalls.dll");
                    IoMemory loadedMemory;

                    // Load the stubs library into the user range, but make
                    // the kernel process the logical owner. This seems like
                    // the only sensible approach since the stubs do not
                    // belong to any particular process but must be in the
                    // user range of memory.

                    // N.B.: RE-ENTERS this object!
                    ring3AbiImage = PEImage.Load(Process.kernelProcess, syscallsMemory,
                                                 out loadedMemory,
                                                 false, // isForMp
                                                 false  // inKernelSpace
                                                 );

                    ring3AbiExports = ring3AbiImage.GetExportTable(loadedMemory);
#if VERBOSE
                    DebugStub.WriteLine("  ...Loaded ring-3 ABI stubs");
#endif
                }
#else // PAGING
                this.initialized = true;
#endif // PAGING
            }
            finally {
                DebugStub.Assert(this.initialized);
                initSpin.Unlock(iflag);
            }
        }
Exemplo n.º 26
0
 internal static object Create(IoMemory region, int offset)
 {
     return(new PlatformInterruptSource(region, offset));
 }
Exemplo n.º 27
0
 internal static object Create(IoMemory region, int offset)
 {
     return(new LocalSApic(region, offset));
 }
Exemplo n.º 28
0
 internal static object Create(IoMemory region, int offset)
 {
     return(new InterruptSourceOverride(region, offset));
 }
Exemplo n.º 29
0
 internal static object Create(IoMemory region, int offset)
 {
     return(new LocalApicAddressOverride(region, offset));
 }
Exemplo n.º 30
0
 internal static object Create(IoMemory region, int offset)
 {
     return(new Nmi(region, offset));
 }