コード例 #1
0
        internal static void ApicTimer(PMTimer pmTimer, ApicTimer apicTimer)
        {
            apicTimer.SetDivisor(1);
            apicTimer.SetOneShot();
            apicTimer.SetInterruptEnabled(false);
            apicTimer.SetInitialCount(~0u);

            uint apicLast = apicTimer.Value;
            uint pmLast   = pmTimer.Value;

            uint pmLimit = PMTimer.FrequencyHz / 15;
            uint pmAccum = 0;
            uint apicNow = 0;

            // Initial measurements
            apicLast = apicTimer.Value;
            pmLast   = pmTimer.Value;
            do
            {
                apicNow = apicTimer.Value;
                uint pmNow = pmTimer.Value | 0xff000000;
                pmAccum += PmDelta(pmNow, pmLast);
                pmLast   = pmNow;
            } while (pmAccum < pmLimit);

            ulong apicHz = PMTimer.FrequencyHz * (ulong)(apicLast - apicNow) / pmAccum;

            DebugStub.Print("Cpu{0}: APIC timer frequency {1} Hz\n",
                            __arglist(Processor.CurrentProcessor.Id, apicHz));

            apicTimer.SetBusFrequency((uint)apicHz);
        }
コード例 #2
0
ファイル: HalDevices.cs プロジェクト: Paul1nh0/Singularity
        public override void ReleaseResources()
        {
            rtClock.ReleaseResources();
            rtClock = null;

            halTimer.ReleaseResources();
            halTimer = null;

            halPic.ReleaseResources();
            halPic = null;

            pic.ReleaseResources();
            pic = null;
        }
コード例 #3
0
ファイル: HalDevices.cs プロジェクト: Paul1nh0/Singularity
        private void InitializeBsp(Processor rootProcessor)
        {
            DebugStub.Print("HalDevicesApic.Initialize()\n");

            pmTimer = AcpiTables.GetPMTimer();

            // Get PIC resources.  Pic is masked by default.
            PnpConfig picConfig
                = (PnpConfig)IoSystem.YieldResources("/pnp/PNP0000", typeof(PicStub));

            pic = new PicStub(picConfig);
            pic.Initialize(PicBaseVector);

            // Parse MP Table and create IO apics
            MpResources.ParseMpTables();
            ioApics = IoApic.CreateIOApics();

            halPic = new Apic(ioApics);
            halPic.Initialize(ApicBaseVector);

            // Apic timer is used to provide one-shot timer interrupts.
            halTimer = new ApicTimer(halPic);
            halTimer.Initialize();

            // Calibrate timers
            Calibrate.CpuCycleCounter(pmTimer);
            Calibrate.ApicTimer(pmTimer, halTimer);

            // Legacy timer is used to time stalls when starting CPUs.
            PnpConfig i8254Config
                = (PnpConfig)IoSystem.YieldResources("/pnp/PNP0100", typeof(Timer8254Apic));

            stallTimer = new Timer8254Apic(i8254Config);

            // Real-time clock
            PnpConfig rtClockConfig
                = (PnpConfig)IoSystem.YieldResources("/pnp/PNP0B00", typeof(RTClockApic));

            rtClock = new RTClockApic(rtClockConfig, halPic);

            // Compose our HalClock from the component clocks we have available
            halClock = new HalClockApic(halPic, rtClock, new PMClock(pmTimer));

            SystemClock.Initialize(halClock, TimeSpan.FromHours(8).Ticks);

            rootProcessor.AddPic(halPic);

            rootProcessor.AddTimer(halTimer.Interrupt, halTimer);
            rootProcessor.AddClock(halClock.Interrupt, halClock);

            InitializeProcessorCount();
            DebugReportProcessors();

            halTimer.Start();

            // Get the screen resources.  Since we have metadata above to
            // declare all fixed resources used by the screen,
            // YieldResources("") will keep the resource tracking correct:

            halScreen      = new HalScreenDirect(IoSystem.YieldResources("", typeof(HalScreen)));
            Console.Screen = (HalScreen)halScreen;

            halPic.DumpState();
            foreach (IoApic ioApic in ioApics)
            {
                ioApic.DumpRedirectionEntries();
            }
            pic.DumpRegisters();
        }