23
votes

About 15 years ago, I used to amuse myself and annoy my CS teacher by writing bad code that would directly modify the text on the monitor. This was/is easily done by accessing video memory at 0xB8000 on VGA-equipped PC-compatibles.

Fast forward to today, I decided to try out my old trick through a debug port that gives me access to read physical memory. To my gratification, it still worked on the first platform I tried it on. Then, dishearteningly, I discovered that it doesn't work on many other systems. It seems that the systems it doesn't work on all have UMA (shared-memory) graphics.

So, a question for all of you BIOS writers, low-level OS guys, and video driver gurus - if I'm in regular 80x25 color textmode on a PC-compatible system with shared graphics memory, in real mode, and the contents of 0xb8000 - 0xB8FFF are all 0xFF instead of giving me what's on the screen, where did the screen buffer go?

3
Just to confirm, you are in true real mode, and not a "DOS" console running on Windows, correct?David
Real, honest-to-god real mode (it's a BIOS setup screen that I'm capturing).Drew Shafer
If it's not 0xB8000, it might be a monochrome monitor. In that case, use 0xB0000.user11462042

3 Answers

17
votes

Ah, if it's a BIOS screen then all bets are off. The fact that it's a BIOS on a motherboard with integrated graphics leans things even more in favor of video strangeness.

In all likelyhood "classic" VGA functionality is for all intents emulated. With an external video card this would be invisible to the BIOS - it still sees a VGA video card. But a BIOS hardwired to the video card wouldn't need to setup the fake VGA layer and old school 20 bit address space memory mapping just to stick some text on the screen.

Instead the BIOS may interface directly with the card (via some proprietary mode) until the operating system is actually going to be started up, at which point it does memory mapping itself. This has a major advantage in that for a card that shares main memory, you don't get a blank screen on startup if your RAM is incorrectly installed (instead the video cards propritary BIOS mode could use a buffer normally reserved for some other purpose, allowing you to get into the BIOS and see 0MB of RAM installed)

6
votes

The CGA (Color Graphics Adapter) and MDA (Monochrome Display Adapter) cards used different regions. One (color) is at 0xB8000; but monochrome starts at 0xB0000. Remember, you could have both displays active on the machine at once.

See DOS Memory Map (although it has a typo in the offset for CGA - should be 8000h not 0800h).

As far as VGA (Video Graphics Array) goes, its memory starts lower, at the 640K boundary at 0xA0000 and continues for 64K - but it can go beyond, as the card could have up to 256K. Some sample code for programming VGA is here. But it isn't quite so simple as it has multiple video modes. You might try here for some help.

Are you sure you have VGA, and not EGA or XGA or Super-VGA? All of those have slightly different semantics... But still, I'm pretty sure any of those should put text either at 0xB0000 or 0xB8000. What happens when you type either

MODE MONO

or

MODE CO80

-- does that affect the display? Those would switch from one adapter text mode to the other, under DOS.

3
votes

It might be the case that virtual memory is enabled at that point.

For eg., I was trying to write to the video buffer in the iPXE codebase and it didn't reflect on the screen. After investigating, I realized that I needed to call the function:

phys_to_virt(0xB8000);

to be able to write to the video buffer directly.