Sleep using the PIT?

Topics: Using Cosmos (Developing your own OS, projects, etc)
Sep 20, 2012 at 3:48 AM

In Cosmos, how do I sleep for a number of Miliseconds or Seconds using the PIT? Thanks, Matt.

Sep 20, 2012 at 10:14 PM
civilwarrock wrote:

In Cosmos, how do I sleep for a number of Miliseconds or Seconds using the PIT? Thanks, Matt.

First you need to remap the IDT, then install an IRQ handler for interrupt 31 I believe and the just have it increment an integer. I think if you set the PIT to 50 that is about a millisecond but I am not completely sure.

Sep 20, 2012 at 11:52 PM
GruntXProductions wrote:
civilwarrock wrote:

In Cosmos, how do I sleep for a number of Miliseconds or Seconds using the PIT? Thanks, Matt.

First you need to remap the IDT, then install an IRQ handler for interrupt 31 I believe and the just have it increment an integer. I think if you set the PIT to 50 that is about a millisecond but I am not completely sure.

Anyway to make this old guy work?

public static void Sleep_Old(uint aMSec) {
            //Cosmos.Debug.Debugger.SendNumber("PC", "Sleep", aMSec, 32);
            CPU.Halt();//At least one hlt even if aMSec is 0
            if (aMSec > 0)
            {
                uint xStart = TickCount;
                uint xEnd = xStart + aMSec;
                while (TickCount < xEnd)
                {
                    CPU.Halt();
                }
            }
            //Cosmos.Debug.Debugger.SendMessage("PC", "Sleeping done");
        }

Sep 21, 2012 at 12:03 AM
civilwarrock wrote:
GruntXProductions wrote:
civilwarrock wrote:

In Cosmos, how do I sleep for a number of Miliseconds or Seconds using the PIT? Thanks, Matt.

First you need to remap the IDT, then install an IRQ handler for interrupt 31 I believe and the just have it increment an integer. I think if you set the PIT to 50 that is about a millisecond but I am not completely sure.

Anyway to make this old guy work?

 

public static void Sleep_Old(uint aMSec) {
            //Cosmos.Debug.Debugger.SendNumber("PC", "Sleep", aMSec, 32);
            CPU.Halt();//At least one hlt even if aMSec is 0
            if (aMSec > 0)
            {
                uint xStart = TickCount;
                uint xEnd = xStart + aMSec;
                while (TickCount < xEnd)
                {
                    CPU.Halt();
                }
            }
            //Cosmos.Debug.Debugger.SendMessage("PC", "Sleeping done");
        }

 

Halt just waits for the next interrupt to be triggered? I do not think this will work.

Developer
Sep 21, 2012 at 12:09 AM

I thought CPU.Halt(); halted the CPU completely. i.e. It can't start again without rebooting.

Sep 21, 2012 at 12:10 AM

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

Sep 21, 2012 at 12:11 AM
scifiboi wrote:

I thought CPU.Halt(); halted the CPU completely. i.e. It can't start again without rebooting.

Im not sure it is executes the instructions

cli

hlt

or just hlt. If it does the first one it will freeze. If that however is not the case the code above would ONLY work if there was a PIT IRQ.

Sep 21, 2012 at 12:13 AM
civilwarrock wrote:

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

And no. Halt is the C# version of the assembly instruction hlt. All hlt does is pauses the processor until an interrupt is fired. The code above would only work if the PIT was working (which it does not....) because the PIT interrupt would be fired every millisecond.

Sep 21, 2012 at 12:16 AM
GruntXProductions wrote:
civilwarrock wrote:

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

And no. Halt is the C# version of the assembly instruction hlt. All hlt does is pauses the processor until an interrupt is fired. The code above would only work if the PIT was working (which it does not....) because the PIT interrupt would be fired every millisecond.

What can I do to make this work again? Thanks, Matt

Developer
Sep 21, 2012 at 12:20 AM

Okay, well, I just looked at what hlt does and it does wait until the next interrupt is fired, and cli disables interrupts, so that would completely halt the processor. jsyk

Sep 21, 2012 at 12:21 AM
civilwarrock wrote:
GruntXProductions wrote:
civilwarrock wrote:

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

And no. Halt is the C# version of the assembly instruction hlt. All hlt does is pauses the processor until an interrupt is fired. The code above would only work if the PIT was working (which it does not....) because the PIT interrupt would be fired every millisecond.

What can I do to make this work again? Thanks, Matt

I do not think you can install the interrupt handler required for the PIT by conventional means (And I made an agreement with other people and OS's that I will not release any of the 'hacks' that allow me to use unconventional means, sorry :(   ). How ever I still think you can use the PIT (just not with your own handler). Follow this tutorial it helped me alot (Basically just remap the IDT and set up the PIT) http://www.jamesmolloy.co.uk/tutorial_html/5.-IRQs%20and%20the%20PIT.html

Sep 21, 2012 at 12:22 AM
GruntXProductions wrote:
civilwarrock wrote:
GruntXProductions wrote:
civilwarrock wrote:

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

And no. Halt is the C# version of the assembly instruction hlt. All hlt does is pauses the processor until an interrupt is fired. The code above would only work if the PIT was working (which it does not....) because the PIT interrupt would be fired every millisecond.

What can I do to make this work again? Thanks, Matt

I do not think you can install the interrupt handler required for the PIT by conventional means (And I made an agreement with other people and OS's that I will not release any of the 'hacks' that allow me to use unconventional means, sorry :(   ). How ever I still think you can use the PIT (just not with your own handler). Follow this tutorial it helped me alot (Basically just remap the IDT and set up the PIT) http://www.jamesmolloy.co.uk/tutorial_html/5.-IRQs%20and%20the%20PIT.html

What agreement? And why would you agree to it, and alright ill look into it. Thanks.

Coordinator
Sep 21, 2012 at 9:14 AM
For doing sleeps, you have to have a PIT timer working. Problem with that right now, is that it means that the interrupt handlers should be faster than the ticks. This is why (at least) IRQ0 is disabled..


On Fri, Sep 21, 2012 at 2:23 AM, civilwarrock <notifications@codeplex.com> wrote:

From: civilwarrock

GruntXProductions wrote:
civilwarrock wrote:
GruntXProductions wrote:
civilwarrock wrote:

Hmm. Is there some way by using CPU.Halt to count the number of ticks per second then use that to determine with CPU.Halt() how long to be in a while loop to do some sort of sleep function? Since System.Threading.Thread.Sleep() is no longer plugged.

And no. Halt is the C# version of the assembly instruction hlt. All hlt does is pauses the processor until an interrupt is fired. The code above would only work if the PIT was working (which it does not....) because the PIT interrupt would be fired every millisecond.

What can I do to make this work again? Thanks, Matt

I do not think you can install the interrupt handler required for the PIT by conventional means (And I made an agreement with other people and OS's that I will not release any of the 'hacks' that allow me to use unconventional means, sorry :( ). How ever I still think you can use the PIT (just not with your own handler). Follow this tutorial it helped me alot (Basically just remap the IDT and set up the PIT) http://www.jamesmolloy.co.uk/tutorial_html/5.-IRQs%20and%20the%20PIT.html

What agreement? And why would you agree to it, and alright ill look into it. Thanks.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com