Keil Logo

C51: Bank Table Entries for Indirectly Called Functions


Information in this article applies to:

  • Keil PK51 All Versions

SYMPTOMS

I have a code banking application that uses indirect function pointers. It appears that the linker does not add an entry to the interbank call table for my indirectly called function. My program appears as follows:

Code Bank 1:

typedef void (code* pback) (void);

void func2 (pback func);

static void return_here (void)  {
  ;
}

void func1 (void)  {
  func2 (return_here);
}

Code Bank 2:

typedef void (code * pback) (void);

void func2 (pback callback_func)  {
  callback_func ();
}

When calling callback_func () in func2 my code should jump to the return_here function. However, it doesn't. It appears that there is no entry in the interbank call table for return_here. How can I solve this problem?

CAUSE

The linker does not create an entry in the call tree for functions that indirectly call functions in other banks. If the call is not listed in the call tree, no entry is made in the interbank call table.

Check the Overlay Map of Module section in your linker map file (*.M51 or *.MAP) for functions called by func2 and you will find that return_here is not listed.

Indirect function references cannot be inferred by the linker for indirect function calls, so you must add them manually.

RESOLUTION

Use the OVERLAY linker directive to add a reference from the func2 function to the return_here function.

In µVision, under Project - Options for Target - Lx51 Misc - Overlay: enter func1 ~ return_here, func2 ! return_here.

This removes the reference from func1 to return_here (since return_here is not actually called from func1) and adds a reference from func2 to return_here (the function call that is made via the function pointer).

Re-link the application and the overlay map shows the correct function references.

?PR?FUNC1?BANK1
  +--> ?PR?_FUNC2?BANK2

?PR?_FUNC2?BANK2
  +--> ?PR?RETURN_HERE?BANK1

Another problem in your example is that the static attribute is applied to the return_here function. The linker cannot generate an interbank call table entry for non-public (static) functions (because there is no public address for a static function). Therefore, you must remove the static attribute for any function that is called from a different code bank.

STATUS

The BL51 Linker V5.03 and LX51 Linker V3.54 issue a warning when the OVERLAY directive adds a call reference to a static function that requires a bank table entry.

If you use a previous version of the tools, make sure that indirectly called functions that are called from different banks are not declared with the static attribute.

MORE INFORMATION

  • Refer to OVERLAY in the BL51 User's Guide.
  • Refer to OVERLAY in the LX51 User's Guide.
  • Refer to Application Note 129: Function Pointers in C51 for a complete discussion of all the ramifications of using function pointers with the C51 compiler.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.