Hi!
I need to make an application in form of a relocatable executable binary file.
Main idea looks like this: there is a host program running DSP/BIOS. This host program at the run time allocates memory for the guest application, loads the binary executable from flash into allocated space and runs the guest application by calling the pointer to allocated memory as a function.
The guest application nether uses any "external" functions (like memory allocation) nor global variables. It shouldn't have initialization code. It only has it's code, global constants (available within it's own boundaries only) and "context" for storing intermediate data. It has a main function that processes initialization and other functionality.
Please help me to start. I have the code of the app but I don't know how to link it to an executable binary file.
What linker CMD file should like like? Maybe there is something that I can read?...
For linking I use "--relocatable" and "--absolute_exe" option. Then I call hex55.exe and get some binary file.
But it doesn't look like what I need.
A pseudocode for main function of the guest application:
//==============================================================================
//------------------------------------------------------------------------------
uint16_t main (uint16_t Command, void* DataBuffer, uint16_t BufWordlen)
{
uint16_t ResultCode;
//------------------------------------------------------
switch (Command)
{
case 0x0001: // Initialize context
if (DataPointer == NULL)
{
ResultCode = 0; // error
} else
{
memset (DataBuffer, 0x0000, BufWordlen);
ResultCode = 1; // success
}
break;
case 0x0002: // Process data
... // some code
ResultCode = 1; // success
break;
default:
ResultCode = 0; // error, unknown command
break;
}
//------------------------------------------------------
return ResultCode;
}
A pseudocode for loading and running this guest application from host program:
//==============================================================================
//------------------------------------------------------------------------------
typedef uint16_t (*T_GuestMainFunc) (uint16_t, void*, uint16_t);
T_GuestMainFunc GuestMainFunc;
void* GuestContext = NULL;
uint16_t GResult = 0;
...
// allocate space for application's code
GuestMainFunc = (T_GuestMainFunc) malloc (8192);
if (GuestMainFunc == NULL) return 0;
// load the code from flash memory
SPI_ReadFromMemory ((void*) GuestMainFunc, ZERO_OFFSET, 8192 * sizeof(uint16_t));
// allocate space for application's context
GuestContext = malloc (1024); // allocate space for context
if (GuestContext == NULL)
{
free ((void*) GuestMainFunc);
return 0;
}
// run application
GResult = GuestMainFunc (0x0000, GuestContext, 1024);
...
Thanks in advance for your replies!