Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

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.
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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.
meh
Member
Member
Posts: 52
Joined: Sun Oct 21, 2007 4:30 pm

Re: OS dies when I try to move cursor.

Post 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.
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Re: OS dies when I try to move cursor.

Post 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!
meh
Member
Member
Posts: 52
Joined: Sun Oct 21, 2007 4:30 pm

Re: OS dies when I try to move cursor.

Post 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?
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Re: OS dies when I try to move cursor.

Post 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.
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Re: OS dies when I try to move cursor.

Post 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?
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Re: OS dies when I try to move cursor.

Post 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.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: OS dies when I try to move cursor.

Post 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
Last edited by PatrickV on Thu Oct 01, 2009 5:12 pm, edited 2 times in total.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by Combuster »

http://wiki.osdev.org/Printing_to_Screen
http://wiki.osdev.org/Text_Mode_Cursor

Long story short: search the wiki first next time, it has all the answers :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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 :P.

So moving the cursor with C using the function here doesn't seem to work. It's staying right where it was. Any ideas?
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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 :P.

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?
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by sythem »

Are the ones included in sys/io.h correct? If so then yes.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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
sythem
Posts: 6
Joined: Thu Oct 01, 2009 2:03 pm

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post 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 :P

Thanks everyone for your help!
Locked