OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Nov 18, 2017 4:21 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:02 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
for the code...

Code:
unsigned long b_input(unsigned char *str, unsigned long count)
{
   unsigned long len;
   asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str));
   return len;
}


Should "mem" be added in the clobber list? as in:

Code:
unsigned long b_input(unsigned char *str, unsigned long count)
{
   unsigned long len;
   asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str) : "mem");
   return len;
}


Since the call to 100020 modifies memory pointed to by str

Just trying to tidy up code and your input will help.

cheers

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Last edited by dchapiesky on Wed Jan 11, 2017 11:11 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:10 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1066
Location: Germany
Yes, you should add "memory" to the clobber list then.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:11 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
Thanks... I thought so but inline asm isn't my strong suite

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:13 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1174
You should also add "cc" to the clobber list if that function modifies any flags. Everyone seems to forget that one.


Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:15 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
'"cc" like carry flag? If you can clarify I need this....

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:18 am 
Offline
Member
Member

Joined: Wed Jan 08, 2014 8:41 am
Posts: 99
Location: Moscow, Russia
dchapiesky wrote:
'"cc" like carry flag? If you can clarify I need this....

CC is for all condition codes, i.e. AF, PF, CF, OF, SF, ZF. Otherwise GCC is free to assume that your inline assembly snippet preserves them and might try to use previous values after the call in generated code.


Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:21 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
Thanks :)

Final code:

Code:
unsigned long b_input(unsigned char *str, unsigned long count)
{
   unsigned long len;
   asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str) : "cc", "memory");
   return len;
}


edited for typo

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Last edited by dchapiesky on Fri Jan 13, 2017 7:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:23 am 
Offline
Member
Member

Joined: Wed Jan 08, 2014 8:41 am
Posts: 99
Location: Moscow, Russia
dchapiesky wrote:
Thanks :)

Also note that when calling functions from inline assembly many of the usual call convention related aspects may not hold. For instance, the direction flag (DF) may be set and the stack may be misaligned.


Top
 Profile  
 
 Post subject: Re: [SOLVED] gcc inline asm clobber list question
PostPosted: Wed Jan 11, 2017 11:27 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
Icee wrote:
For instance, the direction flag (DF) may be set and the stack may be misaligned.


Yah.. ran into the misaligned stack on a different call from this example.

I am going to open a separate thread for another inline asm question that has been bugging me...

Thank you all for your responses

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 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