[Mono-devel-list] Question regarding ASM in mini-x86.c

Jeroen Frijters jeroen at sumatra.nl
Sat Feb 12 03:22:00 EST 2005


Hi,

If you don't know x86 then these parts will be quite tricky to convert
to MSVC, due to the fact that GCC doesn't follow the Intel conventions
in instruction naming and parameter order.

For the two cases below, you could probably use the compiler intrinsincs
_control87() and __cpuid() though.

Here's an example of what the part of cpuid you quoted would look like:

	int have_cpuid = 0;
	__asm {
		pushfd
		pop eax
		mov edx, eax
		xor eax, 0x200000
		push eax
		popfd
		pushfd
		pop eax
		xor eax, edx
		and eax, 0x200000
		mov have_cpuid, eax
	}

Regards,
Jeroen

> -----Original Message-----
> From: mono-devel-list-admin at lists.ximian.com 
> [mailto:mono-devel-list-admin at lists.ximian.com] On Behalf Of J Lothian
> Sent: Saturday, February 12, 2005 06:35
> To: mono-devel-list at lists.ximian.com
> Subject: [Mono-devel-list] Question regarding ASM in mini-x86.c
> 
> Heyyas,
> 
> I seem to have hit a minor roadblock in my quest to get an MSVC 6
> build working, mini-x86 seems to do some interesting things dealing
> with inline ASM, and this is one of those fields I have nearly zero
> experience with.  Before I go and muck about too much, I thought I'd
> ask you all opinions on what I can do here.
> 
> firstly, MSVC doesn't understand __asm__ __volatile__,  it has __asm,
> and a volatile keyword, but I don't believe they can be used together
> in this manner.
> 
> Here's the blocks giving me trouble:
> cpuid (int id, int* p_eax, int* p_ebx, int* p_ecx, int* p_edx)
> {
> 	int have_cpuid = 0;
> 	__asm__  __volatile__ (
> 		"pushfl\n"
> 		"popl %%eax\n"
> 		"movl %%eax, %%edx\n"
> 		"xorl $0x200000, %%eax\n"
> 		"pushl %%eax\n"
> 		"popfl\n"
> 		"pushfl\n"
> 		"popl %%eax\n"
> 		"xorl %%edx, %%eax\n"
> 		"andl $0x200000, %%eax\n"
> 		"movl %%eax, %0"
> 		: "=r" (have_cpuid)
> 		:
> 		: "%eax", "%edx"
> 	);
> 
> and
> 
> void
> mono_arch_cpu_init (void)
> {
> 	guint16 fpcw;
> 
> 	/* spec compliance requires running with double precision */
> 	__asm__  __volatile__ ("fnstcw %0\n": "=m" (fpcw));
> 	fpcw &= ~X86_FPCW_PRECC_MASK;
> 	fpcw |= X86_FPCW_PREC_DOUBLE;
> 	__asm__  __volatile__ ("fldcw %0\n": : "m" (fpcw));
> 	__asm__  __volatile__ ("fnstcw %0\n": "=m" (fpcw));
> 
> }
> 
> The most I can do with these is replace the __asm__ with __asm and
> remove the volatile, but I have a feeling it's not going to perform
> how it's supposed to and that the asm itself probably needs to be
> alterered.   Can anyone help me with this at all?  I'll keep digging
> at it a bit, see if I can figure it out, but this looks like one of
> those times when I'm really gonna need a bit of a hand.  I can add in
> the relavant #ifdef _MSC_VER's to my build notes and svn diff if I can
> figure out what to put in there.
> 
> Thanks for anything you can come up with!
> 
> -J Lothian
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 



More information about the Mono-devel-list mailing list