gcc asm '.section.text.lock"

Programming, for all ages and all languages.
Post Reply
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

gcc asm '.section.text.lock"

Post by miaowei »

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
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

Re: gcc asm '.section.text.lock"

Post by miaowei »

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'.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: gcc asm '.section.text.lock"

Post by Octocontrabass »

miaowei wrote:But i still don't understand what 's the meaning of 'ax'.
It's explained in the manual.
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

Re: gcc asm '.section.text.lock"

Post by miaowei »

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 ... :(
Post Reply