I am trying to load an ELF executable right now but I have been unsuccessful despite my attempts at fixing the code. The program I have been trying to load is a basic statically linked C program. I have fixed a lot of bugs but it still doesn't work. It can locate the program's entry address and load the program headers but when it tries to start from the entry point, the EIP register just increments until it encounters a page that hasn't been mapped. The file is loaded to memory correctly as far as I checked. The problem occurs when I look at the memory address that the program has been loaded. It returns zero instead of 0xC6 (which is the value that is in the .text section of executable file). I have checked the memory address the file has been loaded plus the offset and it returns that value. I haven't loaded the section headers yet but as far as I know statically linked ELF executables can be loaded without loading the section headers. Thanks for any help
Right off the bat I see issues: Your memcpy function changes the values of ESI, EDI, and ECX, but doesn't tell the compiler that. Easiest to fix that would be
Second issue: That count variable should be of type size_t.
This might be it. Next issue is you only allocate a single page per segment. Is that enough? And is the address space free at those locations? You are writing directly to the VGA area, so I'm guessing you run without paging. So the question is: Are the locations mentioned in the ELF file normal RAM or something else?
I found the problem. I have been identity paging the section. Since that memory address doesn't exist physically, it can't write to or read from that address. After changing the code to physically map the address, it worked. I guess I have to improve my paging code...