Where exactly is the stack located? (ARM)
-
- Posts: 2
- Joined: Sun Nov 29, 2020 8:49 am
Where exactly is the stack located? (ARM)
Looking at the boot.S file in the Raspberry Pi Bare Bones tutorial, it seems like the stack pointer register is set to the start of kernel_main(), but what happens to it from there? In the linker.ld file, __end is set to where the .elf ends, but does this include memory for the stack? i.e. when the program is running, are stack variables being stored somewhere between 0x0 and __end, or somewhere else in memory?
Re: Where exactly is the stack located? (ARM)
Nope. The firmware loads the kernel raw binary at 0x8000 (AArch32) or 0x80000 (AArch64). That's going to be the same address as _start (and not kernel_main), and the stack is set to that too, because it's growing downwards.asdfasdfasdf wrote:Looking at the boot.S file in the Raspberry Pi Bare Bones tutorial, it seems like the stack pointer register is set to the start of kernel_main()
No. That _end label does not end where the elf ends (there's also a bss section), and it does not contain the stack either.asdfasdfasdf wrote:In the linker.ld file, __end is set to where the .elf ends, but does this include memory for the stack?
Here's a memory map:asdfasdfasdf wrote:i.e. when the program is running, are stack variables being stored somewhere between 0x0 and __end, or somewhere else in memory?
Code: Select all
+------------+ 0xFFF..F top of memory
| ... |
+------------+ _end, _bss_end
| bss |
+------------+ _bss_start, _data_end \
| data | |
+------------+ _rodata_end, _data_start |
| rodata | | kernel.img
+------------+ _text_end, _rodata_start |
| text | |
+------------+ _text_start, _start, LOADER_ADDR, 0x8000/0x80000 /
| stack |
| ... |
+------------+ 0
Cheers,
bzt