Page 1 of 1

Simple x86 Paging Issue

Posted: Wed Apr 06, 2016 1:21 am
by Gbps
Hey guys,

I'm a new to OS dev and am running into a bit of a problem implementing paging. I've got a higher half kernel working, which maps 0xC0000000 to physical address 0x00 with 4MiB pages. I've now attempted to set 4MiB page 0xC0400000 to map to physical address 0xC0400000 (identity paging), but this fails and the memory is silently not accessible.

I have the bits "present, read_write, page_size" on and address is set to "0xC04".

Here's what I'm getting from Bochs:

Code: Select all

<bochs:5> info tab
cr3: 0x0000000000101000
0xc0000000-0xc03fffff -> 0x0000000000000000-0x00000000003fffff
0xc0400000-0xc07fffff -> 0x00000000c0400000-0x00000000c07fffff
00114316950i[XGUI ] Mouse capture off
<bochs:6> x 0xC0400000
[bochs]:
0x00000000c0400000 <bogus+       0>:bx_dbg_read_linear: physical memory read error (phy=0x00000000c0400000, lin=0x00000000c0400000)
00114316950i[XGUI ] Mouse capture off
Is there something else I need to do in order to allow the physical address 0xC0400000 to be writable?

Thanks!

Re: Simple x86 Paging Issue

Posted: Wed Apr 06, 2016 1:38 am
by iansjack
Do you actually have RAM at that physical address? (As you are running under Bochs, that means have you allocated that much RAM to the virtual machine.)

Re: Simple x86 Paging Issue

Posted: Wed Apr 06, 2016 10:07 am
by SpyderTL
Your virtual machine would need over 3GB of RAM for this approach to work. You should probably just allocate 4MB of memory, and assign that virtual address to that physical memory location.

Re: Simple x86 Paging Issue

Posted: Wed Apr 06, 2016 10:14 am
by Gbps
Duh! You're both right, I didn't allocate enough physical memory on the VM.

That makes a lot of sense. Somehow I made the assumption that the VM would assume the same physical space as your host and allocate memory as needed.

Once I configured bochs to have 4096MiB of physical memory on the guest, everything works fine.

I definitely should just be mapping the lower physical pages into higher pages though!

Thanks again

Re: Simple x86 Paging Issue

Posted: Wed Apr 06, 2016 2:15 pm
by xenos
Actually even with 4GB of RAM it can happen that there is no RAM at 0xC0000000. For example, my notebook has 4GB of RAM, with 3GB in the physical address range 0x00000000-0xBFFFFFFF and 1GB in the range 0x100000000-0x1FFFFFFFF. In the hole between these two is stuff such as graphics card MMIO and such. Usually a memory map, from BIOS or multiboot, should tell you this.