Ejemplo n.º 1
0
int main()
{
	printf("%s", appnote);
	if (!has_cpuid())
	{
		printf("CPUID instruction is not supported!\n");
		return 0;
	}
	printf("Manufacturer: %s\n", get_manufacturer());
	printf("Supported instructions:\n");
	if (Has_SSE())
		printf("- SSE\n");
	if (Has_SSE2())
		printf("- SSE2\n");
	if (Has_SSE3())
		printf("- SSE3\n");
	if (Has_SSSE3())
		printf("- SSSE3\n");
	if (Has_SSE4())
		printf("- SSE4 (4.1, 4.2, 4A)\n");
	if (Has_MMX())
		printf("- MMX\n");
	if (Has_3DNow())
		printf("- 3DNow!\n");
	return 0;
}
Ejemplo n.º 2
0
void kmain(void)
{

	init_bss();
	init_ro();

	setup_kernel_memory();
	setup_pages();
	setup_ints();
	setup_tss();
	setup_paging();
	setup_faults();
	setup_fs();
	setup_syscalls();

	init_devs();

	char vendor[12];
	if (has_cpuid()) {
		cpuid_string(0, vendor);
		dprintf("CPU Vendor ID: %s\n");
	}

	fexec("/prgm/start", 0, NULL, NULL);
	start_scheduler();

	asm volatile ("sti");
	asm volatile ("hlt");

	/* We should never reach this */
	assert(0);
}
Ejemplo n.º 3
0
  int X(have_simd_sse2)(void)
  {
       static int init = 0, res;

       if (!init) {
	    res =   !is_386() 
		 && has_cpuid()
		 && (cpuid_edx(1) & (1 << DS(26,25)))
		 && sse2_works();
	    init = 1;
	    X(check_alignment_of_sse2_pm)();
       }
       return res;
  }
Ejemplo n.º 4
0
  int RIGHT_CPU(void)
  {
       static int wav2midi_init = 0, res;

       if (!wav2midi_init) {
	    res =   !is_386() 
		 && has_cpuid()
		 && (cpuid_edx(1) & (1 << 26))
		 && sse2_works();
	    wav2midi_init = 1;
	    X(check_alignment_of_sse2_pm)();
       }
       return res;
  }
Ejemplo n.º 5
0
  int RIGHT_CPU(void)
  {
       static int init = 0, res;
       extern void X(check_alignment_of_sse_pmpm)(void);

       if (!init) {
	    res =   !is_386() 
		 && has_cpuid()
		 && (cpuid_edx(1) & (1 << 25)) 
		 && sse_works();
	    init = 1;
	    X(check_alignment_of_sse_pmpm)();
       }
       return res;
  }
Ejemplo n.º 6
0
int X(have_simd_avx2)(void)
{
    static int init = 0, res;

    if (!init)
    {
        if(has_cpuid() && ((xgetbv_eax(0) & 0x6) == 0x6))
	{
            int eax,ebx,ecx,edx;
            cpuid_all(7,0,&eax,&ebx,&ecx,&edx);
            /* Bit 5 of ebx for CPUID level 7 is AVX2 support */
            res = ((ebx & (1 << 5))  != 0 );
	}
    }
    return res;
}
Ejemplo n.º 7
0
static int has_cpuid(void)
{
	int has = 0;

#if defined(__GNUC__) && defined(i386)
	__asm__(
		"pushfl\n\t"
		"popl %%eax\n\t"
		"movl %%eax, %%edx\n\t"
		"xorl $0x200000, %%eax\n\t"
		"pushl %%eax\n\t"
		"popfl\n\t"
		"pushfl\n\t"
		"popl %%eax\n\t"
		"xorl %%eax, %%edx\n\t"
		"jz done\n\t"
		"movl $1, %0\n\t"
		"done:\n\t"
		:"=m"(has)
		:
		: "%eax", "%edx"
	);
#elif defined(__GNUC__) && defined(__x86_64__)
	__asm__(
		"pushfq\n\t"
		"popq %%rax\n\t"
		"movq %%rax, %%rdx\n\t"
		"xorq $0x200000, %%eax\n\t"
		"pushq %%rax\n\t"
		"popfq\n\t"
		"pushfq\n\t"
		"popq %%rax\n\t"
		"xorl %%eax, %%edx\n\t"
		"jz done\n\t"
		"movl $1, %0\n\t"
		"done:\n\t"
		:"=m"(has)
		:
		: "%rax", "%rdx"
	);
#elif defined(_MSC_VER) && defined(_M_IX86)
	__asm {
		pushfd
		pop eax
		mov edx, eax
		xor eax, 0x200000
		push eax
		popfd
		pushfd
		pop eax
		xor edx, eax
		jz done
		mov has, 1
		done:
	}
#elif defined(_MSC_VER) && defined(_M_X64)
	has = 1;
#endif

	return has;
}

int cpuinfo(unsigned int eax, cpu_info_t *cpu)
{
	if(!(has_cpuid() && cpu))
		return 0;

	__cpuid__(eax, cpu->eax, cpu->ebx, cpu->ecx, cpu->edx);

	return 1;
}