[NSWI004] getting stack pointer value

Peter G peter.grajcar131 at gmail.com
Thu Oct 8 19:11:02 CEST 2020


Hi,

I have encountered similar behaviour. When solving the problem without inline assembly I got this output

sp1 = 800003e0
sp2 = 800003e0

tests/basic/stack_pointer/test.c:43: Kernel test assertion failed: sp1 == sp2
tests/basic/stack_pointer/test.c:43: $sp unexpectedly changed (0x800003e0 => 0x800003e0)

I could not figure out why this happen, but after I added these two lines the test passes:

printk("&sp1 = %p\n", &sp1);
printk("&sp2 = %p\n", &sp2);
I think that after adding these two lines compiler saves sp1 and sp2 on the stack, otherwise they are kept in the registers. I tried to find where the problem lies in the disassembly but I have not figured it out.

However, solution using inline assembly worked right away.

Best regards,
Peter Grajcar

> On 8 Oct 2020, at 17:13, Georgii Ekserdzhian <gxrjan at gmail.com> wrote:
> 
> Good afternoon,
> 
> I've been thinking on debug_get_stack_pointer function for quite a while now.
> I pushed my code into my repo. 
> Also I attached my log. 
> For some reason the test that asserts that sp1 == sp2 fails, but the log shows that they are the same.
> 
> Also question. You said that we should try first without using inline assembly. 
> I tried to use asm() function and the compiler doesn't recognize this function call.
> Is there another way to use assembly in C?
> 
> Georgii Ekserdzhian
> <log>_______________________________________________
> NSWI004 mailing list
> NSWI004 at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/nswi004



More information about the NSWI004 mailing list