在C++中集成X86组件旧MS-DOS系统信息计划的项目

发布于 2025-01-23 03:48:59 字数 1483 浏览 3 评论 0原文

我是C ++编程的新手,并且一直想为MS-DOS编写系统信息程序。我目前正在为我的项目使用最新的Digimars C ++编译器和MASM 6.13。该项目设置适用于具有Intel 8088处理器的目标CPU的大型内存模型,可与MS-DOS的最兼容性。

我正在尝试编写一个例程,该程序检查CPU是否支持在后期型号486和早期Pentium CPU上找到的CPUID指令。我通过Google搜索找到了几个代码,并且能够将它们添加到项目中并成功编译,但它们都无法使用。问题是,当我尝试执行程序时,我会收到有关无效指令(在我的Windows NT 3.51测试系统下)的消息,并且它完全挂在我的测试MS-DOS系统上。

我正在使用的代码如下:

public _is_cpuid_supported

cpuid macro
    db 0fh, 0a2h
endm

_is_cpuid_supported proc near
    .486
    push bp
    mov bp, sp
    sub sp, 40
    push eax
    push ebx
    pushfd                    ; get extended flags
    pop eax
    mov ebx, eax              ; save current flags
    xor eax, 200000h          ; toggle bit 21
    push eax                  ; put new flags on stack
    popfd                     ; flags updated now in flags
    pushfd                    ; get extended flags
    pop eax
    xor eax, ebx              ; if bit 21 r/w then eax <> 0
    pop ebx
    pop eax
    je no_cpuid               ; can't toggle id bit 21, no cpuid here
    mov ax, 1                 ; cpuid supported
    jmp done_cpuid_sup

no_cpuid:
    mov ax, 0                 ; cpuid not supported

done_cpuid_sup:
    mov sp, bp
    pop bp
    ret
_is_cpuid_supported endp

我还尝试了Osdev.org的示例: https://wiki.osdev.org/cpuid?msclkid=3c6e16f9c23611ec98be59859859d0dd887 但它也不起作用。有技巧吗?让我知道是否需要进一步澄清。

I'm new to C++ programming and have always wanted to write a system information program for MS-DOS. I'm currently using the latest DigiMars C++ compiler and MASM 6.13 for my project. The project settings are for large memory model with a target CPU of an Intel 8088 processor for the widest compatibility with MS-DOS.

I'm attempting to write a routine that checks if the CPU supports the CPUID instruction found on late model 486 and early Pentium CPUs. I found a couple bits of code through Google searches and have been able to add them to the project and successfully compile, but none of them work. The problem is that when I attempt to execute the program I get a message about an invalid instruction (under my Windows NT 3.51 test system) and it completely hangs on my test MS-DOS systems.

The code I'm using is as follows:

public _is_cpuid_supported

cpuid macro
    db 0fh, 0a2h
endm

_is_cpuid_supported proc near
    .486
    push bp
    mov bp, sp
    sub sp, 40
    push eax
    push ebx
    pushfd                    ; get extended flags
    pop eax
    mov ebx, eax              ; save current flags
    xor eax, 200000h          ; toggle bit 21
    push eax                  ; put new flags on stack
    popfd                     ; flags updated now in flags
    pushfd                    ; get extended flags
    pop eax
    xor eax, ebx              ; if bit 21 r/w then eax <> 0
    pop ebx
    pop eax
    je no_cpuid               ; can't toggle id bit 21, no cpuid here
    mov ax, 1                 ; cpuid supported
    jmp done_cpuid_sup

no_cpuid:
    mov ax, 0                 ; cpuid not supported

done_cpuid_sup:
    mov sp, bp
    pop bp
    ret
_is_cpuid_supported endp

I've also tried the sample from OSDev.org here: https://wiki.osdev.org/CPUID?msclkid=3c6e16f9c23611ec98be59859d0dd887 but it doesn't work either. Any tips? Let me know if further clarification is needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2025-01-30 03:48:59

大型内存模型DOS程序中,汇编过程的默认值为far。从行近距离关键字从行_is_cpuid_supported proc靠近解决了问题。感谢@michaelpetch的提示。

In large memory model DOS programs, the default for assembly procedures is far. Removing the near keyword from the line _is_cpuid_supported proc near solved the problem. Thanks to @MichaelPetch for the tip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文