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.
Im back again and have sort of a problem. I have stripped my code down to figure out a problem I've been having with a piece of code.
When I run my code in bochs, I get this error: pit: io write to port 0040, len=4.
I know it has to do with the PIT but Im not sure why. I would appreciate any help on this matter.
Are you sure that it's somewhere in that function that bochs is complaining about?
It's definitely complaining about one of the outs to 0x40, but it's curious that it only complains once, even though it's the exact same thing just different numbers happening twice. That makes me believe that it's not the outportb (otherwise it would complain about you trying to write 4 bytes every time you wrote to a single-byte port), but I don't see anything obviosuly wrong (other than some interesting parentheses, with four opening and only two closing on the last one )...
beyondsociety wrote:
When I run my code in bochs, I get this error: pit: io write to port 0040, len=4.
this error is typical from a 32-bits "out" command on a 8 bits port. By looking at your code, it looks that everything is fine, but maybe the compiler made something wrong.
You should try to disassemble your pit.o (or whatever) file with "objdump -dRS pit.o" and check the function has been assembled the way you expected.
Oh, and please, name those blasted magic numbers. Even if you're certain that they won't change before the heat death of the universe - and it's rarely a good bet that a constant shall remain constant over time - labelling them will make the code a lot easier to read later.
Please excuse my careless disregard for proper English. Also, I probably should have used defined constants or variables for the hard-coded values.
/*
* Initialize the timer
* Instruct the 8254 Programmable Interval Timer to use the
* specified quantum
*/
void
timer_init (void)
{
timer_counter = 0;
I386_OUTB (0x43, 0x36); /* 00110110b - see HelpPC */
/*
* The 8254 PIT uses a 16-bit counter that counts down at 1.19318 mhz.
* We have to calculate the lsb and msb of the value it gets reset to.
*/
I386_OUTB (0x40, (1193180 / QUANTA_PER_SECOND) & 0xff); /* lsb */
I386_OUTB (0x40, (1193180 / QUANTA_PER_SECOND) >> 8); /* msb */
irq_set_handler (0, timer_handler);
irq_enable (0); /* enable timer irq */
}