[SOLVED] Text mode cursor doesn't appear on QEMU

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
hexcoder
Posts: 15
Joined: Thu Oct 20, 2016 12:26 pm

[SOLVED] Text mode cursor doesn't appear on QEMU

Post by hexcoder »

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: Select all

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: Select all

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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Text mode cursor doesn't appear on QEMU - only on Linux

Post by BrightLight »

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: Select all

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.
hexcoder
Posts: 15
Joined: Thu Oct 20, 2016 12:26 pm

Re: Text mode cursor doesn't appear on QEMU - only on Linux

Post by hexcoder »

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?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Text mode cursor doesn't appear on QEMU - only on Linux

Post by BrightLight »

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.
hexcoder
Posts: 15
Joined: Thu Oct 20, 2016 12:26 pm

Re: Text mode cursor doesn't appear on QEMU - only on Linux

Post by hexcoder »

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.
User avatar
Sik
Member
Member
Posts: 251
Joined: Wed Aug 17, 2016 4:55 am

Re: Text mode cursor doesn't appear on QEMU - only on Linux

Post by Sik »

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.
Post Reply