OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 7:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [SOLVED] Text mode cursor doesn't appear on QEMU
PostPosted: Fri Jul 14, 2017 3:35 pm 
Offline

Joined: Thu Oct 20, 2016 12:26 pm
Posts: 15
I'm writing an OS in Rust, but when I run it the textmode cursor doesn't appear. It works fine on OSX (tried on QEMU and VirtualBox there) but when I run QEMU on Linux it doesn't show up - after the GRUB text has displayed, the cursor disappears for good.

I'm wondering if this is to do with not reading values from the BIOS data area but instead hard coding them. Regardless, here is the relevant code (the rust part should be pretty self explanatory even if you haven't used rust before):

Code:
pub fn update_cursor(x: usize, y: usize) {
   assert!(x < BUFFER_WIDTH);
   assert!(y < BUFFER_HEIGHT);
   let position = y * BUFFER_WIDTH + x;
    unsafe {
      ::arch::io::outb(0x3D4, 0x0F);
      ::arch::io::outb(0x3D5, (position & 0xFF) as u8);
      ::arch::io::outb(0x3D4, 0x0E);
      ::arch::io::outb(0x3D5, ((position >> 8) & 0xFF) as u8);
   }
}


Code:
section .text
bits 64

global outb
outb:
   mov eax, esi
   mov edx, edi
   out dx, al
   ret

global inb
inb:
   mov edx, edi
   in al, dx
   ret


Any ideas, or is this a bug with QEMU? I'm using qemu-system-x86_64 version 2.8.1 (Debian 1:2.8+dfsg-6).


Last edited by hexcoder on Fri Jul 14, 2017 4:30 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Text mode cursor doesn't appear on QEMU - only on Linux
PostPosted: Fri Jul 14, 2017 4:17 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
I've seen a post before yours on this issue, which also involved booting from GRUB. Apparently, some GRUB builds don't make the cursor visible on QEMU, and since there is no BIOS functions for you, you need to configure the VGA registers yourself.
Code:
outb(0x3D4, 0x09);   // set maximum scan line register to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0B);   // set the cursor end line to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0A);   // set the cursor start line to 14 and enable cursor visibility
outb(0x3D5, 0x0E);


In case you don't want to copy/paste without knowing what you're doing, the first two lines write the value 15 to register index 9, which is the "maximum scan line" register. This register encodes the height of each character on the VGA text mode screen minus 1. In your case, the default for VGA mode 3 (which is the default VGA text mode) the height is 16, and so we write 15. The next access write the value 15 to register index 11, which is the "cursor end line" register. From the hardware's point of view, the cursor is simply a rectangle whose width is always the character's width, but height can be configured. The cursor end line encodes the last Y coordinate of the cursor, which is 15 because the character's height is 16. The next access writes the value 14 to register index 10, which sets the first Y coordinate of the cursor, which is 14. Ultimately, this tells the hardware to draw a cursor from Y coordinate 14 to Y coordinate 15, which makes a rectangle with height 1 pixel, which really is an underscore cursor. Play around and try the different cursor sizes you can make.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Text mode cursor doesn't appear on QEMU - only on Linux
PostPosted: Fri Jul 14, 2017 4:29 pm 
Offline

Joined: Thu Oct 20, 2016 12:26 pm
Posts: 15
omarrx024 wrote:
I've seen a post before yours on this issue, which also involved booting from GRUB. Apparently, some GRUB builds don't make the cursor visible on QEMU, and since there is no BIOS functions for you, you need to configure the VGA registers yourself.


Thank you very much, that worked perfectly! I did have a brief look on these forums, but perhaps I should have looked harder...

EDIT: Maybe this would be good to add to the wiki?


Top
 Profile  
 
 Post subject: Re: Text mode cursor doesn't appear on QEMU - only on Linux
PostPosted: Fri Jul 14, 2017 5:12 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
hexcoder wrote:
EDIT: Maybe this would be good to add to the wiki?

IIRC, the Wiki has links to the FreeVGA documents, and they are the source of my information and the resulting code and are an easy read, so I think keeping the links to FreeVGA's docs is enough.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Text mode cursor doesn't appear on QEMU - only on Linux
PostPosted: Fri Jul 14, 2017 5:23 pm 
Offline

Joined: Thu Oct 20, 2016 12:26 pm
Posts: 15
omarrx024 wrote:
hexcoder wrote:
EDIT: Maybe this would be good to add to the wiki?

IIRC, the Wiki has links to the FreeVGA documents, and they are the source of my information and the resulting code and are an easy read, so I think keeping the links to FreeVGA's docs is enough.


I did actually have a look at that page, but I sort of assumed that GRUB had taken care of that (since it was working fine for me on OSX) so I didn't think of it. Maybe just a link to this thread at the bottom of the wiki page in a 'related discussions' section would be enough, as I'm sure this won't be the last post on this issue.


Top
 Profile  
 
 Post subject: Re: Text mode cursor doesn't appear on QEMU - only on Linux
PostPosted: Tue Jul 18, 2017 1:44 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 17, 2016 4:55 am
Posts: 251
omarrx024 wrote:
hexcoder wrote:
EDIT: Maybe this would be good to add to the wiki?

IIRC, the Wiki has links to the FreeVGA documents, and they are the source of my information and the resulting code and are an easy read, so I think keeping the links to FreeVGA's docs is enough.

I think the warning about GRUB doing this would be what's needed in the wiki. Normally the BIOS (and most bootloaders for that matter) would just leave the cursor shape untouched or at the very least visible in some form, so it's easy to miss the real issue and thing that something went wrong with booting through GRUB.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 197 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group