int 0x16 crash

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
0x15
Posts: 3
Joined: Mon Jan 06, 2020 3:42 pm

int 0x16 crash

Post by 0x15 »

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

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
azblue
Member
Member
Posts: 147
Joined: Sat Feb 27, 2010 8:55 pm

Re: int 0x16 crash

Post by azblue »

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.
0x15
Posts: 3
Joined: Mon Jan 06, 2020 3:42 pm

Re: int 0x16 crash

Post by 0x15 »

I don't think I switched into protected mode (unless the grub did) .. will the compiler do it automatically?
Octocontrabass
Member
Member
Posts: 6282
Joined: Mon Mar 25, 2013 7:01 pm

Re: int 0x16 crash

Post by Octocontrabass »

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.
0x15
Posts: 3
Joined: Mon Jan 06, 2020 3:42 pm

Re: int 0x16 crash

Post by 0x15 »

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.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: int 0x16 crash

Post by Ethin »

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.
Octocontrabass
Member
Member
Posts: 6282
Joined: Mon Mar 25, 2013 7:01 pm

Re: int 0x16 crash

Post by Octocontrabass »

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