Can anyone explain the arm based assembly code for the stack point of view ; specifically the stack view for "reset_handler" right before calling "main", "save_context" and "resume" part? (Note that I know what the code is doing but I can't comprehend or imagine how exactly the stack look like or behave while the code is running).
*/ asm.s */
.global main, process, process_size
.global reset_handler, context_switch, running
reset_handler:
ldr r0, =process
ldr r1, =process_size
ldr r2, [r1, #0]
add r0, r0, r2
mov sp, r0
bl main
context_switch:
save_context:
stmfd sp!, {r0-r12, lr}
ldr r0, =running
ldr r1, [r0, #0]
str sp, [r1, #4]
resume:
ldr r0, =running
ldr r1, [r0, #0]
ldr sp, [r1, #4]
ldmfd sp!, {r0-r12, lr}
mov pc, lr
*/ cfile.c */
#define SIZE 2048
typedef struct process
{
struct process *next;
int *saved_stack;
int running_stack[SIZE];
}PROC;
int process_size = sizeof(PROC);
PROC process, *running;
main()
{
running = &process;
context_switch();
}