OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Nov 17, 2018 7:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: need help with inline assembly
PostPosted: Fri Sep 07, 2018 6:57 pm 
Offline

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 10
I got a simple procedure to get the instruction pointer value

unsigned long long getRIP(){
unsigned long long l1=0LL;
asm("movq %%rip, %0":"=r"(l1));
return l1;
//return -1ULL;
}

gcc gives me the error message

testRIP.c: Assembler messages:
testRIP.c:5: Error: operand type mismatch for `movq'

my thought is that rip is s 64 bit value... define unsigned long long should be a 64 bit value...
so where ishte operand type mismatch from?


Top
 Profile  
 
 Post subject: Re: need help with inline assembly
PostPosted: Fri Sep 07, 2018 7:44 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

ITchimp wrote:
I got a simple procedure to get the instruction pointer value

unsigned long long getRIP(){
unsigned long long l1=0LL;
asm("movq %%rip, %0":"=r"(l1));
return l1;
//return -1ULL;
}

gcc gives me the error message

testRIP.c: Assembler messages:
testRIP.c:5: Error: operand type mismatch for `movq'

my thought is that rip is s 64 bit value... define unsigned long long should be a 64 bit value...
so where ishte operand type mismatch from?


The "MOV" instruction only works with general purpose registers, and RIP isn't considered a general purpose register. To do what you want you'd need to use RIP relative addressing and LEA.

I don't know what the syntax is for AT&T/GAS, but maybe something like "lea $0(%%rip), %0" might work.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: need help with inline assembly
PostPosted: Sat Sep 08, 2018 1:30 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3303
Location: Chichester, UK
I'm intrigued as to why you want to find the value of the instruction pointer within the subroutine. I can see why you might want the value at the point that the routine is called but not why you want the value within a utility routine.


Top
 Profile  
 
 Post subject: Re: need help with inline assembly
PostPosted: Sat Sep 08, 2018 6:32 pm 
Offline

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 10
I was reading Tannenbaum's OS book, in which he mentioned that p-thead and MACH os's C thread... both package does user space threading... I was thinking ... how do you transfer control among those user level threads.... do you have any scheduling mechanism among the thread groups that share the same process?
Also I am wondering if user level thread aforementioned is related to co-routines in Go?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: weedboi6969 and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group