From cfee6a8999c329d8a7dc135d66e6ffb3c50c1fc0 Mon Sep 17 00:00:00 2001
From: Divyam Khandelwal <divyam@wirelessprv-10-194-9-252.near.illinois.edu>
Date: Sat, 21 Apr 2018 01:25:03 -0500
Subject: [PATCH] PIT now interrupting, need to write handler

---
 student-distrib/idt.c     |  3 +++
 student-distrib/idt.h     |  2 ++
 student-distrib/idt_asm.S | 13 +++++++++++++
 student-distrib/kernel.c  |  4 ++++
 student-distrib/pit.c     |  1 +
 student-distrib/rtc.c     |  8 +-------
 6 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/student-distrib/idt.c b/student-distrib/idt.c
index 18ccd21..a6de4c2 100644
--- a/student-distrib/idt.c
+++ b/student-distrib/idt.c
@@ -143,6 +143,9 @@ void initialize_IDT(void)
     SET_IDT_ENTRY(idt[18], MACHINE_CHECK);
     SET_IDT_ENTRY(idt[19], FLOATING_POINT);
 
+    // insert PIT handler into IDT table
+    SET_IDT_ENTRY(idt[PIT_INDEX], PIT_INTERRUPT);
+
     // insert KB handler into IDT table
     SET_IDT_ENTRY(idt[KEYBOARD_INDEX], KB_INTERRUPT);
 
diff --git a/student-distrib/idt.h b/student-distrib/idt.h
index e582e5f..5f81855 100644
--- a/student-distrib/idt.h
+++ b/student-distrib/idt.h
@@ -5,6 +5,7 @@
 #include "lib.h"
 #include "syscall.h"
 
+#define PIT_INDEX      0x20
 #define KEYBOARD_INDEX 0x21
 #define RTC_INDEX      0x28
 #define SYS_CALL_INDEX 0x80
@@ -37,5 +38,6 @@ void MACHINE_CHECK(void);
 void FLOATING_POINT(void);
 void RTC_INTERRUPT(void);
 void KB_INTERRUPT(void);
+void PIT_INTERRUPT(void);
 
 #endif
diff --git a/student-distrib/idt_asm.S b/student-distrib/idt_asm.S
index 08bf40d..3edc997 100644
--- a/student-distrib/idt_asm.S
+++ b/student-distrib/idt_asm.S
@@ -28,6 +28,7 @@
 .globl FLOATING_POINT
 .globl RTC_INTERRUPT
 .globl KB_INTERRUPT
+.globl PIT_INTERRUPT
 
 # - Each function acts as a bridge sending
 #   the interrupt value
@@ -173,3 +174,15 @@ KB_INTERRUPT:
      STI
 
      IRET
+
+PIT_INTERRUPT:
+
+     CLI
+
+     PUSHAL
+     CALL   pit_handler
+     POPAL
+
+     STI
+
+     IRET
\ No newline at end of file
diff --git a/student-distrib/kernel.c b/student-distrib/kernel.c
index 20cec02..61d88d5 100644
--- a/student-distrib/kernel.c
+++ b/student-distrib/kernel.c
@@ -164,6 +164,10 @@ void entry(unsigned long magic, unsigned long addr) {
     rtc_init();
     printf("RTC Initialized\n");
 
+    printf("Initializing PIT\n");
+    i8253_init();
+    printf("PIT Initialized\n");
+
     printf("Initializing paging\n");
     paging_initi();
     printf("Paging Initialized\n");
diff --git a/student-distrib/pit.c b/student-distrib/pit.c
index 7ac463a..624a5d9 100644
--- a/student-distrib/pit.c
+++ b/student-distrib/pit.c
@@ -18,6 +18,7 @@ void i8253_init(void){
 
 void pit_handler(){
 
+	//printf("[PIT] Interrupt Test");
 	send_eoi(0);
 
     //todo
diff --git a/student-distrib/rtc.c b/student-distrib/rtc.c
index dcb4099..e1082c4 100644
--- a/student-distrib/rtc.c
+++ b/student-distrib/rtc.c
@@ -75,13 +75,7 @@ int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes)
 
     /* Wait until interrupt handler clears flag */
     while (interrupt_flag);
-
-    /* Reset flag, necessary?  */
-    //interrupt_flag = 1;
-
-    /* Testing */
-    //printf("Fu");
-
+    
     return 0;
 }
 
-- 
GitLab