Position Independent Code - seeking more info

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

Position Independent Code - seeking more info

1,472 Views
EdProulx
Contributor I
Position Independent Code - seeking more info


I have been trying without success to get more info on PIC - Position Independent Code. What info is in the ColdFire Build Tools reference manual is basic, and superficial. If the following questions/topics can be answered, I would be greatly appreciative. I am sure there are others with the same issue(s).



1. In another thread on the topic of PIC, CrasyCat stated that a "sample project around PIC code for Coldfire in the installation. Check the example project in {Install}\(CodeWarrior_Examples)\5213_PIC  The file PIC_readme.txt provides some info on how to implement PIC code". But I'll be darned if I can find it. Is it somewhere on the Freescale site? If it is a zip file, it would be good if someone would send it to me (or a web link to get to it).


Otherwise, I have some questions surroundin PIC, how it should be setup, and how it is supposed to work:


2. I build my project to load at address 0x1000 as per my .lcf linker file ("code" in the MEMORY segment). It is the "pictables" definition in the project's .lcf "SECTIONS" section that defines the project as PIC. I added the following to my .lcf file (I took it straight out of the reference manual, and changed "DATA" for "code", as I did not know what "DATA" means), but it doesn't mean anything to me:

 .pictables :
  {
    . = ALIGN(0x8);
    __START_PICTABLE = .;
    *(.picdynrel)__END_PICTABLE = .;
    __PICTABLE_SIZE = __END_PICTABLE - __START_PICTABLE;
    __START_PIDTABLE = .;
    *(.piddynrel)__END_PIDTABLE = .;
    __PIDTABLE_SIZE = __END_PIDTABLE - __START_PIDTABLE;
  } >> code

In the "ColdFire Processor" window, I selected both "Position-Independent Code" and "Position-Independent" Data". I compiled and downloaded this project to flash, it loads in flash at 0x1000 as expected, because "code" is set to that in the MEMORY section in the .lcf. Nothing magical about this.


3. Going back to my CW project, I opened the "Debugger PIC Settings" window, selected "Alternative Load Add", and specified this address: 0x2000. I did not change any other settings in my .lcf file, in particular, the load address of "code" (still set to 0x1000). I cleaned and re-built the project, but the flash programmer continues to load it at 0x1000 (and not at 0x2000 as I was hoping).

I changed the "code" segment to load at 0x0000 and tried again - but the project is now loaded at 0x0000 (and not 0x2000 as expecting). So PIC seems to be ignored.

Do I need extra constraints (#pragma for example) in my startup module? So far, I did not make any changes to any code. I did not and could not find info on any changes, if required, to the code.




4. Assuming I do get the flash programmer to load my project at the expected address, with PIC properly setup, the image downloaded to flash is set to run and use relative addressing. How is the relative address "resolved"? After flashing the image, I am expecting that some register is considered a "relative base address register" of sorts, and it needs to be set after it is flashed to the address where the image was written. If this is so, which base register?



I think the above 4 items can be addressed separately, at least item 1 for sure, the other 3 are somewhat related. I thank you in advance for any help, and will continue to be thankful for some time after that.

Ed
Labels (1)
0 Kudos
2 Replies

402 Views
CompilerGuru
NXP Employee
NXP Employee

Which version of the CW tools are you using?

I just checked  CodeWarrior for ColdFire V7.1 and it does contain a 5213_PIC sample, attached.

 

Daniel

 

 

5213_PIC.zip

Message Edited by t.dowe on 2009-08-31 11:47 AM
0 Kudos

402 Views
EdProulx
Contributor I

Thank you for the zip - I'm looking at it now and getting more familiar.

 

We're using CW 5.9 release, I'll be looking into whether or not it is to our advantage to upgrade.

 

Lastly, I should point out that we are running our application from flash (on an MCF5225x set of processors, 512K flash, 32K RAM). In the 5213 example project, in the pictables section, I see init data that is used to copy into "RAM because they contain the references fixup offsets". If my app is running from flash, have I already boxed myself into a corner?

 

Thanks.

0 Kudos