Page 1 of 1

PIT problem

Posted: Tue Sep 30, 2003 6:27 pm
by beyondsociety
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.

Code: Select all

void pit_timer(void)
{
// Reprogram the clock interrupt to 100 Hz
outportb(0x43, 0x36);
outportb(0x40, (11392 & 0xFF);
outportb(0x40, (((11392 >> 8) & 0xFF);
}
I wonder if It has something to do with my outportb function.

Code: Select all

__inline__ void outportb(unsigned port, unsigned val)
{
__asm__ __volatile__("outb %b0,%w1"::"a"(val), "d"(port));
}

Re:PIT problem

Posted: Tue Sep 30, 2003 7:21 pm
by HOS
i dont really remember what these numbers mean, but you have

Code: Select all

outportb(0x43, 0x36);
and i have

Code: Select all

outportb(0x43, 0x34);
and mine works :)

but like i said, i dont remember where i got the 0x34 from, some manual on the PIT...

Re:PIT problem

Posted: Tue Sep 30, 2003 8:45 pm
by beyondsociety
i dont really remember what these numbers mean, but you have
Code:outportb(0x43, 0x36);

and i have
Code:outportb(0x43, 0x34);

and mine works

but like i said, i dont remember where i got the 0x34 from, some manual on the PIT...
Tried what you suggested and I still get the same error.

Re:PIT problem

Posted: Tue Sep 30, 2003 10:16 pm
by bkilgore
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 :))...

Re:PIT problem

Posted: Tue Sep 30, 2003 11:50 pm
by Solar
If that code is really copy & paste, you have a syntax error. Both outportb calls to 0x40 have mismatched parantheses.

Re:PIT problem

Posted: Wed Oct 01, 2003 1:46 am
by Pype.Clicker
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.

Re:PIT problem

Posted: Wed Oct 01, 2003 9:15 am
by Schol-R-LEA
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.

Re:PIT problem

Posted: Wed Oct 01, 2003 10:07 am
by beyondsociety
If that code is really copy & paste, you have a syntax error. Both outportb calls to 0x40 have mismatched parantheses.
I retyped it word for word and so I have noticed the mismatched parantheses. The original code is correct.
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.
I will try this and get back to you on the results.

Re:PIT problem

Posted: Thu Oct 02, 2003 5:17 am
by kaos
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 */
}

Re:PIT problem

Posted: Thu Oct 02, 2003 6:56 am
by Pype.Clicker
another thing you could try is

Code: Select all

__inline__ void outportb(unsigned port, unsigned char val)
{
__asm__ __volatile__("outb %b0,%w1"::"a"(val), "d"(port));
}
so that the compiler doesn't try to use a 32 bits register for "val" in the out command.

Re:PIT problem

Posted: Thu Oct 02, 2003 7:01 am
by kaos
This could work too:

#define I386_OUTB(address, data) \
asm __volatile__("outb %%al, %%dx" : : "a"((data)), "d"((address)))