182 questions
Advice
1
vote
7
replies
175
views
(Newbie) Where does the Stack Pointer actually point? Does it point to the last used byte or to the first free byte?
I just learnt that you can implement C (or any compiled language) functions in asm. Maybe to optimize them or to access CPU functionality that is not accessible otherways.
I know some MIPS asm from ...
17
votes
3
answers
1k
views
Stack memory in a freestanding environment
I'm reading a GNU as introductory book for programs running on top of an OS. I'm at the stack memory part and I was curious how the stack looks like in a freestanding environment.
I'm guessing that ...
1
vote
0
answers
58
views
How to initialize stack pointer in x86 assembler on Linux [duplicate]
Given the example of a simple program for GNU assembler on i386 architecture in Linux:
.section .data
msg: .ascii "Hi, People!\n"
len = . - msg
.section .text
.global _start
_start:
# ...
0
votes
1
answer
83
views
Null in a dereferenced Stack Pointer in Rust on Cortex-M4 (nRF52833)
When developing a Rust no_std bootloader for my micro:bit v2.21 (Cortex-M4, nRF52833), I have encountered a weird error.
The bootloader jumps to the main application using cortex_m::asm::bootstrap(sp, ...
1
vote
0
answers
107
views
Stack frame contents, pointer to another address within stack frame
I'm trying to learn more about memory and trying to dissect a stack frame. For reference here is the source code that I'm running through gdb.
#include <stdio.h>
void test_function(int a, int b,...
-1
votes
1
answer
157
views
(ARM assembly) how to address elements on the stack relative to the sp
How can I address elements on the stack that are not on top of it? I am talking about for instance first executing stmfd sp!, {r0-r12} and then push {lr}. Now I want to work with the first address of ...
2
votes
1
answer
145
views
Stack is not aligned to 8 bytes on exception entry
I'm writing a mini OS for my STM32F0 board, which has a Cortex-M0 CPU based on the ARMv6-M architecture.
In particular, I'm doing the msp/psp switch after I've created the process queue for the ...
3
votes
1
answer
121
views
Does a write to SP on ARMv8 also write to SP_ELx?
I have been attempting to read through the ARM manual to gain an understanding of how ARM works architecturally. I know that there is a system register for SP at each EL, like SP_EL0, SP_EL1, etc. I ...
1
vote
1
answer
120
views
Can we set the SP register to 0 in x86 assembly real mode?
I was following a tutorial on operating system development, and as a bit of a fanatic, I came across a line in the code that caught my attention:
bits 16
section _ENTRY CLASS=CODE
extern _cstart_
...
0
votes
4
answers
1k
views
How does stack pointer works on STM32F103
I have recently become interested in linker scripts and assembly coding for MCUs. I just discovered that the first thing we do in the reset_handler is set the stack pointer register (sp).
My question ...
0
votes
1
answer
60
views
How to understand the bytes the stack pointer changed when call function
I feel confused about the bytes the stack pointer changes when callq or retq is invoked?
Here’s a little example
; Disassembly of leaf (long y) y in %rdi
0000000000400540 <leaf>:
400540: 48 8d ...
0
votes
1
answer
233
views
riscv stack pointer initialization
I am using https://www.qemu.org/docs/master/system/riscv/virt.html to compile some code that prints 'U' out the uart.
My question is about stack initialization. I am assuming I can do this various ...
22
votes
2
answers
2k
views
How to prepare stack pointer for bare metal Rust?
I'm trying to write an x86 bootloader and operating system completely in Rust (no separate assembly files, only inline assembly within Rust).
My bootloader works completely as intended within the QEMU ...
1
vote
1
answer
183
views
How to get the stack pointer and return address and restore them to a previous state
I'm trying to implement a poor man's call with current continuation for a program written in C. I can "easily" access and memcpy the relevant part of the C stack (obviously, that's not ...
2
votes
2
answers
157
views
If the stack grows downwards, how does it not overlap with other stuff in the address space?
I realized I never really thought of this.
If I made a large enough recursive call chain, wouldn't the stack eventually grow down enough that it will overlap with other things, like shared libraries (...