OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 10:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: How to wait? (in C)
PostPosted: Wed Oct 12, 2016 5:23 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
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.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 17, 2016 6:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Dec 15, 2006 5:26 pm
Posts: 437
Location: Church Stretton Uk
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.

_________________
The continuous image of a connected set is connected.


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 17, 2016 7:56 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
@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.

_________________
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 170 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group