OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jan 19, 2020 8:13 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: int 0x16 crash
PostPosted: Mon Jan 06, 2020 3:56 pm 
Offline

Joined: Mon Jan 06, 2020 3:42 pm
Posts: 3
Sorry, I'm new to os development, and have never programmed using unix assembly, so this may just be a stupid quiestion.

im using c++, and i'm getting a crash exactly on the 0x16 interrupt. I'm not sure if I just set up memory wrong, but I used the virtualbox debugger to confirm that the crash is on that exact instruction. when qemu encounters the crash it restarts, so I can confirm the crash occurs in both when booting the iso with grub, and when booting the kernel with qemu.
here is my code:
Code:
extern "C" {
char getkey(void)
   {
     char ret;
     asm volatile(
       "movb $0, %%ah\n\t"
       "int $0x16\n\t"
      : "=r" (ret)
      :
      : "ah");
     ret = 0;
     return ret;
   }
}

Thanks for the help


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 5:07 pm 
Offline
Member
Member

Joined: Sat Feb 27, 2010 8:55 pm
Posts: 135
How do you boot up? If you're in protected mode -- which I infer from the C code, as most compilers won't output 16-bit code -- then you can't use the BIOS interrupts.


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 5:41 pm 
Offline

Joined: Mon Jan 06, 2020 3:42 pm
Posts: 3
I don't think I switched into protected mode (unless the grub did) .. will the compiler do it automatically?


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 6:01 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1764
Grub did. Qemu did too.

You're using multiboot, and multiboot specifies that the CPU will be in protected mode when your kernel starts running.


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 7:02 pm 
Offline

Joined: Mon Jan 06, 2020 3:42 pm
Posts: 3
Because i'm in protected mode what would be the best method to get keyboard inputs? I know that you could do virtual 8086 mode, but that sounds complicated, and I don't really understand it.


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 7:24 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 119
Location: North Dakota, United States
You typically get keyboard input via just waiting for interrupt 1. At least, that's how you do it on the PIC. I suspect that on the APIC its much harder, but interrupt 1 will give you keyboard data from the PS/2 controller. You'll need somewhere to store it though (I use a ring buffer in my kernel, for example).
Note that interrupt 1 will not just give you keys pressed but keyboard microcontroller information as well. For example, if you send information to the controller (i.e. perform a self test) it willrespond and this interrupt will fire. Check out the PS/2 controller ad PS/2 keyboard articles for more info on this.


Top
 Profile  
 
 Post subject: Re: int 0x16 crash
PostPosted: Mon Jan 06, 2020 8:34 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1764
0x15 wrote:
what would be the best method to get keyboard inputs?

Start with USB drivers. Most keyboards are USB nowadays, and for the ones that aren't, you want your USB drivers to disable USB legacy support anyway. Then, parse the ACPI tables to see if a PS/2 keyboard controller exists, and if it does, start your PS/2 controller driver.

That's a lot of work, though, and you might want to keep things simple for a first attempt. If that's the case, start your simple PS/2 driver by reading a byte from port 0x60 every time you receive IRQ1. (On most computers, this will work even if the keyboard is USB.) You can then work your way up to more complex drivers that properly initialize the hardware as you become more familiar with OS development.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], max, StudlyCaps and 12 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