Search code examples
linuxassemblylinux-kernelarmcpu-registers

How to print out registers in Linux kernel?


I want to print out values of a couple of registers from the linux kernel code running on ARM. Particularly I have the following assembly in linux -

e3c52007        bic     r2, r5, #7      ; 0x7
e1520003        cmp     r2, r3
0a000003        beq     c011fa60 <smem_find+0x40>

How do I print out the values of r2, r3 and r5 in kmsg? I do not want to use the variable names and want to get the values from registers.


Solution

  • I'm not that familiar with kernel development and easy ways to debug, but this would do the job I guess.

    size_t r2, r3, r5;
    
    asm ("str r2, %[r2]\n"
         "str r3, %[r3]\n"
         "str r5, %[r5]\n"
     : [r2]"=m" (r2), [r3]"=m" (r3), [r5]"=m" (r5));
     printk("r2=%u r3=%u r4=%u\n", r2, r3, r5);
    

    Edit: Now with ARM assembly instead of x86 :p