aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-06 15:55:30 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-06 15:55:30 +0200
commitdb553d05824ae463752c8b528feac963e41d9f1c (patch)
treecbb203f46a83dc8f16ae9fe6809c6b681108e3e0 /src
parent76c95cff93a8c4832d6276f2f51055bc91e17535 (diff)
Add Interrupt management
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rw-r--r--src/bringelle.c3
-rw-r--r--src/utils/8042.c16
-rw-r--r--src/utils/8042.h63
-rw-r--r--src/utils/asm.h3
-rw-r--r--src/utils/pic.c65
-rw-r--r--src/utils/pic.h22
7 files changed, 170 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index f55cad5..b95e38d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,7 +10,6 @@ UTILS_OBJ := $(addsuffix .o,$(basename $(shell find ./utils -name "*.[c|S]")))
all: $(EXEC)
$(EXEC): boot/boot.o $(UTILS_OBJ) bringelle.o
- echo "Boot obj:" $(BOOT_OBJ)
ld -Ttext=0x00100000 -melf_i386 -nostdlib --oformat=binary -o bringelle $^
%.o: %.S
diff --git a/src/bringelle.c b/src/bringelle.c
index c13744a..013308f 100644
--- a/src/bringelle.c
+++ b/src/bringelle.c
@@ -1,10 +1,11 @@
#include "utils/print.h"
#include "utils/asm.h"
+#include "utils/pic.h"
void bringelle(){
clear();
print("Booting Bringelle...");
-
+ pic_enable_interrupt();
while(1);
}
diff --git a/src/utils/8042.c b/src/utils/8042.c
new file mode 100644
index 0000000..d8a5ba0
--- /dev/null
+++ b/src/utils/8042.c
@@ -0,0 +1,16 @@
+#include "8042.h"
+#include "print.h"
+#include "asm.h"
+
+DEFINE_AZERTY;
+
+void _8042_keypress(){
+ u8 data;
+ do {
+ inb(0x64,data);
+ }
+ while((data&0x01) == 0);
+ inb(0x60,data);
+ if(data<0x80)
+ putchar(AZERTY[data]);
+}
diff --git a/src/utils/8042.h b/src/utils/8042.h
new file mode 100644
index 0000000..1fecf2a
--- /dev/null
+++ b/src/utils/8042.h
@@ -0,0 +1,63 @@
+#ifndef _8042_H
+#define _8042_H
+
+#include "types.h"
+
+void _8042_keypress();
+
+#define DEFINE_AZERTY char AZERTY[]={\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',/* 10 */\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ '?',\
+ 'a',\
+ 'z',\
+ 'e',\
+ 'r',\
+ 't',\
+ 'y',\
+ 'u',\
+ 'i',\
+ 'o',\
+ 'p',\
+ '^',\
+ '$',\
+ '?',\
+ '?',\
+ 'q',/* 0x1E (30) */\
+ 's',\
+ 'd',\
+ 'f',\
+ 'g',\
+ 'h',\
+ 'j',\
+ 'k',\
+ 'l',\
+ 'm',\
+ '?',\
+ '?',\
+ '?',\
+ '*',\
+ 'w',\
+ 'x',\
+ 'c',\
+ 'v',\
+ 'b',/* 0x30 (48) */\
+ 'n',\
+ ',',\
+ ';',\
+}
+
+#endif \ No newline at end of file
diff --git a/src/utils/asm.h b/src/utils/asm.h
index 0929afa..f92195f 100644
--- a/src/utils/asm.h
+++ b/src/utils/asm.h
@@ -7,5 +7,6 @@
#define outbj(port,value) \
asm volatile ("outb %%al, %%dx;" :: "a" (value), "d"(port) )
-
+#define inb(port,dst) \
+ asm volatile ("inb %%dx, %%al": "=a" (dst) : "d" (port))
#endif \ No newline at end of file
diff --git a/src/utils/pic.c b/src/utils/pic.c
new file mode 100644
index 0000000..f77eb70
--- /dev/null
+++ b/src/utils/pic.c
@@ -0,0 +1,65 @@
+#include "pic.h"
+#include "asm.h"
+#include "mem.h"
+
+struct IDT_REGISTER IDTR={
+ 90*8,
+ 0
+};
+
+/// Bridge between IDT and functions call
+asm (
+"PIC_IRQ_DEFAULT:"
+ "movb $0x20, %al \n\t"
+ "outb %al, $0x20 \n\t"
+ "iret \n\t"
+"PIC_IRQ_PRINT: \n\t"
+ "call _8042_keypress \n\t"
+ "movb $0x20, %al \n\t"
+ "outb %al, $0x20 \n\t"
+ "iret \n\t"
+);
+
+extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT;
+
+
+void pic_enable_interrupt(){
+ // Map first default 32 entries
+ for(int i=0;i<90;i++){
+ pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_DEFAULT,IDT_TYPE_1});
+ if(i==32)
+ pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_PRINT,IDT_TYPE_1});
+ }
+
+ // Now configure 8952A
+
+ // ICW1: Initialisation
+ outbj(0x20,0x11); // Master
+ outbj(0xA0,0x11); // Slave
+
+ // ICW2: Map IRQ index to entry into the IDT
+ outbj(0x21,0x20); // Start interrupt at offset 0x20 in IDT (index 32)
+ outbj(0xA1,0x50); // Start interrupt at offset 0x50 in IDT (index 80)
+
+ // ICW3: Indicate the connection between master and slave
+ outbj(0x21,0x02); // Slave connected to pin 2
+ outbj(0xA1,0x01); // Indicate pin id to the slave (2-1)
+
+ // ICW4: Operating mode
+ outbj(0x21,0x01); // Default operating mode
+ outbj(0xA1,0x01); // Default operating mode
+
+ asm("lidtl (IDTR)");
+ asm("sti");
+
+}
+
+void pic_add_idt_entry(IDT_ENTRY entry){
+ static int cur_offset=0;
+ int descriptor[2];
+ descriptor[0]=entry.offset & 0xFFFF | entry.segment << 16;
+ descriptor[1]=entry.type & 0xFFFF | entry.offset & 0xFFFF0000;
+
+ memcpy((void*)descriptor, (void *)(IDTR.base+cur_offset),8);
+ cur_offset+=8;
+} \ No newline at end of file
diff --git a/src/utils/pic.h b/src/utils/pic.h
new file mode 100644
index 0000000..b8f98ac
--- /dev/null
+++ b/src/utils/pic.h
@@ -0,0 +1,22 @@
+#ifndef PIC_H
+#define PIC_H
+
+#include "types.h"
+
+#define IDT_TYPE_1 0x8E00
+
+typedef struct IDT_ENTRY {
+ u16 segment;
+ u32 offset;
+ u16 type;
+} IDT_ENTRY;
+
+struct IDT_REGISTER {
+ u16 limit;
+ u32 base;
+} __attribute__((packed));
+
+void pic_enable_interrupt();
+void pic_add_idt_entry(IDT_ENTRY entry);
+
+#endif \ No newline at end of file