OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 2:21 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [Solved] Paging works, but doesn't
PostPosted: Tue Dec 03, 2019 9:42 pm 
Offline
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: jzef, Majestic-12 [Bot] and 209 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group