Os Dev 的 PCI IDE 教程中的函数 insl 有什么作用?
What does the function insl do in Os Dev's PCI IDE tutorial?
这是调用插件的函数
void ide_read_buffer(unsigned char channel, unsigned char reg, unsigned int buffer,
unsigned int quads) {
/* WARNING: This code contains a serious bug. The inline assembly trashes ES and
* ESP for all of the code the compiler generates between the inline
* assembly blocks.
*/
if (reg > 0x07 && reg < 0x0C)
ide_write(channel, ATA_REG_CONTROL, 0x80 | channels[channel].nIEN);
asm("pushw %es; movw %ds, %ax; movw %ax, %es");
if (reg < 0x08)
insl(channels[channel].base + reg - 0x00, buffer, quads);
else if (reg < 0x0C)
insl(channels[channel].base + reg - 0x06, buffer, quads);
else if (reg < 0x0E)
insl(channels[channel].ctrl + reg - 0x0A, buffer, quads);
else if (reg < 0x16)
insl(channels[channel].bmide + reg - 0x0E, buffer, quads);
asm("popw %es;");
if (reg > 0x07 && reg < 0x0C)
ide_write(channel, ATA_REG_CONTROL, channels[channel].nIEN);
}
What does the function insl do in Os Dev's PCI IDE tutorial?
void ide_read_buffer(... unsigned int buffer ...)
看不懂代码原因很清楚:
unsigned int buffer
显然是教程代码中的错误。应该是 unsigned int * buffer
.
现在很清楚 insl
做了什么:它从第一个参数中给定的端口读取 quad
次并将结果写入数组 buffer
.
函数的黑盒行为可以用以下方式解释:
void insl(unsigned reg, unsigned int *buffer, int quads)
{
int index;
for(index = 0; index < quads; index++)
{
buffer[index] = inl(reg);
}
}
这是调用插件的函数
void ide_read_buffer(unsigned char channel, unsigned char reg, unsigned int buffer,
unsigned int quads) {
/* WARNING: This code contains a serious bug. The inline assembly trashes ES and
* ESP for all of the code the compiler generates between the inline
* assembly blocks.
*/
if (reg > 0x07 && reg < 0x0C)
ide_write(channel, ATA_REG_CONTROL, 0x80 | channels[channel].nIEN);
asm("pushw %es; movw %ds, %ax; movw %ax, %es");
if (reg < 0x08)
insl(channels[channel].base + reg - 0x00, buffer, quads);
else if (reg < 0x0C)
insl(channels[channel].base + reg - 0x06, buffer, quads);
else if (reg < 0x0E)
insl(channels[channel].ctrl + reg - 0x0A, buffer, quads);
else if (reg < 0x16)
insl(channels[channel].bmide + reg - 0x0E, buffer, quads);
asm("popw %es;");
if (reg > 0x07 && reg < 0x0C)
ide_write(channel, ATA_REG_CONTROL, channels[channel].nIEN);
}
What does the function insl do in Os Dev's PCI IDE tutorial?
void ide_read_buffer(... unsigned int buffer ...)
看不懂代码原因很清楚:
unsigned int buffer
显然是教程代码中的错误。应该是 unsigned int * buffer
.
现在很清楚 insl
做了什么:它从第一个参数中给定的端口读取 quad
次并将结果写入数组 buffer
.
函数的黑盒行为可以用以下方式解释:
void insl(unsigned reg, unsigned int *buffer, int quads)
{
int index;
for(index = 0; index < quads; index++)
{
buffer[index] = inl(reg);
}
}