Skip to content

Can't designate registers in asm! macro #11300

Closed
@edwardw

Description

@edwardw

The x86 instruction in requires specific registers as its operands, i.e. input in dx and output to ax.

#[crate_type="staticlib"];
#[feature(asm)];

#[no_mangle]
pub fn inb(port: u16) -> u8 {
  let data: u8;
  unsafe { asm!("inb $1,$0" : "=a" (data) : "d" (port) :: "volatile"); }
  data
}

But it seems that rustc can't allocate these registers for it:

$ rustc --version
rustc 0.9-pre
host: x86_64-apple-darwin
$ rustc -c asm.rs
error: couldn't allocate output register for constraint 'a'

Trying to relax the register allocation constraints simply leads to invalid assembly:

$ cat asm.rs
...
unsafe { asm!("inb $1,$0" : "=q" (data) : "q" (port) :: "volatile"); }
...
$ rustc -c asm.rs
<inline asm>:1:6: error: invalid operand for instruction
    inb %ax,%cl
LLVM ERROR: Error parsing inline asm

Why is it so? Is it a bug in rustc or in llvm? Any suggestion of where in the rust source code to look into would also be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions