Small nudge in right direction for buggy keyboard handling

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
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Small nudge in right direction for buggy keyboard handling

Post by Bowlslaw »

Image

What would cause this bug? I can post my code if you need it, but I am interested in trying to figure out what the issue is myself. So far, I have been reading about the 8259 PIC and "Interrupt Problems" on the OSDev wiki, but I haven't not noticed anything.

The correct characters show up on the left side, but then it inserts that strange text afterwards, and goes to a newline.

Have I missed something? Anyone have a nudge in the right direction?
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: Small nudge in right direction for buggy keyboard handli

Post by eryjus »

https://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Sets

Are you properly handling the release codes?

As for the extra text, my first thought is an extra format specifier in kprintf() without a matching parameter.
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Small nudge in right direction for buggy keyboard handli

Post by Bowlslaw »

eryjus wrote:https://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Sets

Are you properly handling the release codes?

As for the extra text, my first thought is an extra format specifier in kprintf() without a matching parameter.
Hm, maybe I forgot to add support for the release codes. This is my code: https://github.com/Bowlslaw/slawOS/blob ... terrupts.c

It draws heavily from meaty skeleton and Sortie, Sortix's OS.

Code: Select all


void pic_init() {
  /* ICW1 - begin initialization */
  port_byte_out(PIC1_CMD, 0x11);
  port_byte_out(PIC2_CMD, 0x11);

  /* ICW2 - remap offset address of IDT
   * In x86 protected mode, we have to remap the PICs after 0x20 because
   * Intel has designated the first 32 interrupts as "reserved" for CPU exceptions
   */
  port_byte_out(PIC1_DATA, 0x20);
  port_byte_out(PIC2_DATA, 0x28);

  /* OCW3 - set up cascading */
  port_byte_out(PIC1_DATA, 0x04);
  port_byte_out(PIC2_DATA, 0x02);
  /*
   * port_byte_out(PIC1_DATA, 0x0);
   * port_byte_out(PIC2_DATA, 0x0);
  */

  /* ICW4 - environment info */
  port_byte_out(PIC1_DATA, 0x01);
  port_byte_out(PIC2_DATA, 0x01);

  /* mask interrupts */
  port_byte_out(PIC1_DATA, 0xFF);
  port_byte_out(PIC2_DATA, 0xFF);
}

void isr_handler(struct regs *r) {
  int irqn = (int)r->irqn;
  printf("INT%d\n", irqn);

  /* write EOI */
  port_byte_out(PIC1_CMD, 0x20);

  switch(irqn) {
  case 0x21:
	kbd_isr_main();
	break;

  default:
	printf("Unknown interrupt %d\n", irqn);
	break;
  }
}

EDIT: Funnily enough...about 2 minutes after I posted this, I found my bug: I was the "printf(INT%d\n", irqn);" statement in the wrong spot, so it would print out the interrupt every single time. I moved it to the default case of the switch/case statement, and it works just fine now!
Post Reply