Video RAM at 1B8000 ???

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
aymanmadkour
Posts: 11
Joined: Sat Feb 05, 2005 12:00 am

Video RAM at 1B8000 ???

Post by aymanmadkour »

Hi All...

I have written a basic kernel that works in PMode. I have a GDT with 2 segment descriptors for Code and Data segments, both starting at physical address 0x00000000 and ending at 0xFFFFFFFF.
The kernel works fine on Bochs, but on a real machine, I have a very strange problem.

Video RAM is normally mapped at address 0xA0000, and in text mode, we use the address space starting at 0xB8000.
On a real machine, Video RAM is mapped at BOTH 0xA0000 AND 0x1A0000!! Which means that when I write 0x41 at address 0xB8000 OR 0x1B8000, the character 'A' appears on the screen. However, writing at address 0x2B8000 does nothing (Thank God).

Is this normal? Can anyone please tell me what is going on?

Ayman Madkour
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re: Video RAM at 1B8000 ???

Post by gaf »

Hi,
sounds as if you didn't enable the a20 line-gate which is needed to access memory above the 1 MB mark. Without it, addresses higher than that will just be truncated to fit this restriction. Have a look at http://www.win.tue.nl/~aeb/linux/kbd/A20.html for a detailed explanation and some code examples to enable it.

regards,
gaf
aymanmadkour
Posts: 11
Joined: Sat Feb 05, 2005 12:00 am

Re: Video RAM at 1B8000 ???

Post by aymanmadkour »

If you are talking about setting bit 0 in CR0 register, then I DID enable the A20 gate. Am I missing something?

Code: Select all

MOV       EAX, CR0
OR        EAX, 0x00000001
MOV       CR0, EAX
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re: Video RAM at 1B8000 ???

Post by gaf »

Setting the pmode bit in cr0 won't automatically enable the a20 gate. The purpose of the gate is to ensure backward compability with programs written for real-mode (and that exploited the fact that addresses greather than 0x100000 were back then simply truncated) when pmode was introduced. Since such apps are rather rare today, bochs aswell as some of todays BIOSes simply boot with the a20 line-gate enabled, but you unfortunately can't rely on that. You therefore always have to enable it once pmode was entered as described on the site I pointed you to.

regards,
gaf
aymanmadkour
Posts: 11
Joined: Sat Feb 05, 2005 12:00 am

Re: Video RAM at 1B8000 ???

Post by aymanmadkour »

Hey.. It worked!

Thanks... :)
Post Reply