SOLVED -- caps lock, num lock, and scroll lock interrupts all being sent twice

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
SuperNovaa41
Posts: 3
Joined: Tue Jun 03, 2025 3:36 pm

SOLVED -- caps lock, num lock, and scroll lock interrupts all being sent twice

Post by SuperNovaa41 »

Hey, I'm still pretty new to OSdev, and i'm currently working on implementing a keyboard driver. However, I'm running into an odd issue. Whenever I press Caps Lock, Num Lock, or Scroll Lock, these all fire interrupts 4 times (press, release, press, release).
Image
However, every other key press functions just fine, only receiving a single interrupt for press and release:
Image

I'm using bochs as my emulator, and here is my code for interrupt handling:

Code: Select all

isr_stub%+%1: ; code from OSDev wiki
	pushad
	cld
	push dword %1
	call exception_handler
	pop eax
	popad
	iret

Code: Select all

void exception_handler(unsigned int i)
{
	if (i <= 31) {
		printf("Exception: %u\n", i); // TODO
		__asm__ volatile ("cli; hlt");
	}
	
	if (i == PIC_KEYB) {
		unsigned char in = inb(0x60);
		// I have a keyboard driver in the works but downgraded to printing the scancodes to diagnose this problem
		printf("scancode: %x\n", in); 
		PIC_sendEOI(1);
	}
}
I have the PIC remapped, and have the keyboard init'ing with some commands to enable scanning, i've messed around with different typematic rates but has changed nothing. I'm at a bit of a loss for this, and was wondering if anyone could provide some input.
Last edited by SuperNovaa41 on Tue Jun 03, 2025 4:31 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5823
Joined: Mon Mar 25, 2013 7:01 pm

Re: caps lock, num lock, and scroll lock interrupts all being sent twice

Post by Octocontrabass »

SuperNovaa41 wrote: Tue Jun 03, 2025 3:51 pmHey, I'm still pretty new to OSdev, and i'm currently working on implementing a keyboard driver.
Keep in mind the keyboard itself and the PS/2 controller are two separate devices that (ideally) should have two separate drivers.
SuperNovaa41 wrote: Tue Jun 03, 2025 3:51 pmand have the keyboard init'ing with some commands to enable scanning,
What initialization are you doing? What happens if you skip the initialization and rely on the defaults configured by the BIOS?
SuperNovaa41
Posts: 3
Joined: Tue Jun 03, 2025 3:36 pm

Re: caps lock, num lock, and scroll lock interrupts all being sent twice

Post by SuperNovaa41 »

Octocontrabass wrote: Tue Jun 03, 2025 4:09 pm
SuperNovaa41 wrote: Tue Jun 03, 2025 3:51 pm...
Keep in mind the keyboard itself and the PS/2 controller are two separate devices that (ideally) should have two separate drivers.
Yea I know, its all very much a work in progress, I'm going to be implementing both, at the moment I'm just taking a break because this is puzzling me.
Octocontrabass wrote: Tue Jun 03, 2025 4:09 pm
SuperNovaa41 wrote: Tue Jun 03, 2025 3:51 pm...
What initialization are you doing? What happens if you skip the initialization and rely on the defaults configured by the BIOS?
Current just sending 0xF4 to port 0x60 to enable scanning, i've tried with typematic (0xF3) as well, but nothing different.
When bypassing those commands, nothing changes, its the same behaviour.
Octocontrabass
Member
Member
Posts: 5823
Joined: Mon Mar 25, 2013 7:01 pm

Re: caps lock, num lock, and scroll lock interrupts all being sent twice

Post by Octocontrabass »

Do you see the same problem in another VM such as QEMU? If not, there might be a problem with your bochsrc or with your copy of Bochs.
SuperNovaa41
Posts: 3
Joined: Tue Jun 03, 2025 3:36 pm

Re: caps lock, num lock, and scroll lock interrupts all being sent twice

Post by SuperNovaa41 »

Octocontrabass wrote: Tue Jun 03, 2025 4:22 pm Do you see the same problem in another VM such as QEMU? If not, there might be a problem with your bochsrc or with your copy of Bochs.
oh wow, its doesn't happen on QEMU. I didn't even think to try it. I appreciate your help :lol:
Post Reply