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
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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
get a book on i86 assembly and learn it. -- Thank you Warm Regards Anuz
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@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.
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
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@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
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-...] 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.
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.
Valdis.Kletnieks@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
-----Original Message----- From: kernelnewbies-bounces+jharan=bytemobile.com@kernelnewbies.org [mailto:kernelnewbies- bounces+jharan=bytemobile.com@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
participants (7)
-
Alexander Kuleshov -
Anuz Pratap Singh Tomar -
Bjørn Mork -
Jeff Haran -
Nicholas Krause -
nick -
Valdis.Kletnieks@vt.edu