移动文本模式光标不工作

Moving text mode cursor not working

本文关键字:工作 光标 模式 文本 移动      更新时间:2023-10-16

我一直致力于在我目前正在开发的操作系统中移动文本模式光标。我很难让它显示出来。下面是我用来更新游标的代码:

   void update_cursor()
    {
        unsigned char cursor_loc = (y_pos*Cols)+x_pos;
         // cursor LOW port to vga INDEX register
        outb(0x3D4, 0x0F);
        outb(0x3D5, (unsigned char)(cursor_loc));
        // cursor HIGH port to vga INDEX register
        outb(0x3D4, 0x0E);
        outb(0x3D5, (unsigned char)((cursor_loc>>8)));

    }
   static inline void outb(unsigned short port, unsigned char value)
   {
      asm volatile ( "outb %0, %1" : : "a"(value), "Nd"(port) );
    }
    static inline unsigned char inb(unsigned short port)
    {
       unsigned char ret;
       asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
       return ret;
    }

我使用gcc版本4.8.3 (gcc)来编译我的主文件。我完全迷路了。谁有什么建议,这可能是什么问题?如果你想看完整的源代码,它位于这里:https://github.com/AnonymousUser1337/Anmu/blob/master/Kernel/kernel.cpp

EDIT:我使用Virtual box来运行它

您选择错误的VGA寄存器。您必须使用0x0F作为低电平,使用0x0E作为高电平(两者都有0x0A)。

编辑:如果你的光标是禁用的,这是如何启用它:

void enable_cursor() {
    outb(0x3D4, 0x0A);
    char curstart = inb(0x3D5) & 0x1F; // get cursor scanline start
    outb(0x3D4, 0x0A);
    outb(0x3D5, curstart | 0x20); // set enable bit
}

还可以查看此链接查看寄存器号和用法列表。

Edit2:游标位置变量的宽度不足以存储游标位置。unsigned char cursor_loc应该是unsigned short cursor_loc

outb函数在错误的地方有端口和值。而不是:

asm volatile ( "outb %0, %1" : : "a"(value), "Nd"(port) );

试题:

asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));

希望有帮助