Skip to contentSkip to conversation

Question about assembly in set bit function for x86 architecture

DISCUSSION nick 6 participants 8 messages Apr 19, 2015 – Apr 20, 2015

lore
Share & tools
lore

nick

author
#0 lore raw

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

#1 lore raw
Quoted 13 lines · nick

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

Quoted 5 lines

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

get a book on i86 assembly and learn it.

Signature · 6 lines
Thank you
Warm Regards
Anuz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150419/1d3edc0a/attachment.html 
#2 lore raw
Quoted 18 lines · Anuz Pratap Singh Tomar
Quoted 8 lines · nick

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

Quoted 1 line

is impossible for me to look up in the Intel Manuals. If someone

either

Quoted 1 line

tells me the registers/instructions this uses or explains the code

that

Quoted 3 lines

would be very helpful.
Nick

Quoted 7 lines
Quoted 5 lines

_______________________________________________
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

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#3 lore raw
Quoted 29 lines · Nicholas Krause
Quoted 18 lines · Anuz Pratap Singh Tomar
Quoted 8 lines · nick

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

Quoted 1 line

is impossible for me to look up in the Intel Manuals. If someone

either

Quoted 1 line

tells me the registers/instructions this uses or explains the code

that

Quoted 3 lines

would be very helpful.
Nick

Quoted 7 lines
Quoted 5 lines

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

get a book on i86 assembly and learn it.

Quoted 11 lines

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.

Signature · 6 lines
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 
#4 lore raw

2015-04-20 5:11 GMT+06:00 Anuz Pratap Singh Tomar <[email protected]>:

Quoted 19 lines
Quoted 15 lines · Nicholas Krause
Quoted 10 lines · Anuz Pratap Singh Tomar
Quoted 8 lines · nick

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

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

this

Quoted 1 line

is impossible for me to look up in the Intel Manuals. If someone

either

Quoted 1 line

tells me the registers/instructions this uses or explains the code

that

Quoted 2 lines

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?

Quoted 1 line
Quoted 1 line

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.

#5 lore raw
In reply to Nicholas Krause
Quoted 6 lines · Nicholas Krause

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

#6 lore raw
Quoted 9 lines · Valdis.Kletnieks at vt.edu
Quoted 6 lines · Nicholas Krause

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.

Quoted 3 lines

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

#7 lore raw
In reply to nick
Quoted 11 lines

-----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) {

Quoted 7 lines
         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