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.
How to wait? (in C)
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
Re: How to wait? (in C)
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.NunoLava1998 wrote:i know how to do inline assembly (literally asm();, so easy lol), i ment the assembly code to wait.iansjack wrote:http://wiki.osdev.org/Inline_Assembly
The continuous image of a connected set is connected.
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
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.
@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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.