Timer won't work ?!?

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.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Timer won't work ?!?

Post by quanganht »

Can someone look at my code here http://unnamed-0s.googlecode.com/files/ ... -0.0.0.rar and tell me why the f**k the timer wont' work ? I'm stucking with it dor nearly two weeks now :(
"Programmers are tools for converting caffeine into code."
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Timer won't work ?!?

Post by xyzzy »

Try putting

Code: Select all

__asm__ volatile("sti");
after the init_timer call to enable interrupts.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

well thank you very very very much. But I'm wondering why it keep says "recieved interupt: 6". Why "6" here ? :oops:

EDIT: one more silly question: variable 'tick' start at 0. After the first time IRQ0 fired, 'tick' is 1 ( that's fine). But after the second time, it goes to 2097671. WTF is wrong with it ? :oops: :?
Last edited by quanganht on Wed Dec 31, 2008 8:30 am, edited 1 time in total.
"Programmers are tools for converting caffeine into code."
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Timer won't work ?!?

Post by yemista »

I was looking at your source and Im wondering, why does your code in console.c write to video memory, but it seems like you are setting up protected mode? Does this work?
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

yemista wrote:I was looking at your source and Im wondering, why does your code in console.c write to video memory, but it seems like you are setting up protected mode? Does this work?
What do you mean? Can you quote the code that make you think so? :?
It's can't be. 'Cause GRUB had set up Pmode for me even before my kernel start. All I have to do is load my own GDT, IDT.
"Programmers are tools for converting caffeine into code."
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Timer won't work ?!?

Post by yemista »

Ok I am still learning alot about these things myself, but I thought that you can only access the VGA by writing directly to video memory while in real mode, and if you try to same code in protected mode, not only will the address be interpretted differently, but you wont have the video interrupt like you did in real mode. Would you be able to take a copy of the video interrupt while in real mode, setup pmode, and then set an IDT entry with that code?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Timer won't work ?!?

Post by Combuster »

The VGA interrupt expects that it is being run from real mode. Because of the addressing changes you can't call that code anymore from protected mode.

You can still access the VGA from the standard methods: video memory and I/O ports.

<shameless plug>VGA Hardware</shameless plug>
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

Ok, so now I keep receiving interupt 6, which means 'Undefined OPCode instruction'. Err ?

And if I turn optimization OFF, the machine seems to be triple faulted every time tick reach 1. :(
"Programmers are tools for converting caffeine into code."
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Timer won't work ?!?

Post by yemista »

just a guess but try making the tick variable volatile since the timer updates it.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

Nop, no help.
"Programmers are tools for converting caffeine into code."
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

I found it out now. It the 'sti' instruction make VMware reset over and over again. But when I compile with -O1 option, triple-fault is replaced by firing interupt 6 'Undefined OPCode instruction'. F**K them.

EDIT: to AlexExtreme: asm volatile ("sti") is stupid, as I read on BrokenThorn:
As you know, if we enter protected mode all interrupts must be disabled. If we have not done this, our system will triple fault immediately on the next clock tick.
So there must be somthing *REALLY* wrong with my timer or isr code :x
"Programmers are tools for converting caffeine into code."
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Timer won't work ?!?

Post by xyzzy »

quanganht wrote:EDIT: to AlexExtreme: asm volatile ("sti") is stupid, as I read on BrokenThorn:
As you know, if we enter protected mode all interrupts must be disabled. If we have not done this, our system will triple fault immediately on the next clock tick.
So there must be somthing *REALLY* wrong with my timer or isr code :x
No, it's not stupid. It's what you need to do to get interrupts to fire. The fact that its faulting means that your IDT is probably set up incorrectly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Timer won't work ?!?

Post by Combuster »

Have you tried running the code in bochs and see what it does there (if it breaks it usually does that with more verbose info)?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Timer won't work ?!?

Post by quanganht »

There is no clue of what went wrong. It just ... keep triple-faulting my @ss :oops:
"Programmers are tools for converting caffeine into code."
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Timer won't work ?!?

Post by Combuster »

your bochs dump?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply