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

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

 



Am 24.01.2010 15:51, schrieb me:
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)
    );

    //test file name in rbx and returned file descriptor
    cout<<  test_str<<  endl; // /dev/vcsa1                     pass
    cout<<  test_int<<  endl; // 2 before syscall -14 after ie  fail
}

int main(){
    my_fn();
    return 0;
}
[/code]

I'd be grateful if someone could tell me where I'm going wrong.


Didn't the syscall numbers change in 64bit? I'm not sure.

Best regards.

[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