Page 1 of 1
int 0x16 crash
Posted: Mon Jan 06, 2020 3:56 pm
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
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 5:07 pm
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.
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 5:41 pm
by 0x15
I don't think I switched into protected mode (unless the grub did) .. will the compiler do it automatically?
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 6:01 pm
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.
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 7:02 pm
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.
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 7:24 pm
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.
Re: int 0x16 crash
Posted: Mon Jan 06, 2020 8:34 pm
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.