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
------------------------------------------------------------------------------------------------------------------
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!