Is PBASIC "Position Independent"?
In another forum (the one I usually live in for discussing the target of the product I have under development), the issue of updating the "firmware" for the product I'm building came up.
I want to disconnect the standard programming port once these devices ship, but I still want to be able to have customers update the if needed.
The thought at this point in time is that I enable downloading the firmware via the same RS-232 interface that is going to control the device. Once downloaded (and I may have found a use for some of that SRAM Mike suggested!), I'd need to overwrite the existing PBASIC code. Which tells me that I need to have a bootstrap loader somewhere in my code. And I need to be able to move the bootstrap loader DOWN in memory so that control can be transferred to it when it goes to overwrite the existing code with the updated code. And that usually requires "position independent code" -- software that runs correctly regardless of where it is loaded into, and executed from, in memory.
So, if I have a block of code that starts at some symbol, can I use that symbol with a READ / WRITE FOR loop, move the data to another address, then GOTO that address and it runs properly? Please say "Yes". But be honest [noparse]:)[/noparse]
I want to disconnect the standard programming port once these devices ship, but I still want to be able to have customers update the if needed.
The thought at this point in time is that I enable downloading the firmware via the same RS-232 interface that is going to control the device. Once downloaded (and I may have found a use for some of that SRAM Mike suggested!), I'd need to overwrite the existing PBASIC code. Which tells me that I need to have a bootstrap loader somewhere in my code. And I need to be able to move the bootstrap loader DOWN in memory so that control can be transferred to it when it goes to overwrite the existing code with the updated code. And that usually requires "position independent code" -- software that runs correctly regardless of where it is loaded into, and executed from, in memory.
So, if I have a block of code that starts at some symbol, can I use that symbol with a READ / WRITE FOR loop, move the data to another address, then GOTO that address and it runs properly? Please say "Yes". But be honest [noparse]:)[/noparse]
![burger.gif](http://forums.parallax.com/images/smilies/burger.gif)
Comments
Stamp code in general cannot be relocated using READ/WRITE. However, you are in luck if you have a BS2P (or pe or px). You can READ code from one slot and WRITE it at the same offset in another slot, and the RUN it, no worry. That technique can be helpful when the data has to go through a modem or come off a flash card, something like that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Why 'disable the programming port'? The only thing on the BS2 is "compiled basic token code", and THAT can't be downloaded through the programming port unless YOU put code in to do that.
On the other hand, I may not need to do anything -- copying a piece of code having an absolute address to the correct absolute address works after relocation, but not before.
But the PBASIC token reference manual would still be very handy to have.
To pursue an interest in how the tokens are built (which is pretty awesome), look at Inside the BASIC Stamp II, and/or Decoding the BASIC Stamp I.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com