gpt4 book ai didi

c - bochs 给出 "write to port 0xb004 with len 1 ignored"错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:48:59 24 4
gpt4 key购买 nike

我正在尝试在我的内核开发研究中使用 ACPI。当执行 port_byte_out(0xB004, 0x0000 | 0x2000) 代码时,bochs 给出“write to port 0xb004 with len 1 ignored”错误。 C函数如下:

void port_byte_out(unsigned short port, unsigned char data) {
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
}

这个错误是什么意思?

最佳答案

我认为您打算使用 asm 指令 outb 而不是 outoutb 将一个字节输出到一个端口,其中 out 写入一个 2 字节的字。考虑将代码更改为:

__asm__("outb %%al, %%dx" : : "a" (data), "d" (port));

虽然你定义了函数void port_byte_out(unsigned short port, unsigned char data),第二个参数是unsigned char data你的例子port_byte_out(0xB004, 0x0000 | 0x2000) 试图将 2 字节字(短整型)作为 数据 传递。 port_byte_out 建议您希望该函数输出一个 byte0x0000 | 0x2000 将被截断,因为它比 unsigned char 大。大多数编译器应该对此发出警告。

也许你打算有另一个功能:

void port_word_out(unsigned short port, unsigned short data) {
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
}

那么你可以这样调用它:

port_word_out(0xB004, 0x0000 | 0x2000)

关于c - bochs 给出 "write to port 0xb004 with len 1 ignored"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25991241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com