使用 MASM 进行内联 io 等待

发布于 2024-08-08 10:43:11 字数 1668 浏览 10 评论 0原文

如何将其转换为使用 VC++ 和 MASM

static __inline__ void io_wait(void)
{
  asm volatile("jmp 1f;1:jmp 1f;1:");
}

我知道 asm 更改为 __asm 并且我们删除了 volatile 但下一步是什么?

我正在尝试创建要放置在下面的代码中的函数

#define PIC1        0x20
#define PIC2        0xA0
#define PIC1_COMMAND    PIC1
#define PIC1_DATA   (PIC1+1)
#define PIC2_COMMAND    PIC2
#define PIC2_DATA   (PIC2+1)
#define PIC_EOI     0x20

#define ICW1_ICW4   0x01        /* ICW4 (not) needed */
#define ICW1_SINGLE 0x02        /* Single (cascade) mode */
#define ICW1_INTERVAL4  0x04        /* Call address interval 4 (8) */
#define ICW1_LEVEL  0x08        /* Level triggered (edge) mode */
#define ICW1_INIT   0x10        /* Initialization - required! */

#define ICW4_8086   0x01        /* 8086/88 (MCS-80/85) mode */
#define ICW4_AUTO   0x02        /* Auto (normal) EOI */
#define ICW4_BUF_SLAVE  0x08        /* Buffered mode/slave */
#define ICW4_BUF_MASTER 0x0C        /* Buffered mode/master */
#define ICW4_SFNM   0x10        /* Special fully nested (not) */

void remap_pics(int pic1, int pic2)
{
    UCHAR   a1, a2;

    a1=ReadPort8(PIC1_DATA);
    a2=ReadPort8(PIC2_DATA);

    WritePort8(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    WritePort8(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    WritePort8(PIC1_DATA, pic1);
    io_wait();
    WritePort8(PIC2_DATA, pic2);
    io_wait();
    WritePort8(PIC1_DATA, 4);
    io_wait();
    WritePort8(PIC2_DATA, 2);
    io_wait();

    WritePort8(PIC1_DATA, ICW4_8086);
    io_wait();
    WritePort8(PIC2_DATA, ICW4_8086);
    io_wait();

    WritePort8(PIC1_DATA, a1);
    WritePort8(PIC2_DATA, a2);
}

How to convert this to use VC++ and MASM

static __inline__ void io_wait(void)
{
  asm volatile("jmp 1f;1:jmp 1f;1:");
}

I know asm changes to __asm and we remove the volatile but whats next?

I am trying to create the function to place in the code below

#define PIC1        0x20
#define PIC2        0xA0
#define PIC1_COMMAND    PIC1
#define PIC1_DATA   (PIC1+1)
#define PIC2_COMMAND    PIC2
#define PIC2_DATA   (PIC2+1)
#define PIC_EOI     0x20

#define ICW1_ICW4   0x01        /* ICW4 (not) needed */
#define ICW1_SINGLE 0x02        /* Single (cascade) mode */
#define ICW1_INTERVAL4  0x04        /* Call address interval 4 (8) */
#define ICW1_LEVEL  0x08        /* Level triggered (edge) mode */
#define ICW1_INIT   0x10        /* Initialization - required! */

#define ICW4_8086   0x01        /* 8086/88 (MCS-80/85) mode */
#define ICW4_AUTO   0x02        /* Auto (normal) EOI */
#define ICW4_BUF_SLAVE  0x08        /* Buffered mode/slave */
#define ICW4_BUF_MASTER 0x0C        /* Buffered mode/master */
#define ICW4_SFNM   0x10        /* Special fully nested (not) */

void remap_pics(int pic1, int pic2)
{
    UCHAR   a1, a2;

    a1=ReadPort8(PIC1_DATA);
    a2=ReadPort8(PIC2_DATA);

    WritePort8(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    WritePort8(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    WritePort8(PIC1_DATA, pic1);
    io_wait();
    WritePort8(PIC2_DATA, pic2);
    io_wait();
    WritePort8(PIC1_DATA, 4);
    io_wait();
    WritePort8(PIC2_DATA, 2);
    io_wait();

    WritePort8(PIC1_DATA, ICW4_8086);
    io_wait();
    WritePort8(PIC2_DATA, ICW4_8086);
    io_wait();

    WritePort8(PIC1_DATA, a1);
    WritePort8(PIC2_DATA, a2);
}

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

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

发布评论

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

评论(2

嗫嚅 2024-08-15 10:43:11

我想如果你告诉我们你想用这段代码做什么,你的运气会更好。 VC++支持的平台都不会通过执行无条件跳转来等待IO完成。

尽管如此,根据您的示例,我看到您需要首先解决的几个问题:

  1. “1f”需要有一个后缀,表明它是十六进制的。在 VC++ 中,您可以在内联汇编中使用 C 风格 (0x1f) 或汇编风格 (1fh) 后缀,
  2. 看起来您有两个“1”标签。除了两个同名标签会发生冲突之外,我相信 VC++ 不支持仅包含数字的标签名称
  3. 1fh 是一个奇怪的跳转地址。在实模式下,它是 IRQ 区域,在保护模式下,它位于第一页内,大多数操作系统都不存在该区域以捕获 NULL 取消引用。

除此之外,您的代码可以转换为 VC++ 应该如下所示:

__asm {
    jmp 1fh
a1:
    jmp 1fh
b1:
}

但这不会给您带来任何有用的东西。所以请说明你想要实现的目标

I think you'll have better luck by telling us what you're trying to do with this code. Neither of the platforms supported by VC++ will wait for IO completion by executing an unconditional jump.

Nevertheless, given your example, I see several problems you need to address first:

  1. "1f" needs to have a suffix indicating that it's hexadecimal. In VC++ you can use either C-style (0x1f) or assembly style (1fh) suffixes in inline assembly
  2. it seems that you've got two "1" labels. Besides the fact that two labels of the same name are going to collide, I believe VC++ doesn't support label names containing only digits
  3. 1fh is a strange address to jump to. In Real mode it's IRQ area, in Protected mode it's inside the first page, which most of the OSes keep not-present to catch NULL dereference.

Barring that, your code can be translated to VC++ should look like this:

__asm {
    jmp 1fh
a1:
    jmp 1fh
b1:
}

But this will not get you anything useful. So please state what you're trying to accomplish

森林迷了鹿 2024-08-15 10:43:11

好像是GNU Gas语法,jmp 1f表示向前跳转到标签1。

static __inline__ void io_wait(void)
{
#ifdef __GNUC__
  asm volatile("jmp 1f;1:jmp 1f;1:");
#else
  /* MSVC x86 supports inline asm */
  __asm {
    jmp a1
  a1:
    jmp b1
  b1:
  }
#endif
}

Seems GNU gas syntax, jmp 1f means jump to label 1 forward.

static __inline__ void io_wait(void)
{
#ifdef __GNUC__
  asm volatile("jmp 1f;1:jmp 1f;1:");
#else
  /* MSVC x86 supports inline asm */
  __asm {
    jmp a1
  a1:
    jmp b1
  b1:
  }
#endif
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文