OSDev.org
https://forum.osdev.org/

How to wait? (in C)
https://forum.osdev.org/viewtopic.php?f=13&t=30891
Page 2 of 2

Author:  Antti [ Wed Oct 12, 2016 5:23 am ]
Post subject:  Re: How to wait? (in C)

As an aside, I would avoid "sti; hlt;" because I cannot say for sure whether the delayed effect of enabling interrupts harms "hlt". It probably does not harm it but why take the extra risk? If you take into account the time used for researching the issue thoroughly (CPU errata, for example?), and all kind of stuff, it is just easier to use "sti; nop; hlt;" and move on quickly.

Another classic Antti post, i.e. irrelevant details for side-tracking the discussion. Why I said this is not because I thought this specific small detail did matter. I said it because I think, in general, that we should avoid unnecessary corner cases if we can simply avoid them and be a little bit more defensive.

Author:  mathematician [ Mon Oct 17, 2016 6:46 pm ]
Post subject:  Re: How to wait? (in C)

NunoLava1998 wrote:
iansjack wrote:
http://wiki.osdev.org/Inline_Assembly

i know how to do inline assembly (literally asm();, so easy lol), i ment the assembly code to wait.


Write an interrupt handler to service interrupts from either the PIT, HPET or real time clock. You start the wait by writing a count value to some count variable, and then decrementing the count by one every time the clock ticks. When the count reaches zero, you simply return, if you have been looping, or have the interrupt handler call a function nominated to it by you.

Author:  Schol-R-LEA [ Mon Oct 17, 2016 7:56 pm ]
Post subject:  Re: How to wait? (in C)

@mathematician: While your answer is correct, I suspect that the problem is that NunoLava1998 is thinking in terms of this as something that he would add to the application, rather than as a system service that the application would call - which might be the case for a monotasking system (and even then it would be rather suspect), but would not, in general, be the appropriate solution if more than one process is running.

@Nunolava1998: As I said, to really answer this would take a lot more information about what you are doing, and how you are doing it, and even then, we would not actually give you the code - we'd tell you the general idea, and how to find out the details you need, but the code is up to you to write. If you are just booting bare into a system without setting up multitasking, then you can set up an interrupt service function for the PIT set up as Mathematician described, then use a hlt as described earlier, but replace the unconditional jump with a test (some combination of CMP and conditional jumps, probably) on whatever it is you are waiting for.

Page 2 of 2 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/