Casting a ELF entry addr into a function in GNU EFI

97 Views Asked by At

How would I cast a Elf64_Ehdr.e_entry into a function?

eg: void (*kernel_function)() = (void (*)())*kernel_entry_point;

Current code: (header is a Elf64_Ehdr) | The version of elf.h included is identical to /usr/include/elf.h

EFI_PHYSICAL_ADDRESS* kernel_entry_point;

// get entry
*kernel_entry_point = (&header)->e_entry;
//cast into a usable function
void (*kernel_function)() = (void (*)())*kernel_entry_point;

//call the casted function
kernel_function();

I've tried this but the EFI application exits before the kernel can write a string. (which in this case is "Hello World!")

If anyone can help me with this I'd appreciate it.

EDIT:

Forgot to include kernel code, so here it is

#include <stdint.h>

void write_string( int colour, const char *string )
{
    volatile char *video = (volatile char*)0xB8000;
    while( *string != 0 )
    {
        *video++ = *string++;
        *video++ = colour;
    }
}

extern "C" void _start()
{
    write_string(15, "Hello world! \n");    

    return;
}
0

There are 0 best solutions below