Page 1 of 1

gcc asm '.section.text.lock"

Posted: Tue Oct 25, 2016 12:14 am
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!

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

Posted: Tue Oct 25, 2016 1:32 am
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'.

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

Posted: Tue Oct 25, 2016 1:44 am
by Octocontrabass
miaowei wrote:But i still don't understand what 's the meaning of 'ax'.
It's explained in the manual.

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

Posted: Tue Oct 25, 2016 7:23 am
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 ... :(