Dear Richard,
FreeRTOS info writes:
> On 06/02/2012 09:42, alb wrote:
[...]
>> Certainly I may as well take care about memory initialization
>> explicetely, in my program, without any need to care about seg_init.
>>
[...]
>
> As a minimum you must ensure the stack that main() is going to use is
> setup and configured before main() is called - and then that none of the
> initialisation functions you explicitly call from main() change the
> stack configuration - or write over the stack frame that, by that point,
> will already be in use by main().
At the moment the main is called I believe the stack is configured for the
loader which was running before the 'jump to main'. At this point, since
there's no need to go back to the loader I believe I can re-initialize the
stack from scratch with the lib_setup_environment call which should do the
job.
The beginning of my main will look like this then:
void main (void) {
SETUP_HWR(); // setup hardware (cache, irptl and memory banks)
SETUP_PRO(); // setup processor (registers, modes and memory)
SETUP_ENV(); // setup environment (stacks, errno, heaps, rand, interrupts
// exit and arguments)
...
}
Where SETUP_HWR/PRO/ENV are defines like:
#define SETUP_HWR() asm("CALL ___lib_setup_hardware;")
#define SETUP_PRO() asm("CALL ___lib_setup_processor;")
#define SETUP_ENV() asm("CALL ___lib_setup_environment;")
Even though the main is running, the stack should be empty, as well as the
heap, the registers and all the rest. Have I understood your concerns
correctly?