3 ms·
xxd target/thumbv7em-none-eabihf/release/from-scratch.bin | head -n 5 00000000: 0000 0120 dd00 0000 0000 0000 0000 0000 ... ............ 00000010: 0000 000
by saagarjha 7y ago
xxd target/thumbv7em-none-eabihf/release/from-scratch.bin | head -n 5
00000000: 0000 0120 dd00 0000 0000 0000 0000 0000 ... ............
00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
> Reading this, our initial stack pointer is 0x20100000, and our start address pointer is 0x000000dd.
I see the pointers in the top line, but is this a standard feature of objcopy's binary format? Are the pointers the stack and entrypoint always at the beginning?
- kimixa 7y agoNo, "bin" explicitly has no format, but it's interpreted by the bootloader/whatever on the board - you can see the linker script setting this up manually here: https://github.com/ferrous-systems/zero-to-main/blob/master/from-scratch/linker.ld#L31 https://github.com/ferrous-systems/zero-to-main/blob/master/...
- duskwuff 7y agoFWIW, this is a pretty unusual way of setting up vectors. A more typical approach in C is to declare the vector table entirely in C or assembly, and only use the linker script to position it: https://github.com/duskwuff/stm32f103-example/blob/master/ldscript.ld#L26 https://github.com/duskwuff/stm32f103-example/blob/master/ld...
- TickleSteve 7y ago...and what you're seeing is after the linker has positioned it. that is the defined format of the ARM vector table as it is laid out in memory.
- duskwuff 7y agoI'm referring to the linker script in kimixa's comment. Explicitly placing each vector table entry in the linker script, as this one does, is unusual.
- fra 7y agoThis is part of the spec for ARM MCUs: the vector table starts at 0x0, and the first two words in it are the initial stack pointer and the entrypoint. We go into this in details (with references) in our earlier post: https://interrupt.memfault.com/blog/zero-to-main-1 https://interrupt.memfault.com/blog/zero-to-main-1
- saagarjha 7y agoAh, I see. Thanks!
- chrisseaton 7y ago> objcopy's binary format There is no file format - it’s just whatever stream of data and instructions the user wrote. It’s a flat file.
- saagarjha 7y agoThat's what I thought, hence the surprise that they managed to summon these two things just by looking at the beginning of the file.
- duskwuff 7y agoAlso, they've misread the pointer -- the initial SP is 0x2001_0000 (SRAM + 64K), not 0x2010_0000 (SRAM + 1MB).
- fra 7y agoAh, you're right! fixed.