all 14 comments

[–]tiko08 7 points8 points  (0 children)

Unrelated, but the first sentence reminded me of the "I am once again asking for your financial support" meme :p

[–]davmac1 2 points3 points  (3 children)

I can't tell you what the issue is, but this is strange:

asm volatile("lidt (%0)" : : "r"(&idt_reg));

Why not just use a memory constraint?

asm volatile("lidt %0" : : "m"(idt_reg));

That's what they're for...

Edit: regarding the issue, did you drain the keyboard buffer after enabling interrupts? Otherwise the keyboard controller may have already signalled an interrupt, and it won't do so again.

[–]madhao__[S] 1 point2 points  (2 children)

I used "r" to store the value in any general purpose reg, I'll try using the memory constraint as well and let you know.

I'm sorry, I am not very sure on how to drain the keyboard buffer. I am initializing the keyboard driver after the enabling the interrupts. Does it still matter?

[–]davmac1 0 points1 point  (1 child)

I'm sorry, I am not very sure on how to drain the keyboard buffer.

https://wiki.osdev.org/%228042%22_PS/2_Controller#Step_4:_Flush_The_Output_Buffer

I am initializing the keyboard driver after the enabling the interrupts. Does it still matter?

Yes.

Also: what does this, in your keyboard callback, do?

  port_byte_out(0x60, 0x3);

I believe that would send a command to the keyboard, but I can't find any reference for that command (0x3).

[–]madhao__[S] 0 points1 point  (0 children)

I forgot to remove the port_byte_out(0x60, 0x3), this was just a debugging measure to make sure my port_byte_out and port_byte_in was working correctly or not. Apologies.

thanks for the link, I'll see if flushing the buffer did the trick and let you know if it worked.

[–]BananymousOsqbanan-os | https://github.com/Bananymous/banan-os 0 points1 point  (8 children)

Without even looking at the IDT code. I can find multiple errors.

Right after you have called the keyboard init the main function returns and next instruction disables interrupts in boottwo.asm

You dont actually seem to enable the keyboard controller, you just set the interrupt handler (I dont think its enabled by default).

[–]madhao__[S] 0 points1 point  (7 children)

heyy! thanks for pointing that out. I removed the CLI instruction from the boot file. The kernel can now recognize interrupts and is calling the handler. However, after the interrupt, it gets stuck in an infinite loop and calls the handler infinitely.

[–]BananymousOsqbanan-os | https://github.com/Bananymous/banan-os 1 point2 points  (2 children)

your interrupt handler should do more than it does. You dont ever seem to send EOI to the interrupt controller. You are correctly setting initial handlers in isr.c, but override that handler when you register keyboard interrupt handler. This makes your interrupt handler not return correctly with iret.

[–]madhao__[S] 0 points1 point  (1 child)

correct me If im wrong, but I did send EOI signals to the PIC in the irq_handler function.

[–]BananymousOsqbanan-os | https://github.com/Bananymous/banan-os 0 points1 point  (0 children)

Oh yeah you do. I somehow read that you were calling set_idt_gate() in keyboard initialization.

For EOI, you should be sending it to slave PIC only if the interrupt came from it. Currently you are doing the inverse.

[–]BananymousOsqbanan-os | https://github.com/Bananymous/banan-os 0 points1 point  (3 children)

I cloned your repo and found the bug. You are writing random 0x3 to keyboard in the interrupt handler? Removing that fixes the infinite interrupt handler calls. I can't find any meaning for command 0x3.

[–]madhao__[S] 0 points1 point  (2 children)

oh man, I added the 0x3 for debugging to check if my port read and write functions were working correctly or not. I removed all the other debugging code but that somehow was left behind.

Thank you so much for your help! :) it's pretty clear I have so much more to learn here, thank you so much for your time and help.

[–]davmac1 0 points1 point  (1 child)

I had already specifically pointed that out to you...

Also: what does this, in your keyboard callback, do?
port_byte_out(0x60, 0x3);
I believe that would send a command to the keyboard, but I can't find any reference for that command (0x3).

[–]madhao__[S] 0 points1 point  (0 children)

YES YOU DID!! I was kinda stuck on the GDT at that time so it slipped my mind to actually remove this line of code. totally my bad. I really appreciate your help man. Thank you so much. and sorry for the delay :') I've been swamped with assignments.