Electronics > Microcontrollers

Understanding ARM startup code (__scatterload stuff)

<< < (3/4) > >>

emece67:
Quote from: simonlasnier on Today at 11:13:15 am
Hi :)

* __user_setup_stackheap sets up the stack and the heap... The stack is already set up by the MSP register... What is there left to do? :o
And for the heap I guess it is only a "software" thing since it is not mentioned anywhere in the ARM Cortex Device Generic User Guide?
* After the call to my main() there is the whole exit and __rt_exit, which should just be a dumb forever loop? (or not needed at all since the main() does not ever end)


--- End quote ---


Such stuff is described in the compiler docs. See https://developer.arm.com/documentation/dui0475/m/the-arm-c-and-c---libraries/stack-and-heap-memory-allocation-and-the-arm-c-and-c---libraries/stack-pointer-initialization-and-heap-bounds

If you do not use new/malloc() you can forgive it, but if using dynamic memory, you can use __user_setup_stackheap to set their limits and, perhaps, to fill such areas to 0xDEADBEEF or any other value later useful to detect stack-heap collisions or stack/heap usage.

If your programs do not return, you can also forgive the __rt_exit()/_sys_exit() stuff. I use _sys_exit() to signal (with a blinking LED) that someone forgot that you must not return from main().

Regards.

simonlasnier:
Thank you all for the replies!!  8)


--- Quote from: abyrvalg on October 20, 2021, 03:34:56 pm ---Startup function names points to Keil (ARM Compiler-based), correct? Unlike GCC, it can compress the .data section and call an appropriate decompressor from __scatterload (choosing the most efficient approach is automatic).
Heap setup is for malloc & friends (so you can drop it if not using dynamic allocation).
__rt_exit is for people who returns from main.

--- End quote ---
You are just SPOT on  ;D
And yes I should have mentioned I am using ARM Keil - I did not think it will be different from one compiler to another, I just thought it was standard ARM.

And so now I can see why this __scatterload code looks a lot more complicated than it should be (I just imagined a loop initializing the variable), it's because it is decompressing!

@emece67: thanks for the link :)

@newbrain: as said I am using Keil and I think they use their own compiler?
Interesting using gcc&make for this. How do you debug though, gdb?
I just thought having Keil will get me up and running faster, and having a graphical view for a debugger really really helps IMO.

westfw:

--- Quote ---And for the heap I guess it is only a "software" thing ...
I did not think it will be different from one compiler to another, I just thought it was standard ARM.
--- End quote ---
Once you get into "only a software thing", initialization can vary a great deal from one compiler to another, depending on what libraries they use and etc.  In particular WRT "heap", different compilers/libraries can have different implementations of malloc()/etc.For CM23, I'd start to expect that some build environments would have some support for the "trustzone" features that ARM is pushing.  Maybe adding overrun protection to the stack in addition to "just set SP to some place in memory", and/or "protecting" un-allocated memory.

simonlasnier:

--- Quote from: newbrain on October 20, 2021, 01:46:33 pm ---If you want to generate the assembler listing and you are using gcc, check the -S option (will generate the assembler and stop) or the --save-temps option, which will keep the .i (preprocessed source) and the .S (assembler) intermediate products, more easily integrated in an existing makefile or other compilation script.

--- End quote ---
Thanks for that :) Unfortunately when I add -S or --save-temps it seems I get the same error: "error: use of xxxx is disallowed in this variant of ARM Compiler".
It seems the compiler Keil uses is called armclang and is kinda their own modified version of gcc.

newbrain:

--- Quote from: simonlasnier on October 20, 2021, 08:45:54 pm ---It seems the compiler Keil uses is called armclang and is kinda their own modified version of gcc.

--- End quote ---
Rather, it's ARM's own version of LLVM/clang.
And, according to the docs, armclang should accept -S and -save-temps as does clang (which is mostly gcc compatible), but I don't know whether Keil uses some special/limited version of it.

Note that I had an extra '-' in my original post, the option is actually -save-temps, not --save-temps.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version