We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I have two separate questions: 1) I was wondering whether the Keil C51 compiler can generate Position Independent Code. Perhaps, if I build a program as a library, would the generated object code be position independent? By PIC, I mean that all jumps would be Program Counter-relative rather than absolute.
2) Can the C51 generate OMF51 Object code rather than Absolute OMF51 object code? If I write a program with unresolved external references, would the linker abort as soon as it realizes that these references cannot be linked or would it resolve as much as it can and generate object code with 'dangling' unresolved symbols? If so, would the OMF51 file list these unresolved symbols such that a dynamic loader can patch them at runtime?
Thanks, Umar
I don't think the PC is visible to software at all -- or is it?
Not really. However, there are several ways to get the PC (program counter) value.
http://www.keil.com/support/docs/3265.htm
Jon
Clever.
Peeking at the stack had occurred to me, but to set the PC that way seems to involve making all calls indirect through a thunk that converts a parameter to the actual target address. You'd need tool support much like that for bank switching to insert calls to this thunk, and there would be overhead on every single procedure call.
At that point, writing a dynamic loader starts to seem simple by comparison. It's just a list of offsets into the code to be updated when you copy it into executable RAM...
If dynamic loading of program modules is important for the application, maybe it's time to look at the ARM7. The ARM architecture does PIC nicely.
Now that wouldn't be fun now would it? :)
Thanks all for the inputs.