OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:35 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to wait? (in C)
PostPosted: Sun Oct 09, 2016 12:44 pm 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Last edited by NunoLava1998 on Mon Oct 10, 2016 2:17 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: How to wait?
PostPosted: Mon Oct 10, 2016 12:26 am 
Offline
Member
Member

Joined: Sat Nov 07, 2015 3:12 pm
Posts: 145
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.


Top
 Profile  
 
 Post subject: Re: How to wait?
PostPosted: Mon Oct 10, 2016 1:19 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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.

It's in C. I will include it in a header file called "funct.h" which is similar to "tty.h" in Meaty Skeleton.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 2:20 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
And..?

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 2:23 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
Roman wrote:
And..?

i like cats i had nothing to say after what i said and was waiting for an answer so i said this.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 5:14 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 10, 2016 7:35 am
Posts: 167
Location: Lancaster, England, Disunited Kingdom
I suppose that is an example of a wait function :)


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 6:05 am 
Offline
Member
Member

Joined: Thu May 06, 2010 4:34 am
Posts: 116
Location: Leiden, The Netherlands
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.

_________________
posnk ( a simple unix clone )
twitter profile - security research, die shots and IC reverse engineering, low level stuff


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 10:47 am 
Offline
Member
Member

Joined: Sat Nov 07, 2015 3:12 pm
Posts: 145
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 ..


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 11:37 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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 ..

inline assembly is not a thing by yo.. okay, but how do i do it?

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


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

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
http://wiki.osdev.org/Inline_Assembly


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Mon Oct 10, 2016 1:06 pm 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


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

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You have already been told that. I assume you are not asking for complete code. (That's not how this site works.)


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

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
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


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Tue Oct 11, 2016 12:24 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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.

that uses clock cycles, so it really depends on your CPU. Not going for that one.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to wait? (in C)
PostPosted: Tue Oct 11, 2016 11:29 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
NunoLava1998 wrote:
Roman wrote:
And..?

i like cats i had nothing to say after what i said [...]


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.

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:
pause_loop:
        sti
        hlt
        jmp short pause_loop


Assuming that the interrupts are set (hence the first instruction), then any new interrupt will trap to the scheduler, and if some other process is now schedulable, it will go to that, otherwise, it returns to the loop at the JMP instruction.

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.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 26 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