Page 1 of 2
Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:01 am
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
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:05 am
by xyzzy
Try putting
after the init_timer call to enable interrupts.
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:11 am
by quanganht
well thank you very very very much. But I'm wondering why it keep says "recieved interupt: 6". Why "6" here ?
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 ?
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:28 am
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?
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:34 am
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.
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 9:00 am
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?
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 9:06 am
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>
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 9:26 am
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.
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 12:58 pm
by yemista
just a guess but try making the tick variable volatile since the timer updates it.
Re: Timer won't work ?!?
Posted: Wed Dec 31, 2008 8:49 pm
by quanganht
Nop, no help.
Re: Timer won't work ?!?
Posted: Thu Jan 01, 2009 12:56 am
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
Re: Timer won't work ?!?
Posted: Thu Jan 01, 2009 2:46 am
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
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.
Re: Timer won't work ?!?
Posted: Thu Jan 01, 2009 6:09 am
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)?
Re: Timer won't work ?!?
Posted: Thu Jan 01, 2009 9:13 am
by quanganht
There is no clue of what went wrong. It just ... keep triple-faulting my @ss
Re: Timer won't work ?!?
Posted: Thu Jan 01, 2009 10:40 am
by Combuster
your bochs dump?