global label declaration

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

global label declaration

Jump to solution
5,001 Views
mayfly
Contributor III
Hi,

Is there such a thing as a "global label" in C where I can goto a label in one function from another?  GNU C has a label declaration "__label__" that looks like it could work but it doesn't work in Codewarrior.  I can't seem to find a solution in C.  Below is what I am trying to do conceptually.  Any help would be appreciated.

__label__ mylabel;

void function1(void)
{
mylabel:
    ;
    return;
}
void function2(void)
{
    extern __label__ mylabel;
    goto mylabel;
    return;
}
Labels (1)
Tags (1)
0 Kudos
1 Solution
2,243 Views
CrasyCat
Specialist III
Hello
 
If you are moving the whole segment, all the functions within the segments will be moved in the same sequence and there will be no padding byte. So the offset between the functions should be the same.
 
On getting code size, there is a linker defined object __SEG_SIZE_<SegName>, allowing to retrieve the size of a section within an application.
 
Please refer to following manual for more information on that linker defined object.
{Install}\Help\PDF\Build_Tools_Utilities.pdf, chapter "Smart Linker", section "Linking Issues" -> "Linker Defined Objects".
 
CrasyCat

View solution in original post

0 Kudos
5 Replies
2,243 Views
CompilerGuru
NXP Employee
NXP Employee
no, there is no such thing in C.
For your code I'm not sure what is supposed to happen. Especially with local variables allocated in both functions.

Maybe you can reformulate your code to use the usual C constructs, maybe you can use function pointers?

0 Kudos
2,243 Views
mayfly
Contributor III
Sorry, I should have explained better.  What I would like to do is copy the code for a function into RAM from another function and then jump to that location in RAM.  Is there another way to do it "automatically" (meaning to do it in code without having to look at the compiled code size, then hardcoding the size in) and without having to copy the whole compiled file module into RAM?  Is there a way to get the address of a label?  Below is a better concept of what I would like to do (do_some_stuff(), etc are just for conciseness--the real code doesn't call any functions).  If I could do it this way, does C guarantee that the function's compiled code will lay consecutively between the start of the function and the location pointed to by the end label?

#define RAM_TOP 0x10AF  //S08DZ60 ram top? bottom?

unsigned int code_size = 0;
__label__ function_end;   //pretending for now that there is such a thing as "global labels"

void function1(void)
{
    do_some_stuff();
    while(1)
    {
       do_some_more_stuff();
    }
function_end:   
    ;
}
void function2(void)
{
    unsigned int i;
    unsigned int* ram_start;

    extern __label__function function_end;
    code_size=&function1 - &function_end;
    ram_start = RAM_TOP-(code_size+1);

    for(i=0; i< code_size; i++)
    {
         *(ram_start++)=*(&function1++);  
    }
}

This won't work, but is there an easier/better/cleaner way to do it (one that actually works)?
0 Kudos
2,243 Views
CrasyCat
Specialist III
Hello

There are two Technical notes available on that topic:
TN228: Running Portion of the Application in RAM.
TN235: Running Portion of the Application from Stack
To download the Technical Notes:
- Go to CodeWarrior for HC08 (or HC12) page (I do not know which
CPU you are targeting).
- For HC12 URL is http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=CWS-H12-STDED-CX
- For HC08 it is http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=CWS-H08-STDED-CX
- Click on 8/16-Bit Tech Notes under "Featured Documents"
- Download the .zip file and look for the 2 Technical Notes specified above.

I hope this helps.

CrasyCat
0 Kudos
2,243 Views
mayfly
Contributor III
Hi,

Thanks.  The TNs helped.  The target processor is a S908DZ60.

Ok.  I would like to be able to find the code size of the function "automatically", meaning without referring to or modifying the .prm or .map files.  (The TNs require modification of the .prm files)  I've seen other posts about this (determining code size), and found hints that it can't be done but can anyone give a definitive answer and reason why not?  (or an answer as to how it can be done).

Additionally, the TN says  that the code needs to be PIC but that the HC08 compiler (which, I assume, also applies to the S08 as well) does not support PIC.   How can you erase the flash in an HC08 if you can't guarantee the order of the code?  Does moving the whole segment guarantee that the code will be in the right place?


0 Kudos
2,244 Views
CrasyCat
Specialist III
Hello
 
If you are moving the whole segment, all the functions within the segments will be moved in the same sequence and there will be no padding byte. So the offset between the functions should be the same.
 
On getting code size, there is a linker defined object __SEG_SIZE_<SegName>, allowing to retrieve the size of a section within an application.
 
Please refer to following manual for more information on that linker defined object.
{Install}\Help\PDF\Build_Tools_Utilities.pdf, chapter "Smart Linker", section "Linking Issues" -> "Linker Defined Objects".
 
CrasyCat
0 Kudos