Moving text mode cursor not working

大憨熊 提交于 2019-12-01 09:26:01

问题


I have been working on moving the text mode cursor in the operating system I am currently developing. I am having trouble getting it to show up at all. Here is the code that I use to update the cursor:

   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;
    }

I use gcc version 4.8.3 (GCC) to compile my main file. I am completely lost. Anyone have any suggestions as to what might be the problem with this? If you want to see the full source it is located here: https://github.com/AnonymousUser1337/Anmu/blob/master/Kernel/kernel.cpp

EDIT: I am using Virtual box to run it

Thanks in advance.


回答1:


You select wrong VGA registers. You have to use 0x0F for low and 0x0E for high (you have 0x0A for both).

Edit: In case your cursor is disabled, this is how to enable it:

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
}

Also check this link for list of register numbers and usages.

Edit2: Your cursor location variable is not wide enough to store the cursor location. unsigned char cursor_loc should be unsigned short cursor_loc.




回答2:


Your outb function has port and value in the wrong places. Instead of:

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

Try:

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

Hope it helps :)



来源:https://stackoverflow.com/questions/25321608/moving-text-mode-cursor-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!