Programming, for all ages and all languages.
miaowei
Member
Posts: 84 Joined: Wed Dec 18, 2013 9:10 am
Post
by miaowei » Tue Oct 25, 2016 12:14 am
I am reading the source code of linux 2.4.
The following code is the entry of 'up' operation of semaphore. It's located in include/asm-i386-semaphore.h .
Code: Select all
static inline void down(struct semaphore * sem)
{
__asm__ __volatile__(
"# atomic down operation\n\t"
LOCK "decl %0\n\t" /* --sem->count */
"js 2f\n"
"1:\n"
".section .text.lock,\"ax\"\n" /* I don't understand this line*/
"2:\tcall __down_failed\n\t"
"jmp 1b\n"
".previous"
:"=m" (sem->count)
:"c" (sem)
:"memory");
}
This line :
".section .text.lock,\"ax\"\n"
What's he doing? The syntax seems horrible. I even don't know how to google it.
Could any friend help me? Thanks!
miaowei
Member
Posts: 84 Joined: Wed Dec 18, 2013 9:10 am
Post
by miaowei » Tue Oct 25, 2016 1:32 am
I see. The code between
Code: Select all
".section .text.lock, \"ax"\n"
...
".previous"
is sent to a special section by gcc.
Because these instructions are not often 'hit', we separate them to another place to get a shorter function body of down().
But i still don't understand what 's the meaning of 'ax'.
miaowei
Member
Posts: 84 Joined: Wed Dec 18, 2013 9:10 am
Post
by miaowei » Tue Oct 25, 2016 7:23 am
Octocontrabass wrote: miaowei wrote: But i still don't understand what 's the meaning of 'ax'.
It's explained in
the manual .
Thank you very much, Octocontrabass.
I treated it as the 'AX' register ...