获得64位CPUID样本code在VS2008编译 [英] Getting 64-bit CPUID sample code to compile in VS2008

查看:1131
本文介绍了获得64位CPUID样本code在VS2008编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一些C和; ASM样本code,我发现运行在Visual Studio 2008中,我不认为这个问题是VS 2005 - 2008年之间的差异。 <一href=\"http://software.intel.com/en-us/articles/cpuid-for-x64-platforms-and-microsoft-visual-studio-net-2005/\"相对=nofollow>这个例子应该接受在64位系统中的CPUID。 (我尝试获得ASM-仅32位示例编译失败过)

我可以复制这个code粘贴到一个新的项目,但我一直没能建立它。我试过没有成功的几个不同的VS项目模板。我相信我跟着指示一路。有人可以提供一个一步一步来获得在Visual Studio 2008这一运行的项目模板和项目设置?

有一件事我注意到的是,虽然我可以使环境是64位的,我似乎无法针对x64的这个项目 - 添加新平台的唯一选项是移动平台。而我已经在命令行选项,我怀疑我不应该做的手动定义_M_X64。

为了不被直接调试,只是您的信息 - 错误,据我得到的,如下:

  1 GT;组装:\\ cpuid64.asm
1&GT; \\ cpuid64.asm(4):错误A2013:.MODEL必须precede这个指令
1&GT; \\ cpuid64.asm(5):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(7):错误A2034:必须在段块:cpuid64
1&GT; \\ cpuid64.asm(11):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(12):错误A2008:语法错误:。
1&GT; \\ cpuid64.asm(13):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(14):错误A2008:语法错误:。
1&GT; \\ cpuid64.asm(15):错误A2008:语法错误:。
1&GT; \\ cpuid64.asm(17):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(18):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(19):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(20):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(21):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(22):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(23):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(24):错误A2085:指令或当前CPU的模式寄存器不接受
1&GT; \\ cpuid64.asm(26):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(27):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(29):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(30):错误A2034:必须在段块
1&GT; \\ cpuid64.asm(31):致命错误A1010:不匹配的块嵌套:cpuid64


解决方案

好吧,如果你不能定位 64 ,你有一个小问题,因为你不使用 64 工具链。我强烈建议你使用VS安装向导在 64 添加工具。您应该可以去新的平台,称之为 64 键,它的基础的win32

说了这么多,其实我建议使用 YASM ,因为它可以让你与VS集成和YASM是迄今为止比微软的一个更好的汇编。

因为我碰巧有一个无论如何都会受益于这个项目,我想我会用YASM做到这一点:

gcpuid.asm

 ; CPUID在x64-的Win32
;参考:一节。code
全球gcpuid;无效CPUID(uint32_t的* cpuinfo,字符* vendorstr);gcpuid:    推RBP
    MOV RBP,RSP    MOV R8,RCX;捕捉的第一和第二参数成1→ R8,2→ R9
    MOV R9,RDX;原因CPUID将抹杀那些暂存器的下半部    ; retrive在供应商的字符串
    ;三个部分
    MOV EAX,0
    CPUID
    MOV [R9 + 0],EBX
    MOV [R9 + 4],EDX
    MOV [R9 + 8],ECX    ;检索CPU位串,它告诉我们
    ;各种多汁的东西
    MOV EAX,1
    CPUID
    MOV [R8],EAX
    MOV EAX,0    离开
    RET

CPUID-w32.c:

 的#include&LT;&stdio.h中GT;
#包括LT&;&stdint.h GT;无效gcpuid(uint32_t的* cpuinfo,字符* vendorstr);INT主(INT ARGC,字符** argv的)
{
    焦炭供应商[13] = {0};
    uint32_t的标志;    gcpuid(安培;标志,供应商);
    的printf(标志:%U,销售商:%S \\ n,旗帜,供应商);    返回0;
}

在上的链接提供的VS2010存档继 readme.txt文件下载页,这是一个轻而易举得到VS组装这一点,这个解决方案是更清楚,我想,比英特尔。

至于你的的与cpuinfo参数,好了,你可以尝试不同的面具,找出种种关于CPU类型信息​​的。如果我完成了我执行更新可能会

I'm trying to get some c & ASM sample code I found running in Visual Studio 2008. I don't think the problem is the difference between VS 2005-2008. This example is supposed to get the CPUID on 64-bit systems. (My attempts getting the ASM-only 32-bit examples to compile failed too)

I can copy and paste this code into a new project, but I have not been able to build it. I've tried a few different VS project templates with no success. I believe I followed the instructions all the way. Can someone provide a step-by-step to get this running in Visual Studio 2008 with the project template and project settings?

One thing I've noticed is that although I can make the environment be 64-bit, I can't seem to target x64 for this project - the only options for adding new platforms are mobile platforms. And I've had to manually define _M_X64 in the command-line options, which I suspect I shouldn't have to do.

Not to be debugged directly, but just for your info - Errors, as far as I got, are as follows:

1> Assembling: .\cpuid64.asm
1>.\cpuid64.asm(4) : error A2013:.MODEL must precede this directive
1>.\cpuid64.asm(5) : error A2034:must be in segment block
1>.\cpuid64.asm(7) : error A2034:must be in segment block : cpuid64
1>.\cpuid64.asm(11) : error A2034:must be in segment block
1>.\cpuid64.asm(12) : error A2008:syntax error : .
1>.\cpuid64.asm(13) : error A2034:must be in segment block
1>.\cpuid64.asm(14) : error A2008:syntax error : .
1>.\cpuid64.asm(15) : error A2008:syntax error : .
1>.\cpuid64.asm(17) : error A2034:must be in segment block
1>.\cpuid64.asm(18) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(19) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(20) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(21) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(22) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(23) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(24) : error A2085:instruction or register not accepted in current CPU mode
1>.\cpuid64.asm(26) : error A2034:must be in segment block
1>.\cpuid64.asm(27) : error A2034:must be in segment block
1>.\cpuid64.asm(29) : error A2034:must be in segment block
1>.\cpuid64.asm(30) : error A2034:must be in segment block
1>.\cpuid64.asm(31) : fatal error A1010:unmatched block nesting : cpuid64

解决方案

Well, if you can't target x64, you have a slight problem because you're not using the x64 toolchain. I strongly suggest you use the VS install wizard to add in the x64 tools. You should be able to go to new platform, call it x64 and base it on win32.

Having said that, I actually recommend using YASM because it allows you to integrate with VS, and YASM is by far a nicer assembler than Microsoft's.

Since I happen to have a project that would benefit from this anyway, I thought I'd do it using yasm:

gcpuid.asm:

; CPUID on x64-Win32
; Ref: 

section .code
global gcpuid

; void cpuid(uint32_t* cpuinfo, char* vendorstr);

gcpuid:

    push rbp
    mov  rbp, rsp

    mov  r8, rcx   ; capture the first and second arguments into 1-> r8, 2-> r9
    mov  r9, rdx   ; cause cpuid will obliterate the lower half of those regs

    ; retrive the vendor string in its
    ; three parts
    mov eax, 0
    cpuid
    mov [r9+0], ebx    
    mov [r9+4], edx
    mov [r9+8], ecx

    ; retrieve the cpu bit string that tells us
    ; all sorts of juicy things
    mov eax, 1
    cpuid
    mov [r8], eax
    mov eax, 0

    leave
    ret

cpuid-w32.c:

#include <stdio.h>
#include <stdint.h>

void gcpuid(uint32_t* cpuinfo, char* vendorstr);

int main(int argc, char** argv)
{
    char vendor[13] = { 0 };
    uint32_t flags;

    gcpuid(&flags, vendor);
    printf("Flags: %u, Vendor: %s\n", flags, vendor);

    return 0;
}

Following readme.txt in the vs2010 archive supplied on the links download page, it was a doddle to get vs to assemble this, and this solution is much clearer, I think, than intels.

As to what you do with the cpuinfo parameter, well, you can try various masks to find out all sorts of info about the cpu type. I might update if I finish the implementation.

这篇关于获得64位CPUID样本code在VS2008编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆