x86_64 register constaints

Programming, for all ages and all languages.
Post Reply
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

x86_64 register constaints

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: x86_64 register constaints

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: x86_64 register constaints

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: x86_64 register constaints

Post 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.
If a trainstation is where trains stop, what is a workstation ?
Post Reply