Page 1 of 1

x86_64 register constaints

Posted: Sun May 30, 2010 6:15 am
by gerryg400
I'm trying to tell port my syscall functions to x86_64 using the native parameter passing of the processor. So far I've got something like this.

Code: Select all

static inline uint64_t _Syscall4(uint64_t __n, uint64_t __p1, uint64_t __p2, uint64_t __p3, uint64_t __p4) {
	long ret;
	__asm__ __volatile__ ( \
		"int $0x20\n\t"
		: "=a" (ret)
		: "D" (__n), "S" (__p1), "d" (__p2), "c" (__p3), "XXX" (__p4)
	);
	return ret;
}
There is no register constraint for r8 hence the XXX. If I don't have the constraints, gcc thinks I'm not going to use the parameters and they get optimised away. What can I do ? Thanks in advance.

Re: x86_64 register constaints

Posted: Sun May 30, 2010 6:32 am
by Owen
Local Reg Vars

Just a note: If you're targetting x86_64, seriously use syscall/sysret instead of int. It is significantly faster.

Re: x86_64 register constaints

Posted: Sun May 30, 2010 6:49 am
by gerryg400
Cool, thanks I'll try that. I will use syscall or sysenter, but right now I'm just trying to get things working again. I'll still need to solve this problem won't I ?

Re: x86_64 register constaints

Posted: Sun May 30, 2010 7:36 am
by gerryg400
This appears to work. Do you think it's okay ?

Code: Select all

static inline uint64_t _Syscall4(uint64_t __n, uint64_t __p1, uint64_t __p2, uint64_t __p3, uint64_t __p4) {

	long ret;
	register long r8 asm ("r8") = __p4;

	__asm__ __volatile__ ( \
		"int $0x20\n\t"
		: "=a" (ret)
		: "D" (__n), "S" (__p1), "d" (__p2), "c" (__p3), "r" (r8)

	);
	return ret;
}
Thanks again in advance.