<div dir="ltr"><div>Good evening, <br></div><div><br></div><div>I've also tried the "register" keyword route.</div><div><br></div><div>register int *foo asm ("sp"); <br></div><div><br></div><div>this line produces error:</div><div>In file included from src/debug/code.c:4:<br>include/debug/code.h: In function 'debug_get_stack_pointer':<br>include/debug/code.h:11:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'asm'<br>  11 |   register int *foo asm ("sp");<br>   |            ^~~<br>include/debug/code.h:11:23: error: implicit declaration of function 'asm' [-Werror=implicit-function-declaration]<br>cc1: all warnings being treated as errors</div><div><br></div><div><br></div><div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Georgii Ekserdzhian</div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ÑÑ, 8 окÑ. 2020 г. в 20:06, Petr Tůma <<a href="mailto:petr.tuma@d3s.mff.cuni.cz">petr.tuma@d3s.mff.cuni.cz</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
inline assembly is one option, but you could also try the "register" keyword, as suggested by the README file. For exact syntax, see <a href="https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables" rel="noreferrer" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables</a>, this makes it possible to access specific register values directly from C (simply by defining a variable that resides in that particular register and then reading it).<br>
<br>
Many compiler optimizations make naive solutions for accessing stack location fail, so the above solution might really be better than trying without "register".<br>
<br>
Petr<br>
<br>
<br>
On 08/10/2020 19:11, Peter G wrote:<br>
> Hi,<br>
> <br>
> I have encountered similar behaviour. When solving the problem without inline assembly I got this output<br>
> <br>
> sp1 = 800003e0<br>
> sp2 = 800003e0<br>
> <br>
> tests/basic/stack_pointer/test.c:43: Kernel test assertion failed: sp1 == sp2<br>
> tests/basic/stack_pointer/test.c:43: $sp unexpectedly changed (0x800003e0 => 0x800003e0)<br>
> <br>
> I could not figure out why this happen, but after I added these two lines the test passes:<br>
> <br>
> printk("&sp1 = %p\n", &sp1);<br>
> printk("&sp2 = %p\n", &sp2);<br>
> 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.<br>
> <br>
> However, solution using inline assembly worked right away.<br>
> <br>
> Best regards,<br>
> Peter Grajcar<br>
> <br>
>> On 8 Oct 2020, at 17:13, Georgii Ekserdzhian <<a href="mailto:gxrjan@gmail.com" target="_blank">gxrjan@gmail.com</a>> wrote:<br>
>><br>
>> Good afternoon,<br>
>><br>
>> I've been thinking on debug_get_stack_pointer function for quite a while now.<br>
>> I pushed my code into my repo. <br>
>> Also I attached my log. <br>
>> For some reason the test that asserts that sp1 == sp2 fails, but the log shows that they are the same.<br>
>><br>
>> Also question. You said that we should try first without using inline assembly. <br>
>> I tried to use asm() function and the compiler doesn't recognize this function call.<br>
>> Is there another way to use assembly in C?<br>
>><br>
>> Georgii Ekserdzhian<br>
>> <log>_______________________________________________<br>
>> NSWI004 mailing list<br>
>> <a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
>> <a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
> <br>
> _______________________________________________<br>
> NSWI004 mailing list<br>
> <a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
> <a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
> <br>
_______________________________________________<br>
NSWI004 mailing list<br>
<a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
<a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
</blockquote></div>