Page 1 of 2
Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Thu Oct 01, 2009 2:09 pm
by sythem
Hi all!
So I started 2 days ago on my own OS not knowing a bit of assembly and I have to say I'm surprised at how straight forward it is. However... I have a problem. When I call int $0x10 my OS dies... Everything I've read said this should work just fine.
Code: Select all
.global loader # making entry point visible to linker
# setting up the Multiboot header - see GRUB docs for details
.set ALIGN, 1<<0 # align loaded modules on page boundaries
.set MEMINFO, 1<<1 # provide memory map
.set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum required
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
# reserve initial kernel stack space
.set STACKSIZE, 0x4000 # that is, 16k.
.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
loader:
mov $(stack + STACKSIZE), %esp
push $15
call txt_clear # Clears screen
mov $2, %AH
mov $0, %BH
mov $0, %DH
mov $0, %DL
int $0x10 # Moves cursor
#push %eax
#push %ebx
#call kmain # call kernel proper
cli
hang:
hlt # halt machine should kernel return
jmp hang
txt_clear is a C function that works fine when I comment out int $0x10.
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:21 pm
by meh
I don't know much Assembly, but I don't think "int $0x10" will work in protected mode. If you're using GRUB, I think it switches to protected mode for you.
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:23 pm
by sythem
That would explain it. So I have to move the cursor without the BIOS. Or do I need to setup an IDT?
Thanks!
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:42 pm
by meh
I don't think you have to use an IDT, but I'm not completely sure. Do you want to move it with Assembly or C?
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:42 pm
by inx
sythem wrote:So I have to move the cursor without the BIOS. Or do I need to setup an IDT?
Generally, both. Technically, the IDT is optional if you want to periodically poll the hardware and just use cooperative multitasking to move into kernel mode.
However, you're going to need both a video driver (CGA, EGA, VGA, or VESA will all work, with different capabilities, on current hardware, or you can create a native driver for whatever card you're using) and a mouse driver (Serial, PS/2, or USB).
Your other options would be to switch back to real mode for every BIOS call, or set up VM86 and emulate/map all hardware accesses, which will both likely be dog slow.
EDIT: Punctuation creep fixed and added the VM86 option.
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:54 pm
by sythem
Ok so I've now been very much overwhelmed. I have a very simple kernel as of the time being, looking at the tutorials on the wiki, it has IDT as a requirement for a protected mode keyboard driver. So I was wondering if I also needed that in order to do the calls nessesary to move and track the cursor. I'm not anywhere near ready to tackle mouse or video stuff yet.
So I guess my question is now, is IDT the most efficient or easiest way of accessing interrupts from protected mode?
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 2:57 pm
by inx
What you have to remember is that you're not accessing interrupts. Interrupts are signals to the processor that cause it to execute certain vectors.
BIOS interrupts are ROM procedures that are associated with those vectors at system startup. They are software, not part of the hardware.
Using the IDT will still not allow you to access them, they are real mode code. You must either switch back to real mode or set up the BIOS in a VM86 task to be able to use them.
Re: OS dies when I try to move cursor.
Posted: Thu Oct 01, 2009 5:05 pm
by PatrickV
You can move the cursor with inline assembly in your c file. This is one of the ways you can do this
Code: Select all
void move_csr(void)
{
unsigned temp;
/* The equation for finding the index in a linear
* chunk of memory can be represented by:
* Index = [(y * width) + x] */
temp = csr_y * 80 + csr_x;
/* This sends a command to indicies 14 and 15 in the
* CRT Control Register of the VGA controller. These
* are the high and low bytes of the index that show
* where the hardware cursor is to be 'blinking'. To
* learn more, you should look up some VGA specific
* programming documents. A great start to graphics:
* http://www.brackeen.com/home/vga */
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
Copying that exactly is not going to work. The code in red is the part you need to look at
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Thu Oct 01, 2009 5:11 pm
by Troy Martin
The BIOS interrupts do not exist in protected mode. You must, as Patrick said, do the cursor moving and everything in your C.
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Thu Oct 01, 2009 11:04 pm
by Combuster
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Fri Oct 02, 2009 8:07 am
by sythem
Thanks for all the info.
Long story short: search the wiki first next time, it has all the answers
While I'm thankful that you're much nicer about saying this than most people, the reason I'm on the forums is because the wiki confused me, not because I'm lazy
.
So moving the cursor with C using the function
here doesn't seem to work. It's staying right where it was. Any ideas?
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Fri Oct 02, 2009 8:30 am
by Creature
sythem wrote:Thanks for all the info.
Long story short: search the wiki first next time, it has all the answers
While I'm thankful that you're much nicer about saying this than most people, the reason I'm on the forums is because the wiki confused me, not because I'm lazy
.
So moving the cursor with C using the function
here doesn't seem to work. It's staying right where it was. Any ideas?
Are you sure your outb routines are correct?
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Fri Oct 02, 2009 8:56 am
by sythem
Are the ones included in sys/io.h correct? If so then yes.
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Fri Oct 02, 2009 9:23 am
by quok
sythem wrote:Are the ones included in sys/io.h correct? If so then yes.
What is sys/io.h? Hopefully it is something you created yourself and you're not relying on anything from your host environment! Doing so is quite a bad idea.
You can grab a working outb() / outportb() from
http://wiki.osdev.org/Inline_Assembly/Examples
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Fri Oct 02, 2009 9:55 am
by sythem
Thanks again. One more step towards this working hopefully. I was using <sys/io.h> included on my debian VM. However switching to what is shown in the inline assembly examples, which is
almost identical to the inline asm in sys/io.h, has just caused the cursor to disappear instead of moving.
EDIT: Never mind, it's working, I was just using it wrong
Thanks everyone for your help!