[Solved] Paging works, but doesn't

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
User avatar
thosakwe
Posts: 3
Joined: Mon Apr 30, 2018 2:24 am
Location: The Stallion project
Contact:

[Solved] Paging works, but doesn't

Post by thosakwe »

I realized the answer to my question while typing this out, so I'll include the answer below (below the dashed line):

Problem
Sorry for the somewhat confusing title, but I think that's probably the most accurate way to describe the situation. I'll keep the description relatively short, because I think I've mostly narrowed down the issue, and also because I don't want to bombard anyone reading this...

Anyways, in short: I'm working on mapping program segments from an ELF executable into memory, with the aid of bochs and i686-elf-readelf. I am 100% sure that my ELF loader is correct. The executable data ends up in an address, addrA, which is then mapped, in this case, to a 4KB page pointing to the virtual address 0x08048000.

Executing the code was previously leading to all sorts of errors, but I realized that I was executing random garbage data, because for some reason, the data at 0x08048000 didn't reflect what was at addrA.

My first guess was that my code for mapping pages was incorrect, but running `info tab` shows that the address is indeed mapped to the correct region (addrA is 0x526290 in this case):

Code: Select all

0x08048000-0x08048fff -> 0x000000526000-0x000000526fff
Yet, when I dump the memory (both in Bochs and in my kernel), the data at the virtual address is different from what's at addrA.

------------------------------------------------------------------------------------------------------------------

Solution

If you look closely, the error is actually deceptively simple. Note that I want the virtual address to point to 0x526290. However, I have it mapped to 0x526000. So essentially, I'm pointing to an address that's an entire 0x290 bytes off - no wonder things are wrong.

The issue is that my physical address is not page-aligned. It needs to be. The solution was to change my page allocator to page-align address before checking if there were open space. The data regions now match, hooray!
Another OSDev hopeful, just like you.

Project | Github | Twitter | Website
Post Reply