8253/8254 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
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

8253/8254 PIT problem

Post by neon »

Hey everyone,

I have a weird problem with my code. It is somewhat hard to explain
without seeing the code first, so Ill post the code first.

I am implimenting an routines for a system timer in my OS using
the 8253/8254 PIT. I wrote code to test the timer:

Code: Select all

	Sys_gotoxy (0,24);
	Sys_settextcolor (COL_BLUE,COL_WHITE);
	Sys_puts ("MicroOS Operating System Starting up...                                         ");

	while (1) {
		Sys_gotoxy (0,20);
		Sys_puts ("PIT Test uses sine wave to generate pulses. This text should blink.");
		Sys_Timer_Wait (500);
		Sys_gotoxy (0,20);
		Sys_puts ("                                                                   ");
		Sys_Timer_Wait (500);
	}
(I know, the "sys" prefex is getting redundent ;)

This code is supposed to blink (using my timers wait() routine)
the text "PIT Test..etc". Note that it is in an infinity loop.

Here is Sys_Timer_Wait():

Code: Select all

volatile long int _Sys_TickCount = 0;
//etc...

void Sys_Timer_Wait (int ticks) {

	unsigned long ulTicks;

	ulTicks = _Sys_TickCount + ticks;
	while (_Sys_TickCount < ulTicks)
		;

	// _Sys_TickCount is updated by interrupt,
	// so we dont need to update here
}
The timer interrupt is set in the IDT, and just increments
the global system counter (_Sys_TickCount)

Now for the problem...

-> It works fine in the Bochs emulator (only the "PIT test" string blinks,
as it should)

-> On 3 laptops, *both* strings (the one in the infinity loop, the "PIT test"
string, *And* the string *outside* the infinity loop ("MicroOS is starting")
blink.

Why would the string outside the loop blink as well..?

Also, every 28 blinks, the "PIT test" string (The one that should
blink) dissapears. 28 blinks later (The "MicroOS is starting" string
still blinks, as it shouldnt), the "PIT test" reappears.

What could cause this?

-> On PCs (I only tested 1 here), it causes a GPF.

I suspect the GPF and the odd string problems with laptops are somehow
related. (It works in Bochs though)

By "blink", I mean the text dissapears, and then reappears (Only those
two strings. No other string output is effected by the timer)

The blinks are consistant, so I know the interrupt is getting executed
at constent intervals.

Im not sure what could cause these problems, and am looking for any
possible suggestions here.

I am using NASM and GCC.

Thanks for any suggestions!
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

You could use vga hardware to acheive that result (I'm not sure whether qemu or boch actualy do the blinking though).
An article on this can be found Here
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Thanks for the advice.

Actually, I set up the blinking for a way to see the timing and wait
routines, and to insure the timer interrupt is working.

I do wonder why it would GPF on a PC, and how the text is blinking
from outside an *infinity loop* on laptops. ..Weird.

I am currently writing a printf routine so I could provide more detail
in my kernels RSOD when it GPFs. that way, Ill be able to post more
information here.

I was just hoping someone here experienced the same problem
like this one..

Ill check the link out, though :)

Thanks!
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post by urxae »

Perhaps you inadvertently also enabled hardware blinking? Your color code:

Code: Select all

Sys_settextcolor (COL_BLUE,COL_WHITE);
Does whichever of those is the background color have bit 3 set (i.e. is it > 7)?

There are 16 foreground colors, but only 8 background colors. The upper bit of the background is used for blinking.
(IIRC technically that bit is also used for the color, but by default the upper 8 colors are the same as the lower 8 so without reprogramming the colors it's effectively just a 'blink' bit)

No idea why it would GPF though. Perhaps unrelated?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

There are 16 foreground colors, but only 8 background colors.
Didnt know that :)

In settextcolor(), COL_BLUE=0001b, COL_WHITE=1111b
They are packed into a 32bit int, and COL_WHITE was the
background, so the end color is (background color first):

11110001b

The background colors third bit is set (Bit 7)

I am going to try a different color (whose value is <=7) and see what
happens.

Also, I finished by printf() routine, and am updating my RSOD so
I could debug and provide more information on the GPF. Perhaps
it is a different issue...

Thanks for the help! :D
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

I set the background color to a light gray color (7, 0111), and it seems to
have fixed the blinking problem! (Although my laptops timing seems to
be drastically different/slower then in Bochs)

I wont be able to test the GPF until later today though.

Thanks again! :D
Post Reply