Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling native cpuid obviously doesn't work in windows with Visual studio compiler #17

Closed
wireshrink opened this issue Apr 13, 2017 · 4 comments

Comments

@wireshrink
Copy link

(Who needs it at all, anyway) ?

With visual studio compiler it should look like

...
#if defined(_MSC_VER)
#include <intrin.h>
#endif
...
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
	unsigned int *ecx, unsigned int *edx)
{
	/* ecx is often an input as well as an output. */
	
#if !defined(_MSC_VER)
	
	asm volatile("cpuid"
		: "=a" (*eax),
		"=b" (*ebx),
		"=c" (*ecx),
		"=d" (*edx)
		: "0" (*eax), "2" (*ecx));

#else 
	int registers[4] = {0,0,0,0};
	
	__cpuidex(registers, *eax, *ecx);
	*eax = registers[0];
	*ebx = registers[1];
	*ecx = registers[2];
	*edx = registers[3];

#endif
}

I know that it works in windows but unfortunately can not check that it still works in other places.

@ayeks
Copy link
Owner

ayeks commented May 30, 2017

Hey,
unfortunately I do not have a working visual studio environment currently. I will leave the issue open until someone can help or I have a running environment on my own.

Best regards
Lars

@harcalion
Copy link

I have just compiled the file with the changes @wireshrink suggested for the native_cpuid function and it works on Windows 10 compiled with Visual Studio 2017.

I have then taken the code to a RHEL 6 machine with GCC 4.4.7 and it still works. Using the -Wall switch of course complains that main doesn't return a value.

@georgefeakes
Copy link

Can clarify this change worked for me on Windows 10 with VS Pro 2015. Couldn't get the original version to work at all

ayeks added a commit that referenced this issue Jan 7, 2018
@ayeks
Copy link
Owner

ayeks commented Jan 7, 2018

Thanks guys! 14acc2b

@ayeks ayeks closed this as completed Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants