CONTROL HOW LIBRARIES ARE USED AND/OR PLACED INTO MEMORY

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CONTROL HOW LIBRARIES ARE USED AND/OR PLACED INTO MEMORY

1,052 Views
JaimeR
Contributor III
I am writing a Loader and some of the code in my loader is calling instructions from this library, the problem is the compiler locates these library instructions into the segments I need to erase.

The question is:
Is there any pragma or instruction to avoid jumping to libraries in specific functions?
I mean, can you specify the compiler to copy this instruction into your function instead of jumping to the library?

This is a very simple example, but I hope it explains what I need to do:
//In ansiis.lib
void Increment(int & P)
{
   P++;
}

//In bootloader.c
void Function()
{
   int A = 1;
   Increment(A); 
}

I want the compiler to to this

void Function()
{
   int P = 1;
   P++; 
}

instead of this

void Function()
{
   int P = 1;
   JMP Increment; 
}

Any ideas, comments, help, will be appreciated.
Labels (1)
0 Kudos
3 Replies

237 Views
CompilerGuru
NXP Employee
NXP Employee
For some C code patterns the compiler will always use runtime routines, for example
think of a floating point division.
For the other cases, try to optimize for time (-ot). In this mode the compiler does choose to inline code for cases where the default optimize for side does call runtime routines. For most of the "simple" cases this should suffice to generate code with no runtime routines.
If you want to check if certain code is compiled without using runtime routines, the easiest way is to just check the disassembly listings. Also there is a (by default disabled) message issued for each runtime routine invocation. By mapping this message to an error for certain functions (by surrounding the function with two #pragma MESSAGE'es to enable/disable the message) the compiler can be instructed to fail the compilation if the code would contain a runtime routine. The pragma does however not change the decision made by the compiler to use the runtime routine, it just stops the compilation if the compiler does choose to use a runtime routine.

Daniel
0 Kudos

237 Views
JaimeR
Contributor III
Hi Daniel,

Thank you for your answer. The application consist of a CAN Loader , therefore, I am placing my code in a secure memory segment, however, some libraries are being called and I don't know how to control the use of these libraries or its placement.
I used __OPTIMIZE_FOR_TIME__ ;      instruction but the call to runtime routine is still there (LCMP_RC).

If there is no way to get around the JUMP generated by the compiler, maybe the way to get this work done is by controlling the memory segment in which the routine is placed.

I'd rather eliminate the JUMP instead of placing it in safe memory but I don't know if it is possible.

Thanks,

Jaime

0 Kudos

237 Views
CompilerGuru
NXP Employee
NXP Employee
If you write this compare differently (simpler, maybe with a temporary), then the compiler would not use the long compare with constant routine routine (when optimizing for time with -ot. The shown macro is set by the compiler on its own when using -ot, setting it directly does not change anything).

The other "clean" approach is to build the loader as its own project, completely separate from the application code. This way the loader gets its own set of runtime routines and everything is separate and independent per design.

Daniel

0 Kudos