Fwd: Understanding disassembly x86 + understanding function call + parameter pass and stack frame
Andreas Platschek
andi.platschek at gmail.com
Tue Aug 6 10:13:19 EDT 2013
> c)lets say for a program a.c i use gcc -S a.c ...do we have some other
> command to generate
> somewhat more clear assembly code, may be with some comments in english
>
Not sure if this is of any help, but the kernel build system (no idea
how to do this for user space programs) offers to generate a listing
that interleaves the c code into assembly making it better readable. So
if your function is e.g. in kernel/rtmutex.c you could do the following:
andi at PC63:~/working_git/linux-next$ make kernel/rtmutex.lst
SYSHDR arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h
SYSHDR arch/x86/syscalls/../include/generated/uapi/asm/unistd_64.h
<SNIP>
HOSTCC scripts/asn1_compiler
MKLST kernel/rtmutex.lst
No System.map
andi at PC63:~/working_git/linux-next$
here is one function from the resulting rtmutex.lst file:
static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
{
70: e8 00 00 00 00 callq 75 <fixup_rt_mutex_waiters+0x5>
71: R_X86_64_PC32
__fentry__+0xfffffffffffffffc
75: 55 push %rbp
76: 48 ff 05 00 00 00 00 incq 0x0(%rip) # 7d
<fixup_rt_mutex_waiters+0xd>
79: R_X86_64_PC32 .bss+0x6fc
7d: 48 89 e5 mov %rsp,%rbp
80: 53 push %rbx
81: 48 89 fb mov %rdi,%rbx
if (!rt_mutex_has_waiters(lock))
84: e8 8e ff ff ff callq 17 <rt_mutex_has_waiters>
89: 48 ff 05 00 00 00 00 incq 0x0(%rip) # 90
<fixup_rt_mutex_waiters+0x20>
8c: R_X86_64_PC32 .bss+0x704
90: 85 c0 test %eax,%eax
92: 75 0c jne a0 <fixup_rt_mutex_waiters+0x30>
}
btw. you can for example generate the pre-processed code in the same way:
andi at PC63:~/working_git/linux-next$ make kernel/rtmutex.i
or the assembly code:
andi at PC63:~/working_git/linux-next$ make kernel/rtmutex.s
this is especially helpful, as it also contains a list of all the flags
used for compiling.
regards,
andi
> Any kind of help in understanding this will be appreciated ..
>
> Thanks
> Nidhi
>
>
>
>
>
> --
> Thanks & Regards
> Nidhi Mittal Hada
>
> http://nidhi-searchingmyself.blogspot.com/
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130806/25fc4a97/attachment-0001.html
More information about the Kernelnewbies
mailing list