How to wait? (in C)
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
How to wait? (in C)
I have managed to link/etc. the assembly/C files, and i'm now editing a functions file called funct.h which can do simple VGA functions (put pixel, start VGA, fill screen), and i want to implement a wait() function and be informed if there is a wait function from the default libs (and if then, what lib and how to use it). How do i do this?
I'm using C and editing a header.
I'm using C and editing a header.
Last edited by NunoLava1998 on Mon Oct 10, 2016 2:17 am, edited 2 times in total.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
Re: How to wait?
Hello,
The wait function is based upon :
- A programmable timer that generates interrupts ( PIT, HPET...)
- A task switch. Or , if you don't have any task to switch to ,the hlt instruction. ( Remember to enable interrupts before doing HLT)
The PiT is easy to configure, and there are tutorials about it in the wiki.
The wait function is based upon :
- A programmable timer that generates interrupts ( PIT, HPET...)
- A task switch. Or , if you don't have any task to switch to ,the hlt instruction. ( Remember to enable interrupts before doing HLT)
The PiT is easy to configure, and there are tutorials about it in the wiki.
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: How to wait?
It's in C. I will include it in a header file called "funct.h" which is similar to "tty.h" in Meaty Skeleton.Boris wrote:Hello,
The wait function is based upon :
- A programmable timer that generates interrupts ( PIT, HPET...)
- A task switch. Or , if you don't have any task to switch to ,the hlt instruction. ( Remember to enable interrupts before doing HLT)
The PiT is easy to configure, and there are tutorials about it in the wiki.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
Re: How to wait? (in C)
And..?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: How to wait? (in C)
i like cats i had nothing to say after what i said and was waiting for an answer so i said this.Roman wrote:And..?
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
- MichaelFarthing
- Member
- Posts: 167
- Joined: Thu Mar 10, 2016 7:35 am
- Location: Lancaster, England, Disunited Kingdom
Re: How to wait? (in C)
I suppose that is an example of a wait function
-
- Member
- Posts: 116
- Joined: Thu May 06, 2010 4:34 am
- Libera.chat IRC: peterbjornx
- Location: Leiden, The Netherlands
- Contact:
Re: How to wait? (in C)
When writing a kernel you have to write all functions you want to use yourself, you do not have any kind of standard library available, please see the wiki.
Re: How to wait? (in C)
Whatever the language is, you will still have to make your CPU execute assembler. It's your job to make the sugar candy around it and call it "void wait(unsigned howmuch)", "(define wait(howmuch))" or whatever ..
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: How to wait? (in C)
inline assembly is not a thing by yo.. okay, but how do i do it?Boris wrote:Whatever the language is, you will still have to make your CPU execute assembler. It's your job to make the sugar candy around it and call it "void wait(unsigned howmuch)", "(define wait(howmuch))" or whatever ..
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: How to wait? (in C)
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
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
Re: How to wait? (in C)
You have already been told that. I assume you are not asking for complete code. (That's not how this site works.)
Re: How to wait? (in C)
If you wanted to be incredibly lazy you could just have a loop with hundreds of thousands of iterations. Just make sure the compiler doesn't optimize it out.
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
Compiler Development Forum
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: How to wait? (in C)
that uses clock cycles, so it really depends on your CPU. Not going for that one.zenzizenzicube wrote:If you wanted to be incredibly lazy you could just have a loop with hundreds of thousands of iterations. Just make sure the compiler doesn't optimize it out.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: How to wait? (in C)
Unless this is a direct translation of an idiom from some other language, then I assume you are referring to the English language pun, "like cats, it goes without saying" (based on the general disdain cats seem to show to human endeavors, leaving in the middle of being petted and so forth). That usually is meant to imply that the implications of something were obvious, which, well... the fact that Roman asked that indicates it might not have been so obvious after all.NunoLava1998 wrote:i like cats i had nothing to say after what i said [...]Roman wrote:And..?
As for the solution, that is going to depend on the OS itself - it isn't something any canned response will give.
Usually, the solution in a multitasking system is to provide a system call that requests that the scheduler halt the running process and place it in the wait queue until after a given period of time. How you would implement that is entirely dependent on your scheduler design, and even if we had access to it (you do have it in a publicly accessible offsite version control repo, right? If not, then shame on you, drop everything and do that now), we could not and would not give you the solution because at that point it would become our OS project, not yours.
For the case where all processes are waiting, you would normally have a dummy no-op process, called the null process, which on an x86 CPU can often be just:
Code: Select all
pause_loop:
sti
hlt
jmp short pause_loop
Note that this depends on the interrupt handlers and the scheduler being in place first. This approach will not work inline to a process, as it will hang the process - the whole point is for the null process to hang itself, you see, and if you insert this loop into some other code you will never break out of it. It also is not sufficient for a multi-core system, as you would need a null process for each core.
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.