Simple x86 Paging Issue

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
Gbps
Posts: 2
Joined: Wed Apr 06, 2016 12:20 am

Simple x86 Paging Issue

Post 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!
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Simple x86 Paging Issue

Post 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.)
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Simple x86 Paging Issue

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Gbps
Posts: 2
Joined: Wed Apr 06, 2016 12:20 am

Re: Simple x86 Paging Issue

Post 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
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Simple x86 Paging Issue

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply