I am trying to build my own hobby operating system and is trying to create load and run flat binary file into the heap and then execute it in protected mode?
I have tried creating a pointer and then copied a 45 bytes function to its address and then jump into it, but it gave interrupt 13 (General Protection fault)
Here is my code https://github.com/s0ubhik/myos
void aa(){
printkc("H OH O H", 0xb);
}
void kernel_main(unsigned long kernel_stack){
...
unsigned char* m = (unsigned char*) &aa;
unsigned char* b = (unsigned char*) 0x600000;
for (int i=0; i < 45; i++){
print_hex(m[i], 2);
b[i] = m[i];
printk(" ");
}
printk("\n");
for (int i=0; i < 45; i++){
print_hex(b[i], 2);
printk(" ");
}
printk("\n");
void (*func_ptr)(void) = (void (*)(void))0x600000;
func_ptr();
....
}
Look at this section where I load the contents of function aa into the heap 0x600000 and then try to jump to it

aafunction is a problem. The x86 call instruction is relative, so you can't relocate the function and expect it to work, unless you fix up all those addresses. From building your code, it looks like it's trying to be position-independent and make that call through the GOT, but the calls it makes to locate the GOT don't work either...