Page 1 of 1

Text printing not working (C)

Posted: Fri Aug 24, 2012 9:16 am
by niou
Hello everybody!

I was happily developing my own kernel and it worked great!
But something went wrong...

This code worked:

Code: Select all

void putch (const char character) {
	volatile ushort *where;
	where = (ushort*)0xb8000 + (1 * 2);
	*where = character | (0x0f << 8);
}
But this one didn't!!

Code: Select all

void putch (const char character) {
	volatile ushort *where;
	ushort x = 1;
	where = (ushort*)0xb8000 + (x * 2);
	*where = character | (0x0f << 8);
}
While the first code prints the character on the screen, the second does nothing!! ):

Re: Text printing not working (C)

Posted: Fri Aug 24, 2012 12:50 pm
by Combuster
My crystal ball says you're either using CLI;HLT; in a VM or you're not using your compiler properly.

Re: Text printing not working (C)

Posted: Fri Aug 24, 2012 1:38 pm
by Nable
Use bochs debugger, use it one more time, do it harder! (:

Re: Text printing not working (C)

Posted: Fri Aug 24, 2012 1:43 pm
by bluemoon
It may not be the root cause but...

Code: Select all

ushort x = 1;
where = (ushort*)0xb8000 + (x * 2);
You are mixing ushort for pointer arithmetic, it's not a good habit, try:

Code: Select all

uintptr_t x = 1;
where = (uint16_t*)( (uintptr_t)0xb8000 + x*2 );

Re: Text printing not working (C)

Posted: Sat Aug 25, 2012 2:24 am
by Love4Boobies
There's no need for uintptr_t there. But yes, I would also like to complain about using ushort, which doesn't exist.