What all do I need to achieve this?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Tim, if you could pin point me to some code that would do delays, I would be very grateful. Right now I'm using the keyboard (press any key to continue). Good temporary solution!
Tim

Re:What all do I need to achieve this?

Post by Tim »

You'll need to start handling the timer interrupt (IRQ 0). If you do this, and increment a clock value on each interrupt, measuring time will be easy.
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Should I just init the PICS so that IRQ0 starts at 0x20?

Then just inportb 0x20 to find out when the timer goes off?
Slasher

Re:What all do I need to achieve this?

Post by Slasher »

do you have your idt setup? if you do,you need to write,as Tim just said, an isr for the timer on IRQ0.
A little side info, the x86 in pmode uses the first 32 ints(0 - 31) for its exceptions and faults (read the intel doc,that part is clear ;)) The PIC has to then be reprogrammed to use int values starting from 32(0x20) upwards(you can choose which ones) to use for interrupts like keyboard,timer etc. Most people use continuous numbers ie for the master pic, ints 0x20 - 0x27 (32 to 39) and the slave pic 0x28 - 0x2f (40 - 47) the way the pic is programed, you only have to supply the starting values for ints on master and slave pics after certain command setting have be issued. the docs on programming the pic are clear and easy to implement.

so your isr for timer on irq0, would have to so something like this (at least until you get signalling implemented in your kernel either though passing messages or a shared semaphore between the timer isr and timer driver/task)

In the asm file,(NASM syntax)

Global _timer_counter,_timer_int

_timer_counter dd 0

_timer_int:
inc dword [timer_counter]
mov al,0x20 ;this is the value to ack ints to PIC
out 0x20,al ;send the value to the PIC
iret

Now, if you programmed the PIC to use 0x20+ for the master then the timer int has to be serviced by the code pointed to by the 0x20th entry in your IDT,keyboard int by entry 0x21,floppy ints by entry 0x26,ps/2 mouse ints by entry 0x2c etc
so you point
idt_table[0x20].function address = address of timer_int
idt_table[0x21].function address = address of keyboard_int
idt_table[0x26].function address = address of floppy_int
....
once you've done this,
all you have to do is poll the global variable timer_counter
until it gets to the value desired
eg
void delay(int milliseconds)
{
while(timer_counter < milliseconds) ; // wait for timer to fire
timer_counter=0; //timer has fired so reset variable after each use!
return;
}
hope this helps and not confuses you ;D
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Very helpful! I do not have an IDT set up, at least not manually (I'm using GRUB).

By the way, you said you learned this from the Intel docs? Where can I get those?
Slasher

Re:What all do I need to achieve this?

Post by Slasher »

Try these other Os dev sites
plenty os docs here
http://kos.enix.org/docs.php?lang=en - has the intel Vol 1 to 3 docs
www.osdev.org
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:What all do I need to achieve this?

Post by Solar »

You are guilty of not reading .:QuickLinkz:. <-- read this before you post.
Every good solution is obvious once you've found it.
beyond infinity lazy

Re:What all do I need to achieve this?

Post by beyond infinity lazy »

oy, solar ... Wouldn't a hint be sufficient instead of wagging the Finger Of Judgement?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:What all do I need to achieve this?

Post by Solar »

Sorry, you are right. Hint remains, Finger of Judgement edited away.

I've got a "weak spot" there when it comes to seeing people hurling themselves at some large-scope development efforts without having covered the basics. That's not limited to OS development; SourceForge is full of such "projects"... I'm a bit testy when it comes to this, and the reduced signal / noise ratio resulting from it.

Again, my apologies.
Every good solution is obvious once you've found it.
beyond infinity lazy

Re:What all do I need to achieve this?

Post by beyond infinity lazy »

that's, why i for my part prefer to develop silently, working in the background prior to avising a huuuge project aiming at building a egg-laying wool-milk-swine (shall be: eierlegende wollmilchsau - canna translate it properly to english cuz it's kinda "telling nonsense" *rofl*). Since I have the knowledge and know the nitty gritty... ]:->. being an apprentice of the Dark Arts Of OS helps, even in job life *dg*.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:What all do I need to achieve this?

Post by Solar »

beyond infinity lazy wrote: ...egg-laying wool-milk-swine (shall be: eierlegende wollmilchsau - canna translate it properly to english cuz it's kinda "telling nonsense" *rofl*).
Kind of "Jack of all Trades", or "Swiss Army Knife", with stressing the impossibility (you can't get eggs, wool, milk, and meat from the same animal).

Ich glaube allerdings, Wollmilchsau schreibt man hier gro?... ;-)
Every good solution is obvious once you've found it.
beyond infinity lazy

Re:What all do I need to achieve this?

Post by beyond infinity lazy »

hehe ];->

the "jack of all trades" is known as "der Schnittlauch in allen Suppen" here in vienna, altough "Hansdampf in allen Gassen" will be recognized too. as far as I know, the "eierlegende Wollmilchsau" is mostly applied to so called high sophisticated programs that claim to deliver the all of best solution to every problem.

*gg* sorry for omitting that "Gross/klein - schreibung" sometimes. When one is delving deep beneath the crust of OS Secrets, he might forget about such rules ;p.
Eero Ränik

Re:What all do I need to achieve this?

Post by Eero Ränik »

I "delve deep beneath the crust of OS secrets" too, but that doesn't mean I forget about spelling rules of human languages... ::) Maybe because I don't drink milk... ;D
beyond infinity lazy

Re:What all do I need to achieve this?

Post by beyond infinity lazy »

@eero r?nik:

Oh thou who are wise amongst the wisest, honor is due to thee for thou sharest thy vast knowladge about languages with us ]:->. Wilt thou forgive my faults?

--- snip ---

Well, I 've forgotten to put emphasis on that MIGHT in this very special sentence you have cited. Oh, and I am of cource on too much coffee.
Eero Ränik

Re:What all do I need to achieve this?

Post by Eero Ränik »

I shall... um... think about it... You drink coffee a lot? Like me! I have forgiven! ;D
And we better stop kidding around, unless we don't want to get this thread locked. ;)
That is, if we do want to play like kids, you really should send me a PM...
Post Reply