aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-02 21:48:38 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-02 21:48:38 -0500
commitc8a195e1eb19d346c03c1dfa6ed66c6215caefa2 (patch)
tree3096ea08f7f213d7efe56a86391ab79b27333d40 /kernel
parent5c84e678defa9333aefcdcd0870564fb945a8c61 (diff)
downloadkappa-c8a195e1eb19d346c03c1dfa6ed66c6215caefa2.zip
kappa-c8a195e1eb19d346c03c1dfa6ed66c6215caefa2.tar.gz
kappa-c8a195e1eb19d346c03c1dfa6ed66c6215caefa2.tar.bz2
kappa-c8a195e1eb19d346c03c1dfa6ed66c6215caefa2.tar.xz
Refactor, begin writing a PS/2 driver
Diffstat (limited to 'kernel')
-rw-r--r--kernel/include/isr.h11
-rw-r--r--kernel/include/panic.h1
-rw-r--r--kernel/include/timer.h7
-rw-r--r--kernel/irq.c4
-rw-r--r--kernel/isr.c2
-rw-r--r--kernel/main.c26
-rw-r--r--kernel/timer.c17
7 files changed, 55 insertions, 13 deletions
diff --git a/kernel/include/isr.h b/kernel/include/isr.h
index 5d6d282..de81cd2 100644
--- a/kernel/include/isr.h
+++ b/kernel/include/isr.h
@@ -34,15 +34,18 @@ extern void _isr29(void);
extern void _isr30(void);
extern void _isr31(void);
-/* installs all the ISR's */
+/* installs ISR's 0-31 */
void isr_init(void);
/* This defines what the stack looks like after an ISR was running */
struct regs_t {
- uint32_t gs, fs, es, ds; /* pushed the segs last */
+ uint32_t gs, fs, es, ds; /* pushed the segs last */
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */
- uint32_t int_no, err_code; /* our 'push byte #' and ecodes do this */
+ uint32_t err_code; /* exceptions push this */
+ uint32_t int_no; /* interrupt stubs do this */
uint32_t eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */
-};
+} __attribute__((packed));
+
+#define IRQ(x) (32+x)
void set_interrupt_handler(uint8_t interrupt, void (*func)(struct regs_t));
diff --git a/kernel/include/panic.h b/kernel/include/panic.h
new file mode 100644
index 0000000..db53e8e
--- /dev/null
+++ b/kernel/include/panic.h
@@ -0,0 +1 @@
+void panic(const char*, ...);
diff --git a/kernel/include/timer.h b/kernel/include/timer.h
new file mode 100644
index 0000000..a7459a6
--- /dev/null
+++ b/kernel/include/timer.h
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+extern const uint64_t *current_tick;
+
+struct regs_t;
+
+void timer_init(void);
diff --git a/kernel/irq.c b/kernel/irq.c
index 5d48c46..d98ecda 100644
--- a/kernel/irq.c
+++ b/kernel/irq.c
@@ -55,6 +55,10 @@ void irq_handler(struct regs_t regs)
{
handler(regs);
}
+ else
+ {
+ printf("WARNING: Unhandled IRQ: 0x%x!\n", regs.int_no);
+ }
/* If the IDT entry that was invoked was greater than 40
* (meaning IRQ8 - 15), then we need to send an EOI to
diff --git a/kernel/isr.c b/kernel/isr.c
index a4627d0..cb59603 100644
--- a/kernel/isr.c
+++ b/kernel/isr.c
@@ -19,7 +19,7 @@ void isr_handler(struct regs_t regs)
}
else
{
- printf("WARNING: unhandled ISR");
+ printf("WARNING: unhandled ISR!\n");
}
}
diff --git a/kernel/main.c b/kernel/main.c
index 63ba635..119cf15 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,30 +1,40 @@
+#include <stdio.h>
#include "gdt.h"
#include "idt.h"
#include "isr.h"
#include "irq.h"
+#include "ps2.h"
+#include "timer.h"
#include "tty.h"
-#include <stdio.h>
-
-void interrupt(struct regs_t regs)
-{
-}
void main(struct multiboot_header *hdr, uint32_t magic)
{
+ /* init the terminal first so we can get some output */
tty_init();
+ /* then the descriptor tables so we can do more useful stuff */
gdt_init();
idt_init();
+ /* install all the interrupt stubs */
isr_init();
irq_init();
- for(int i=0;i<256;++i)
- set_interrupt_handler(i, interrupt);
+ /* initialize other drivers */
+ timer_init();
+ ps2_init();
asm("sti");
- printf("Boot finished.!\n");
+ for(;;)
+ {
+ ps2_set_leds(0x01);
+ ps2_set_leds(0x02);
+ ps2_set_leds(0x04);
+ ps2_set_leds(0x02);
+ }
+
+ printf("Boot finished.\n");
while(1)
;
}
diff --git a/kernel/timer.c b/kernel/timer.c
new file mode 100644
index 0000000..4b700d7
--- /dev/null
+++ b/kernel/timer.c
@@ -0,0 +1,17 @@
+#include <stdint.h>
+#include "isr.h"
+#include "timer.h"
+
+uint64_t current_tick_data = 0;
+
+const uint64_t *current_tick = &current_tick_data;
+
+static void timer_callback(struct regs_t regs)
+{
+ ++current_tick_data;
+}
+
+void timer_init(void)
+{
+ set_interrupt_handler(IRQ(0), timer_callback);
+}