Dynamically loading code

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Jamie
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Post by Jamie »

To do it I would compile the code in the xde and then disassemble it with xobjdump and run it through a parser written in perl....Then there was some assembly required to set the CP and DP to their relative locations, and allocate space for the stack.
What is it that your parser does to the dissasembly? Do you ensure that all of the address references in your loadable modules are relative so the instructions are position independent? (And all you have to worry about is the cp and dps). Or are you statically patching absolute references?

Jamie


User avatar
monk_is_batman
Active Member
Posts: 38
Joined: Wed Jun 09, 2010 3:20 am
Location: Maine, USA

Post by monk_is_batman »

The only absolute references that I know about besides the CP and the DP are the branch instructions BAU and BLA, which my perl checks for and spits a warning if it finds any in the module. From my experience the compilers provided by xmos does not really use these instructions so its not really an issue. I wasn't sure if anyone really wanted to know the details so I did kind of breeze over some of the aspects of my system.

First let me start this by mentioning that the module to be put into flash is inside a project containing code capable of flashing it to memory, but to do that it needs to know some information about where it is.

All of the assembly that I mentioned is in my C program when loading the module, it uses GETR to get a thread, then uses INIT to setup registers on the thread, and finally START to run it.

The perl doesn't actually make any changes to the disassembly, mostly because I'm too lazy to reassemble it afterwards. So what it does it spit out a bunch of information that I need to know. It looks for the beginning address and end address of the module and also where the CP and DP are in this program and how much of the CP and DP are used just inside the module functions.

So currently the process involves compiling, disassembling, perl, typing in numbers, recompiling then running. Then the module is in my module DB on my flash. I am working on automating this process to make it easier, but considering this only needs to be done once then it seems worth it.

-Monk