Cannot use call instruction with a name of a function when running on a different core

65 views Asked by At

I recently started writing a native hypervisor, and in order to support a multicore system, I must initialize the hypervisor on all cores. Using Intel's x2APIC, I am sending a SIPI interrupt from the BSP to other cores. After issuing the interrupt, I am unable to call a function that resides in a different file (a C function) using the name of the function. When I am trying to do that, the CPU runs into a triple fault.

The code looks like this (generated using objdump -dj .text):

000000000330049c <ApicLongMode>:
330049c: mov    $0x770000,%esp
33004a1: mov    0x4000,%rdi
33004a9: callq  3303a2c <InitializeSingleHypervisor>

However, the call succeeds when using the address of the function instead of its name:

000000000330049c <ApicLongMode>:
330049c: mov    $0x770000,%esp
33004a1: mov    0x4000,%rdi
33004a9: callq  *0x4008

In the above case, the address 0x4008 contains the address of the InitializeSingleHypervisor function.

Note that when I am running the exact same code (the first piece of code) from the BSP, the function is successfully called.

I am using nasm as an assembler and ld as a linker. Of course, I have made sure to declare the function as extern before calling it.

Can someone explain this behavior?

0

There are 0 answers