Relocation issue with Codewarrior 8.1 for PPC

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

Relocation issue with Codewarrior 8.1 for PPC

2,436 Views
Velocirex
Contributor I
I'm using CW 8.1 for PPC and am working with the MPC565. I'm running into what appears to be a rom->ram data relocation issue when running from internal flash. Here are two instances of the problem:
 
1. If the compiler option to leave initialized strings in rom is not checked (i.e. initialized strings are copied to ram at runtime), and the string is then sent to the SCI via a simple polling method, the first four bytes appear to be missing. They are there in the flash image but when they are copied to ram, the string is offset such that it starts on the fifth byte.  When this same application is targeted to RAM (and therefore no rom->ram copy takes place) the strings come out the SCI intact. Similarly, if the above compiler option is checked (leaving the strings in rom) the strings come out fine.
 
2. switch statements. If I use a switch statement with 4 cases, the resulting assembly uses a fairly straightforward jump table implementation that works fine. As the number of cases is increased, the implementation changes to a method in which the jump table is copied to RAM and the address index to use is computed based on the switch statement argument. This is in contrast to the hard coded branch addresses used previously when the number of cases is less. In this implementation, the code breaks and jumps to the wrong case statement. For example, if the switch argument (the index) is 1, it will jump to case 2: and so on. All cases are "off by one". And again, the same application targeted for RAM works properly. The only difference between the two appears to be the relocation of the jump table to RAM before its use.
 
so the question, has this come up previously or do I have a unique situation here? Any ideas?
Jethro
 
Labels (1)
0 Kudos
Reply
6 Replies

909 Views
CrasyCat
Specialist III
Hello
 
I have never heard about such a problem.
I would suggest you to submit a service request  for that.
 
To log the issue please go to following URL:
    http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=054670&tid=FSH
and click on "Submit a service request"
 
Make sure to attach a project reproducing the trouble and also to provide informational on the version of Code Warrior you are using when you submit the request..
 
CrasyCat
 
0 Kudos
Reply

909 Views
Velocirex
Contributor I
Its not really the cause but I have found that adding "#pragma switch_tables off" changes the assembly produced by the compiler. Doing this leads to more obvious code which does not rely on anything in RAM. What is not clear though is what exactly this pragma is doing and why. The manual does not have any description of it. Are you able to describe why this pragma exists and what it does?
0 Kudos
Reply

909 Views
CrasyCat
Specialist III
Hello
 
Here is what I found in the V8.7 build tools manual:
 

switch_tables

Controls the generation of switch tables.

Syntax

   #pragma switch_tables on | off | reset

Remarks

When

on, the compiler translates switch statements into tables of addresses where each address in the lists corresponds to a case statement. Using tables improves the performance of switch statements but may increase the size of the executable code if there are many case statements or if the case statements are not contiguous.

When

off, the compiler translates switch statements into a series of comparisons, one comparison for each case statement.

This is valid also for V8.1 as the behavior of the pragma did not change.
 
Note that there is another pragma read_only_switch_tables, allowing you to use switch tables and get them allocated in Flash (or ROM). I am not sure though this pragma existed for V8.1. You will have to give it a try.

read_only_switch_tables

Controls where tables for

switch statements are placed in object code.

Syntax

#pragma read_only_switch_tables on | off | reset

Remarks

This option specifies where the compiler places executable code addresses for

switch statements. When this option is on, the compiler places these tables in a read-only section (.rodata), allowing the linker to place this object code in a ROM image instead of RAM.

When this option is

off, the compiler places these switch tables in an object code section that is readable and writable (.data). Putting these tables in a read/write section allows relocation at runtime. The System V ABI, SuSE, YellowDog, and SDA PIC/PID application binary interfaces (ABIs) allow relocatable object code at runtime.

I hope this helps a bit.
 
CrasyCat
 
0 Kudos
Reply

909 Views
ispd
Contributor II

Hello CrasyCat,

 

Is there any command line option instead of #pragma read_only_switch_tables on. I use makefiles and I am trying to know if is available such option, I haven't fount on app  note 4094.

 

Thanks a lot and best regards,

 

ispd

0 Kudos
Reply

909 Views
CrasyCat
Specialist III

Hello

 

I checked the command line option from PPC compiler delivered with V8.8.

 

There are 2 things you can try if you want to activate that pragma on the command line:

  1- Use the option -pragma.

  

       Here is the description of this option (according to on-line help):

             -pragma ...                # specify a #pragma for the compiler such as      
                                                #   "#pragma ..."; quote the parameter if you    
                                                #   provide an argument (i.e., '-pragma "myopt    
                                                #   reset"')   

 

  2- Place the pragma in a .h file that you specify as a prefix file.

       If you already have a prefix file add the pragma to this file.

      Otherwise create a new .h file and use option -prefix to tell the compiler to use it as a prefix file.

      This will make sure the file is automatically included in every C source file you are building.

 

CrasyCat

0 Kudos
Reply

909 Views
Velocirex
Contributor I
Thanks!
FWIW, unfortunately the read_only_switch_tables pragma is not available in 8.1. That option might recover some of the performance loss of using the switch_tables off pragma.
0 Kudos
Reply