I'm trying to build a solution, where there would be two projects: 'bootloader' (starting after reset and doing smth), and 'mainApplication' getting the control from bootloader.
Initially i've just reproduced the example from here: https://visualgdb.com/tutorials/arm/bootloader/
The final part of this tutorial describes "system call" - passing the pointer to some function residing in bootloader to the main application and then making a call to this function from there.
The intention is to pass not a pointer to a function, but say pointer to an object of a class.
Modified example from tutorial looks like this:
Bootloader:
//sys.h
class SysCalls
{
public:
SysCalls();
int sum(int, int);
};
//sys.cpp
#include "sys.h"
SysCalls::SysCalls()
{
}
int SysCalls::sum(int a, int b)
{
return a + b;
}
// main.cpp
#include <sys.h>
...
SysCalls _sys;
void *g_Syscalls[] __attribute__((section(".syscalls"))) = { (void *)&_sys };
Main Application:
//main.cpp
#include <sys.h> // the same header as in bootloader
extern "C" void *g_Syscalls[];
SysCalls *_sys = (SysCalls*) g_Syscalls[0];
int main(void)
{
...
int sum = _sys->sum(1, 2);
...
I get an linker error:
undefined reference to `SysCalls::sum(int, int)'
which is predictable, but...
Is there any good way to build this, i wonder? some linker config? or should i include sys.cpp to mainApplication also, and make the content not to be included in final binary somehow?
Also, looking forward - if talking about simple staff like shown sum function, which uses only stack, it is only a linker issue, but if i want to create a kind of 'system service', say singleton object with some heap usage, then the question would be - if there is any good way to freeze the part of heap used by this object when transferring control from bootloader, where it was created to main Application, which should use it...