Timeline for Bare-metal start-up code for Cortex M3 .bss region initialization
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 8, 2019 at 7:06 | comment | added | ilkkachu |
@old_timer, as for bootstrapping a language... I don't think pure C on a microcontroller has much of internal state to bootstrap. Sure, on a real OS the standard library would need to initialize stdin and others, and arrange for argc and argv to be available to main , but I don't think those are that commonly used on MCU's. (I may have forgotten something, sure.) And you do realize that they are already using C in the startup function, yes? If you think they shouldn't do that to begin with, then please post an answer to that effect (oh, I see you already did, good.)
|
|
Aug 8, 2019 at 7:01 | comment | added | ilkkachu |
@old_timer, What exactly is the magic in "bootstrapping" here? If you look at the code in the link (under "C startup code"), you'll see that there's just a plain call to main() at the bottom of the startup function that e.g. clears bss . Now, assuming that one can call memset() from main() what makes the magic difference here? It looks like just a function call, I can't tell how it would make a difference.
|
|
Aug 8, 2019 at 6:27 | comment | added | glglgl |
@old_timer You don't "bootstrap C", you just bootstrap your program. Surely you cannot do everything you want in the bootstrap code, but as long as the code doesn't depend on the contents of .bss , everything should work.
|
|
Aug 7, 2019 at 21:58 | comment | added | old_timer | yes with more understanding of the language and what is going on here it is easy to not rely on .data in order to init .bss for the code as shown. Even easier to not try to use C to bootstrap C. (move it to .text/.rodata depending on the toolchain) | |
Aug 7, 2019 at 21:57 | comment | added | old_timer | the op is also relying on .data to be initialized before .bss, you expecting them to use a memcpy to initalize .data so that they can initalize .data and then how are they going to initialize .data by relying on .data to initialize .data? likewise makes absolutely no sense to use C to bootstrap C. .data is also dealt with in a few lines of assembly since there arent many other lightweight languages to use instead of asm that wouldnt also require their own bootstrap. | |
Aug 7, 2019 at 21:54 | comment | added | old_timer | this is a bootstrap startup question on top of a less than vs equal question, you simply do not use memset for the C bootstrap by definition you dont use the langauge you are booting with the language you are booting because you will need to bootstrap that code with some other bootstrap so you can bootstrap the language with the language. or you can do it like everyone else and use some other language, which means assembly language for C boostraps, making no calls to C functions (even if memset is optimized in asm). you write the three/four lines of code in asm. | |
Aug 7, 2019 at 12:59 | comment | added | ilkkachu | Of course, for custom situations, custom solutions, but they asked for a standard way. | |
Aug 7, 2019 at 12:59 | comment | added | ilkkachu |
@old_timer, the standard C function to set memory to a particular value is memset() , and C is what they seem to be programming in. The simple implementation of memset() is also pretty much just that loop, it's not like it depends on much else. Since that's a microcontroller, I also assume that there's no dynamic linking or such going on (and looking at the link, there isn't, it's just a call to main() after that zeroing loop), so the compiler should be capable of dropping memset() in there along with àny other functions (or to implement it inline).
|
|
Aug 7, 2019 at 12:51 | comment | added | old_timer | the bootstrap code and linker script are very much married, you will find it common that the linker script aligns and sizes the .bss on at least a 4 byte boundary to improve the fill (in the bootstrap) by 4x over byte at a time instructions (assuming (minimum) 32 bit busses which is typical for arm but there are exceptions) | |
Aug 7, 2019 at 12:47 | comment | added | old_timer | you dont use the same language to bootstrap that language | |
Aug 7, 2019 at 12:44 | comment | added | old_timer | in no way shape or form is the standard solution for the bootstrap to use memset, that is crazy. | |
Aug 7, 2019 at 11:00 | comment | added | Codo |
Agree very much with the use of memset() . But alignment to 4 bytes is more or less a must. So why not do it?
|
|
Aug 7, 2019 at 9:43 | history | edited | ilkkachu | CC BY-SA 4.0 |
I can't spell "area"
|
Aug 7, 2019 at 7:49 | history | answered | ilkkachu | CC BY-SA 4.0 |