i8254 - Cannot change Timer frequency
Hi all,
I posted the following question on the QEMU general forum few weeks ago
(http://qemu-forum.ipi.fi/viewtopic.php?f=3&t=4638#p13814). Someone adviced me to post it directly on the development mailing list. I already tried to look up into the archive but I didn't find any answers. Since several people seems to be concerned by this issue, I finally decided to do it.
Thanks in advance for your help.
Best Regards,
Adrien
PS: please find below the copy/paste from the QEMU forum.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
i8254 - Cannot change Timer frequency
by alebre on Wed Sep 17, 2008 4:26 pm
Hi all,
In the context of study, we have to develop a simple operating system from scratch. To develop our ''kernel'' we are using QEMU.
For few days, we have fighted with the I8254 chip in order to create a timer for our system.
Based on the code provided in the Simple OS
(http://sos.enix.org/lxr/source/hwcore/i8254.c), we are trying to change the frequency.
Unfortunately, whatever the value of nb_tick, the frequency does not change. Here, I just copied the related code. We tried by setting the nb_tick with 11931, 1193 and 119 directly in the following functions. Unfortunately, the time frequency (according to the IRQ timer handler) is still the same .
Does anyone have an idea ?
Thanks in advance,
Adrien.
/** 82c54 clock frequency */
#define I8254_MAX_FREQ 1193180
/* Ports to communicate with the 82c54 */
#define I8254_TIMER0 0x40 #define I8254_TIMER1 0x41 #define I8254_TIMER2 0x42
#define I8254_CONTROL 0x43
...
int i8254_set_frequency(unsigned int freq){
unsigned int nb_tick;
if (freq <= 0)
return -255;
/* Compute counter value */ nb_tick = I8254_MAX_FREQ / freq;
/* Counter must be between 1 and 65536 */
if (nb_tick > 65536)
return -255;
if (nb_tick <= 0)
return -255; /* The i8254 interprets 0 to mean counter == 65536, because 65536
cannot be coded on 16bits */
if (nb_tick == 65536)
nb_tick = 0;/* We want to configure timer0, we want to send both LSB+MSB to set
timer0 freq (-> 0x30), and we configure timer0 in mode 2, ie as a
rate generator (-> 0x4) ==> 0x34 */ outb(0x34, I8254_CONTROL);
/* Send LSB of counter first */
outb((nb_tick & 0xFF), I8254_TIMER0);
/* Send MSB of counter */ outb((nb_tick >> 8) & 0xFF, I8254_TIMER0);
return 1;
}
Re: i8254 - Cannot change Timer frequency
by alebre on Wed Sep 17, 2008 4:37 pm
What is the behavior of QEMU with regard to such instructions ? Does QEMU emulate the I8254 chip or does it simply forward the instruction to the host OS ? In that case, the host OS could simply does not consider such an instruction ?
Adrien, still looking for some explanations....
Hi Adrien...
Quoted 7 lines · adrien lebre
Re: i8254 - Cannot change Timer frequency
by alebre on Wed Sep 17, 2008 4:37 pmWhat is the behavior of QEMU with regard to such instructions ? Does QEMU emulate the I8254 chip or does it simply forward the instruction to the host OS ? In that case, the host OS could simply does not consider such an instruction ?
I can not really answer about the i8524 emulation behaviour, but all I know is that Qemu will turn it into setitimer() or RTC reprogramming (via /dev/rtc). So the chance is, the granularity could be not as fine as you expect. Especially if you end up using OS supplied timer, the granularity will be 1/HZ.
Not an expert...just want to share my thoughts.
regards,
Mulyadi.