Q:图形方式下,在进入保护模式后、分页前,可以正常直接写屏,线性地址为:0xE0000000

开启分页后,我没有把0xE0000000映射到物理内存上,不能把数据写到该地址

而映射好后,写到物理内存了,但屏幕上却没反映。

我该怎么做?

A:若你映射正确,那么屏幕上总会出现一些痕迹。估计你映射错了地方。

Accessing Linear Framebuffer Memory

Once you have initialized the graphics hardware into a mode that supports a hardware linear

framebuffer, you need to create a pointer that your application can use to write to the linear

framebuffer memory. The first thing you should realize is that the linear framebuffer location

reported in the ModeInfoBlock for the mode you are using is a physical memory address, and

cannot be used directly from protected mode applications. Before you can use the memory you

must use the services your operating system provides to map the physical memory to a linear

memory address, and then map this linear address into your applications memory space. Under

DPMI mapping the linear memory is done with DPMI function 0x800, and equivalent functions

exist under other operating systems.

The steps involved in mapping in a linear framebuffer region are as follows (32-bit protected

mode only):

1. Map the physical memory address to a linear memory address (using DPMI function

0x800 for example).

2. Find the base address of the default DS selector for your operating environment.

3. Subtract the base address from the linear address computed in step 1 to give you a

near pointer (relative to DS) that you can use from within your code.


以上所讲的Linear Framebuffer memory,是物理地址,开启分页后不能影响地址的对应关系,也就是说如果分页前Linear Framebuffer memory是0xE0000000(不要怀疑,确实是那么大的值),那分页后访问0xE0000000就应该通过页表映射到物理地址0xE0000000。


总结:

1.调试时在Bochs机上通过,而Vmware不行,为什么?

测试是在Bochs上进行的,因为调试方便。此时看到Linear Frambuffer memory是0xE0000000,于是就自作主张,在程序里向这个地址写0xFF00,果然有效。但用Vmware,嗯?怎么还是一片黑黑的?过了好几天,才明白过来:Vmware里的Linear Framebuffer memory不是0xE0000000!!!


2.终于调试完成。哎,最后Vmware上没试过,但想想应该是可以了的。

原来VESA告诉我的0xE0000000不是线性地址,是真实的物理地址,那段英文也说了,是physical memory!

所以我们要把分页后的程序地址0xE0000000映射到物理地址0xE0000000!弄好后bochs就可以了。

因为Vmware上的VESA告诉的物理地址不是0xE0000000,所以在Vmware上运行不通过。