LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 08-03-2011, 09:38 PM   #1
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Rep: Reputation: 16
Would you mind explain the get_current() for Power?


Experts

I am reading the code get_current()

static inline struct task_struct *get_current(void)
{
struct task_struct *task;

__asm__ __volatile__("ld %0,%1(13)"
: "=r" (task)
: "i" (offsetof(struct paca_struct, __current)));

return task;
}

I guest the %0 is the local variable "task".
%1 is the offset of __current of struct paca_struct.

while I still don't understand the meaning of
"ld %0, %1(13)"
 
Old 08-04-2011, 03:21 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,060

Rep: Reputation: 88
Following link can help you
http://www.ibiblio.org/gferg/ldp/GCC...bly-HOWTO.html
 
Old 08-04-2011, 11:20 PM   #3
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Original Poster
Rep: Reputation: 16
this is very helpful.

but I am curious about where r13 is set to paca?
 
Old 08-05-2011, 03:49 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,060

Rep: Reputation: 88
Where do you get the code? Why do mention r13?
 
Old 08-06-2011, 04:01 AM   #5
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Original Poster
Rep: Reputation: 16
ld %0,%1(13)

the 13 in the () means r13.

arch/powerpc/include/asm/current.h
 
Old 08-08-2011, 02:18 AM   #6
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Original Poster
Rep: Reputation: 16
BTW, the document you pointed out is for x86 I think.
Do you have a Power version?
 
Old 08-08-2011, 08:35 AM   #7
robvoo
LQ Newbie
 
Registered: Jul 2009
Distribution: debian, ubuntu
Posts: 22

Rep: Reputation: 2
When using inline assembly in GCC
(see howto posted by nini09)
the following template is defined in your c code

asm ( assembler template
: output operands /* optional */
: input operands /* optional */
: list of clobbered registers /* optional */
);

%0 means the first operand used, and this starts counting at the output operands
in this example only one output operand is available so this is %0
only one input operand is used so this gets %1

when there would have been two output operands these would get %0 %1 as index
and the only input operand would get %2 as index

"=r" this modifier says that it is the output operand and is write-only ("="), and use an "r" register for this value
"i" means use an i type register for this value
(don't exactly know the internals of power-pc so correct me if i'm wrong)

Hope this explanation is clear, this is also mentioned in the GCC howto.
Registers, Register names etc., And how the compiler uses them is architecture specific and you should try to search for technical reference manuals of your architecture.

Regards

Rob

Last edited by robvoo; 08-08-2011 at 08:42 AM.
 
1 members found this post helpful.
Old 08-09-2011, 02:17 AM   #8
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Original Poster
Rep: Reputation: 16
Thanks a lot for your reply.

In the howto posted by nini09, "i" means:
"i" : An immediate integer operand (one with constant value) is allowed. This includes symbolic constants whose values will be known only at assembly time.
I think this has the same meaning for Power.

So there is no specific gcc inline asm syntax for Power architecture, at least it is not popular?
 
Old 08-09-2011, 03:23 PM   #9
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,060

Rep: Reputation: 88
ld %0,%1(13)

the 13 in the () is compiler helper.
 
  


Reply

Tags
power


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Management not working on embedded MIPS when using /sys/power/state RichardS Programming 1 01-21-2011 08:18 AM
power company idiots cut power while system was on, now hangs at boot with # prompt shroomy_bee Linux - Newbie 10 07-04-2008 01:12 AM
can someone explain power supplies to me? drumvudu Linux - Hardware 6 01-15-2007 09:41 PM
How to use kernel functions like get_current() in user programs Sreeram B S Linux - Kernel 1 09-02-2006 10:09 PM
LXer: Linux Networx partners with CEI to power 2X visualization power of ... LXer Syndicated Linux News 0 04-26-2006 04:03 AM


All times are GMT -5. The time now is 01:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration