Prechádzať zdrojové kódy

receive keyboard data

greatbridf 4 rokov pred
rodič
commit
468c2091c4
3 zmenil súbory, kde vykonal 20 pridanie a 0 odobranie
  1. 3 0
      include/asm/port_io.h
  2. 9 0
      src/asm/port_io.s
  3. 8 0
      src/kernel/interrupt.c

+ 3 - 0
include/asm/port_io.h

@@ -2,4 +2,7 @@
 
 #include <types/types.h>
 
+#define PORT_KEYDATA 0x0060u
+
 extern void asm_outb(uint16_t port_number, uint8_t data);
+extern uint8_t asm_inb(uint16_t port_number);

+ 9 - 0
src/asm/port_io.s

@@ -13,3 +13,12 @@ asm_outb:
     popl %edx
     popl %eax
     ret
+
+.globl asm_inb
+.type  asm_inb @function
+asm_inb:
+    pushl %edx
+    movw 8(%esp), %dx
+    inb %dx, %al
+    popl %edx
+    ret

+ 8 - 0
src/kernel/interrupt.c

@@ -2,6 +2,8 @@
 
 #include <asm/port_io.h>
 #include <kernel/interrupt.h>
+#include <kernel/stdio.h>
+#include <kernel/vga.h>
 
 static struct IDT_entry IDT[256];
 
@@ -50,9 +52,15 @@ void irq0_handler(void)
 {
     asm_outb(0x20, 0x20);
 }
+// keyboard interrupt
 void irq1_handler(void)
 {
     asm_outb(0x20, 0x20);
+    uint8_t c = 0x00;
+    c = asm_inb(PORT_KEYDATA);
+    static char buf[4] = { 0 };
+    snprintf(buf, 4, "%d", c);
+    vga_printk(buf, 0x0fu);
 }
 void irq2_handler(void)
 {