kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: andi.platschek@gmail.com (Andreas Platschek)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Fwd: Understanding disassembly x86 + understanding function call + parameter pass and stack frame
Date: Tue, 06 Aug 2013 16:13:19 +0200	[thread overview]
Message-ID: <5201047F.6070405@gmail.com> (raw)
In-Reply-To: <CAL+pkpfAU1UisMgc_nH0RYpHfoxB9f7ORoXk44cDNwjmj2QHmw@mail.gmail.com>


> 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 

      parent reply	other threads:[~2013-08-06 14:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAL+pkpfXRUPUK9phHEt_auM0zCC97yzkgD0e1TRsFzSMfnrb3g@mail.gmail.com>
2013-08-06  9:06 ` Fwd: Understanding disassembly x86 + understanding function call + parameter pass and stack frame nidhi mittal hada
2013-08-06  9:43   ` Saket Sinha
2013-08-06 10:16     ` Anuz Pratap Singh Tomar
2013-08-06 10:30   ` Fwd: " Tobias Boege
2013-08-06 13:43   ` Matthias Brugger
2013-08-09 19:19     ` Tayade, Nilesh
2013-08-09 21:40       ` neha naik
2013-08-12 11:58         ` nidhi mittal hada
2013-08-12 12:51           ` Tobias Boege
2013-08-12 14:44             ` Tobias Boege
2013-08-12 15:07           ` amit mehta
2013-08-13 12:17             ` nidhi mittal hada
2013-08-13 12:32               ` amit mehta
2013-08-14 10:21                 ` nidhi mittal hada
2013-08-14 10:44                   ` nidhi mittal hada
2013-08-14 11:35                     ` Valdis.Kletnieks at vt.edu
2013-09-03  9:16                       ` nidhi mittal hada
2013-09-15 18:13                         ` Tobias Boege
2013-08-14 10:55                   ` Valdis.Kletnieks at vt.edu
2013-08-06 14:13   ` Andreas Platschek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5201047F.6070405@gmail.com \
    --to=andi.platschek@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).