All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about assembly in set bit function for x86 architecture
@ 2015-04-19 20:51 nick
  2015-04-19 21:13 ` Anuz Pratap Singh Tomar
  2015-04-20 16:27 ` Jeff Haran
  0 siblings, 2 replies; 8+ messages in thread
From: nick @ 2015-04-19 20:51 UTC (permalink / raw)
  To: kernelnewbies

Greetings All,
I am wondering what the below code in the asm modifier does:
static inline void set_bit(int nr, void *addr)
{
         asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
}
This would be very helpful as I am new to  x86 assembly and don't
even known what register(s)/instruction(s) this touches and therefore this
is impossible for me to look up in the Intel Manuals. If someone either
tells me the registers/instructions this uses or explains the code that
would be very helpful.
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 20:51 Question about assembly in set bit function for x86 architecture nick
@ 2015-04-19 21:13 ` Anuz Pratap Singh Tomar
  2015-04-19 23:08   ` Nicholas Krause
  2015-04-20 16:27 ` Jeff Haran
  1 sibling, 1 reply; 8+ messages in thread
From: Anuz Pratap Singh Tomar @ 2015-04-19 21:13 UTC (permalink / raw)
  To: kernelnewbies

On Sun, Apr 19, 2015 at 9:51 PM, nick <xerofoify@gmail.com> wrote:

> Greetings All,
> I am wondering what the below code in the asm modifier does:
> static inline void set_bit(int nr, void *addr)
> {
>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
> }
> This would be very helpful as I am new to  x86 assembly and don't
> even known what register(s)/instruction(s) this touches and therefore this
> is impossible for me to look up in the Intel Manuals. If someone either
> tells me the registers/instructions this uses or explains the code that
> would be very helpful.
> Nick
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

get a book on i86 assembly and learn it.

-- 
Thank you
Warm Regards
Anuz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150419/1d3edc0a/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 21:13 ` Anuz Pratap Singh Tomar
@ 2015-04-19 23:08   ` Nicholas Krause
  2015-04-19 23:11     ` Anuz Pratap Singh Tomar
  2015-04-20 15:46     ` Valdis.Kletnieks at vt.edu
  0 siblings, 2 replies; 8+ messages in thread
From: Nicholas Krause @ 2015-04-19 23:08 UTC (permalink / raw)
  To: kernelnewbies



On April 19, 2015 5:13:20 PM EDT, Anuz Pratap Singh Tomar <chambilkethakur@gmail.com> wrote:
>On Sun, Apr 19, 2015 at 9:51 PM, nick <xerofoify@gmail.com> wrote:
>
>> Greetings All,
>> I am wondering what the below code in the asm modifier does:
>> static inline void set_bit(int nr, void *addr)
>> {
>>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
>> }
>> This would be very helpful as I am new to  x86 assembly and don't
>> even known what register(s)/instruction(s) this touches and therefore
>this
>> is impossible for me to look up in the Intel Manuals. If someone
>either
>> tells me the registers/instructions this uses or explains the code
>that
>> would be very helpful.
>> Nick
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>
>get a book on i86 assembly and learn it.
The reason I am asking is that is assembly worth my time to learn for this part of the kernel, I understand  it's use in boot code but outside of that and cache memory lines in architecture directories there is very little, 95 percent of the kernel is written in C.  In addition due to this the only practical reason I  can thing of is for
debugging,  how useful is assembly for kernel debugging is my other question about this topic. 
Nick 
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 23:08   ` Nicholas Krause
@ 2015-04-19 23:11     ` Anuz Pratap Singh Tomar
  2015-04-20  8:05       ` Alexander Kuleshov
  2015-04-20 15:46     ` Valdis.Kletnieks at vt.edu
  1 sibling, 1 reply; 8+ messages in thread
From: Anuz Pratap Singh Tomar @ 2015-04-19 23:11 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Apr 20, 2015 at 12:08 AM, Nicholas Krause <xerofoify@gmail.com>
wrote:

>
>
> On April 19, 2015 5:13:20 PM EDT, Anuz Pratap Singh Tomar <
> chambilkethakur at gmail.com> wrote:
> >On Sun, Apr 19, 2015 at 9:51 PM, nick <xerofoify@gmail.com> wrote:
> >
> >> Greetings All,
> >> I am wondering what the below code in the asm modifier does:
> >> static inline void set_bit(int nr, void *addr)
> >> {
> >>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
> >> }
> >> This would be very helpful as I am new to  x86 assembly and don't
> >> even known what register(s)/instruction(s) this touches and therefore
> >this
> >> is impossible for me to look up in the Intel Manuals. If someone
> >either
> >> tells me the registers/instructions this uses or explains the code
> >that
> >> would be very helpful.
> >> Nick
> >>
> >> _______________________________________________
> >> Kernelnewbies mailing list
> >> Kernelnewbies at kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >>
> >
> >get a book on i86 assembly and learn it.
> The reason I am asking is that is assembly worth my time to learn for this
> part of the kernel, I understand  it's use in boot code but outside of that
> and cache memory lines in architecture directories there is very little, 95
> percent of the kernel is written in C.  In addition due to this the only
> practical reason I  can thing of is for
> debugging,  how useful is assembly for kernel debugging is my other
> question about this topic.
> Nick
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>

Just read the books, don't be lazy.

-- 
Thank you
Warm Regards
Anuz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150420/3e38a2cb/attachment-0001.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 23:11     ` Anuz Pratap Singh Tomar
@ 2015-04-20  8:05       ` Alexander Kuleshov
  0 siblings, 0 replies; 8+ messages in thread
From: Alexander Kuleshov @ 2015-04-20  8:05 UTC (permalink / raw)
  To: kernelnewbies

2015-04-20 5:11 GMT+06:00 Anuz Pratap Singh Tomar <chambilkethakur@gmail.com>:
>
>
> On Mon, Apr 20, 2015 at 12:08 AM, Nicholas Krause <xerofoify@gmail.com>
> wrote:
>>
>>
>>
>> On April 19, 2015 5:13:20 PM EDT, Anuz Pratap Singh Tomar
>> <chambilkethakur@gmail.com> wrote:
>> >On Sun, Apr 19, 2015 at 9:51 PM, nick <xerofoify@gmail.com> wrote:
>> >
>> >> Greetings All,
>> >> I am wondering what the below code in the asm modifier does:
>> >> static inline void set_bit(int nr, void *addr)
>> >> {
>> >>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
>> >> }
>> >> This would be very helpful as I am new to  x86 assembly and don't
>> >> even known what register(s)/instruction(s) this touches and therefore
>> >this
>> >> is impossible for me to look up in the Intel Manuals. If someone
>> >either
>> >> tells me the registers/instructions this uses or explains the code
>> >that
>> >> would be very helpful.
>> >> Nick

What's the problem to read it in the intel manual or just to use
google [https://www.google.com/search?channel=fs&q=btsl+instruction&ie=utf-8&oe=utf-8]
which will give you answer with first link instead of spend time of
community for such questions?

>> 95 percent of the kernel is written in C

This is true. But kernel is big, and are you really sure that somebody
will want to expain you rest of 5% of the
kernel? I am not sure about it.

Yes kernel is big and complex. It contains many tricks which even hard
to find explanation in the interntet. But,
if you want to read/develop kernel, you need learning to learn, but
not just ask. It's important.

Heed the advice of Anuz, he gave the perfect advice.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 23:08   ` Nicholas Krause
  2015-04-19 23:11     ` Anuz Pratap Singh Tomar
@ 2015-04-20 15:46     ` Valdis.Kletnieks at vt.edu
  2015-04-20 16:29       ` Bjørn Mork
  1 sibling, 1 reply; 8+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2015-04-20 15:46 UTC (permalink / raw)
  To: kernelnewbies

On Sun, 19 Apr 2015 19:08:17 -0400, Nicholas Krause said:

> The reason I am asking is that is assembly worth my time to learn for this
> part of the kernel, I understand  it's use in boot code but outside of that and
> cache memory lines in architecture directories there is very little, 95 percent
> of the kernel is written in C.  In addition due to this the only practical
> reason I  can thing of is for debugging,  how useful is assembly for kernel
> debugging is my other question about this topic.

We're not going to bail you out here, Nick.  Either learn enough assembly
to answer your question, or don't obsess over one line of code and assume
it works.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150420/f8f5b361/attachment.bin 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-19 20:51 Question about assembly in set bit function for x86 architecture nick
  2015-04-19 21:13 ` Anuz Pratap Singh Tomar
@ 2015-04-20 16:27 ` Jeff Haran
  1 sibling, 0 replies; 8+ messages in thread
From: Jeff Haran @ 2015-04-20 16:27 UTC (permalink / raw)
  To: kernelnewbies

> -----Original Message-----
> From: kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org
> [mailto:kernelnewbies-
> bounces+jharan=bytemobile.com at kernelnewbies.org] On Behalf Of nick
> Sent: Sunday, April 19, 2015 1:51 PM
> To: kernelnewbies
> Subject: Question about assembly in set bit function for x86 architecture
> 
> Greetings All,
> I am wondering what the below code in the asm modifier does:
> static inline void set_bit(int nr, void *addr) {
>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr)); } This would be very
> helpful as I am new to  x86 assembly and don't even known what
> register(s)/instruction(s) this touches and therefore this is impossible for me
> to look up in the Intel Manuals. If someone either tells me the
> registers/instructions this uses or explains the code that would be very
> helpful.
> Nick

You are dealing with 2 levels of complexity here. First, there's what the actual generated assembly code is doing. For that you'll want to get the Intel manuals but you can get started with the Wikipedia on x86 assembly. Be forewarned, there's two different standards for the syntax here, AT&T's and Intel's, so you'll want to become familiar with the differences between them so you know which one you are reading.

The second level is the embedded assembly-in-C syntax, which is the glue that links C to assembly. What I do whenever I need to read this stuff is I go ahead and compile the code in question then use objdump -S on the .o file to dump the assembly intermixed with the C source. That means I don't have to decipher what that second level is doing. With the original C source and the generated assembly, I can usually figure out what it's doing.

Jeff Haran

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Question about assembly in set bit function for x86 architecture
  2015-04-20 15:46     ` Valdis.Kletnieks at vt.edu
@ 2015-04-20 16:29       ` Bjørn Mork
  0 siblings, 0 replies; 8+ messages in thread
From: Bjørn Mork @ 2015-04-20 16:29 UTC (permalink / raw)
  To: kernelnewbies

Valdis.Kletnieks at vt.edu writes:
> On Sun, 19 Apr 2015 19:08:17 -0400, Nicholas Krause said:
>
>> The reason I am asking is that is assembly worth my time to learn for this
>> part of the kernel, I understand  it's use in boot code but outside of that and
>> cache memory lines in architecture directories there is very little, 95 percent
>> of the kernel is written in C.  In addition due to this the only practical
>> reason I  can thing of is for debugging,  how useful is assembly for kernel
>> debugging is my other question about this topic.
>
> We're not going to bail you out here, Nick.  Either learn enough assembly
> to answer your question, or don't obsess over one line of code and assume
> it works.

It's not necessary to limit this advice by language or specific lines of
code.

NO part of the kernel can be understood without investing some time
trying to learn. But fear not - there is a shortcut available for those
(assuming there might be more than one) who refuse to learn:

  Assume it works.


OK, I'll admit taking that route more than once myself :-)


Bj?rn 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-20 16:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-19 20:51 Question about assembly in set bit function for x86 architecture nick
2015-04-19 21:13 ` Anuz Pratap Singh Tomar
2015-04-19 23:08   ` Nicholas Krause
2015-04-19 23:11     ` Anuz Pratap Singh Tomar
2015-04-20  8:05       ` Alexander Kuleshov
2015-04-20 15:46     ` Valdis.Kletnieks at vt.edu
2015-04-20 16:29       ` Bjørn Mork
2015-04-20 16:27 ` Jeff Haran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.