PIT problem

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.
Post Reply
beyondsociety

PIT problem

Post 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));
}
HOS

Re:PIT problem

Post 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...
beyondsociety

Re:PIT problem

Post 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.
bkilgore

Re:PIT problem

Post 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 :))...
User avatar
Solar
Member
Member
Posts: 7632
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:PIT problem

Post by Solar »

If that code is really copy & paste, you have a syntax error. Both outportb calls to 0x40 have mismatched parantheses.
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:PIT problem

Post 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.
Schol-R-LEA

Re:PIT problem

Post 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.
beyondsociety

Re:PIT problem

Post 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.
kaos

Re:PIT problem

Post 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 */
}
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:PIT problem

Post 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.
kaos

Re:PIT problem

Post by kaos »

This could work too:

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