Re: Struggling with conversion to AMD64/Linux syscalls in inline asm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/25/2010 04:47 PM, Jie Zhang wrote:
On 01/25/2010 04:39 PM, me wrote:
On Mon, 25 Jan 2010 12:18:51 +0800
Jie Zhang<jie.zhang@xxxxxxxxxx> wrote:

On 01/24/2010 10:51 PM, me wrote:
I'm trying to convert some 32 bit linked asm (which runs fine)
into 64 bit inline asm (g++) but am stumbling at the first hurdle
ie I'm getting -14 returned as the file descriptor for /dev/vcsa1.

Here's my attempt.

[code]
//My amd64 inline asm version
#include<iostream>
using namespace std;

void my_fn(){
const char * fl = "/dev/vcsa1";
const char * test_str = " "; //make same size as fl
int test_int = -1; //ie initialised to fail unless replaced by
value

//1 open /dev/vcsa1& return file descriptor in rax
__asm__ __volatile__(
".equ sys_open, 2\n"
".equ O_RDWR, 02\n"
"mov $sys_open, %%rax\n"
"mov $O_RDWR, %%rcx\n"
"mov $0600, %%rdx\n" //read/write for user in x86. Not sure for
AMD64? "syscall\n"
:"=b"(test_str), "=a"(test_int)
:"b"(fl)

This statement does not tell gcc the connections between registers
and C variables. So there is no guarantee that those variables will
be put into the registers you expect by the above statement.

I'm grateful for your comment but don't really understand it.
i.e. If...
:"=b"(test_str), "=a"(test_int)
:"b"(fl)
didn't connect the c variable "fl" to the register "rbx" then I'm not
sure how

Oops. I overlooked there is only on register in class 'a' for AMD64. So it definitely connects the register with the variable. Sorry!


Jie

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux