aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config2
-rw-r--r--Makefile3
-rw-r--r--Makefile.config2
-rw-r--r--devices/pic.h1
-rw-r--r--devices/pic_8259.c11
-rw-r--r--devices/ps2_keyboard.c9
-rw-r--r--devices/vga.c4
-rw-r--r--i686/Makefile2
-rw-r--r--i686/init.s2
-rw-r--r--i686/isr.c4
-rw-r--r--i686/lidt.c7
-rw-r--r--i686/sys/control.h12
-rw-r--r--src/kernel.c10
13 files changed, 51 insertions, 18 deletions
diff --git a/.config b/.config
index a843a13..038981e 100644
--- a/.config
+++ b/.config
@@ -2,7 +2,7 @@
#
# Toolchain
#
-CONFIG_CCFLAGS=""
+CONFIG_CCFLAGS="-g"
CONFIG_LDFLAGS=""
# end of Toolchain
diff --git a/Makefile b/Makefile
index ca76f48..9937467 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ all:
@${MAKE} ARCH=${ARCH} -C src all
run: glitch.iso
- qemu-system-i386 -cdrom glitch.iso -accel kvm
+ qemu-system-i386 -cdrom glitch.iso -accel kvm -d cpu_reset -display gtk,zoom-to-fit=on
clean:
@${MAKE} ARCH=${ARCH} -C lib clean
@@ -60,5 +60,6 @@ glitch.iso: glitch.elf grub/grub.cfg
@grub-script-check grub/grub.cfg
@cp grub/grub.cfg isodir/boot/grub/grub.cfg
@cp glitch.elf isodir/boot/glitch/glitch.elf
+ @${STRIP} isodir/boot/glitch/glitch.elf
@grub-mkrescue -o glitch.iso isodir
diff --git a/Makefile.config b/Makefile.config
index 8f18c80..c3f80ad 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -2,7 +2,7 @@
#
# Toolchain
#
-CONFIG_CCFLAGS=""
+CONFIG_CCFLAGS="-g"
CONFIG_LDFLAGS=""
# end of Toolchain
diff --git a/devices/pic.h b/devices/pic.h
index 685a85b..c545c60 100644
--- a/devices/pic.h
+++ b/devices/pic.h
@@ -1,4 +1,5 @@
#pragma once
void pic_init();
+void pic_enable();
void pic_clear(unsigned char irq);
diff --git a/devices/pic_8259.c b/devices/pic_8259.c
index 74c576a..62164d3 100644
--- a/devices/pic_8259.c
+++ b/devices/pic_8259.c
@@ -1,4 +1,5 @@
#include "pic.h"
+#include <sys/control.h>
#include <sys/io.h>
#define PIC1 0x20
@@ -28,8 +29,18 @@ pic_init()
outb(ICW4_8086, PIC2 + DATA);
// PIC masks
+ outb(0xff, PIC1 + DATA);
+ outb(0xff, PIC2 + DATA);
+}
+
+void
+pic_enable()
+{
+ // PIC masks
outb(0xfc, PIC1 + DATA);
outb(0xff, PIC2 + DATA);
+
+ enable_interrupts();
}
void
diff --git a/devices/ps2_keyboard.c b/devices/ps2_keyboard.c
index e5af423..4ebcc65 100644
--- a/devices/ps2_keyboard.c
+++ b/devices/ps2_keyboard.c
@@ -1,4 +1,5 @@
#include "ps2_keyboard.h"
+#include "vga.h"
#include <stdint.h>
#include <stdio.h>
#include <sys/io.h>
@@ -50,6 +51,14 @@ ps2_keyboard_irq_handler()
case 0xb6: // right shift up
shift_case = 0;
return;
+
+ case 0x5b: // left meta
+ case 0x5c: // right meta
+ return;
+
+ case 0x58: // F12
+ vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
+ return;
}
if (key >= 0x80) return;
diff --git a/devices/vga.c b/devices/vga.c
index 908bd5e..93231ea 100644
--- a/devices/vga.c
+++ b/devices/vga.c
@@ -20,7 +20,7 @@ void
vga_init()
{
buffer = (struct VGAEntry *)0xc03ff000;
- // vga_enable_cursor(0, 15);
+ vga_enable_cursor(0, 15);
vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
}
@@ -35,7 +35,7 @@ vga_clear(enum vga_color foreground, enum vga_color background)
buffer[index].background = background;
}
col = row = 0;
- // vga_update_cursor();
+ vga_update_cursor();
}
void
diff --git a/i686/Makefile b/i686/Makefile
index 431db77..a04e5d3 100644
--- a/i686/Makefile
+++ b/i686/Makefile
@@ -1,6 +1,6 @@
include ../Makefile.config
-CCFLAGS += -I../grub/include -I../lib
+CCFLAGS += -I../grub/include -I../lib -mgeneral-regs-only
arch,SRCS = boot.S init.s \
gdt.c lgdt.c \
diff --git a/i686/init.s b/i686/init.s
index d16de51..ad329bb 100644
--- a/i686/init.s
+++ b/i686/init.s
@@ -15,7 +15,6 @@ k_ptable0x300: .skip 1024 * 4
.section .text
.global k_init
.extern kmain
-.extern pic_init
.extern gdt_install
.extern idt_install
k_init:
@@ -39,7 +38,6 @@ k_init:
# hardware init
call gdt_install # Global Descriptor Table
call idt_install # Interrupt Descriptor Table
- call pic_init # Programmable Interrupt Controller
# jump into kernel
call kmain
diff --git a/i686/isr.c b/i686/isr.c
index 4f6729b..3f99425 100644
--- a/i686/isr.c
+++ b/i686/isr.c
@@ -23,12 +23,11 @@ syscall_handler(struct interrupt_frame *)
abort();
}
-extern void pic_clear(unsigned char irq);
+void pic_clear(unsigned char irq);
__attribute__((interrupt)) void
irq0x00(struct interrupt_frame *)
{
- // printf("irq0x00\n");
pic_clear(0x00);
}
@@ -36,7 +35,6 @@ extern void ps2_keyboard_irq_handler();
__attribute__((interrupt)) void
irq0x01(struct interrupt_frame *)
{
- // printf("irq0x01\n");
ps2_keyboard_irq_handler();
pic_clear(0x00);
}
diff --git a/i686/lidt.c b/i686/lidt.c
index aa6185b..5cb66b6 100644
--- a/i686/lidt.c
+++ b/i686/lidt.c
@@ -39,16 +39,15 @@ idt_install()
{
// exceptions 0x00~0x13
for (int i = 0; i <= 0x13; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
+
// irq 0x20~0x2f
- // for (int i = 0; i < 16; ++i) irq_table[i] = NULL;
- for (int i = 0x20; i <= 0x2f; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
Gate(&interrupt_table[0x20], &irq0x00, 0x10);
Gate(&interrupt_table[0x21], &irq0x01, 0x10);
+ for (int i = 0x22; i <= 0x2f; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
+
// syscall 0x80
Gate(&interrupt_table[0x80], &abort_handler, 0x10);
const struct Pointer ptr = {.limit = sizeof(interrupt_table) - 1, .base = (unsigned)&interrupt_table};
asm volatile("lidt (%0)" : : "a"(&ptr));
-
- asm volatile("sti");
}
diff --git a/i686/sys/control.h b/i686/sys/control.h
index a40a67f..0231236 100644
--- a/i686/sys/control.h
+++ b/i686/sys/control.h
@@ -7,3 +7,15 @@ abort()
h: hlt
jmp h)");
}
+
+static void
+enable_interrupts()
+{
+ asm volatile("sti");
+}
+
+static void
+disable_interrupts()
+{
+ asm volatile("cli");
+}
diff --git a/src/kernel.c b/src/kernel.c
index 6b3df3f..4698d7a 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -4,11 +4,12 @@
// description: kernel entry point
//=====================================================================
-#include "mem.h"
-#include <stdio.h>
+#include "devices/pic.h"
#include "devices/uart_16550.h"
#include "devices/vga.h"
+#include "mem.h"
#include <conf.h>
+#include <stdio.h>
#include <sys/cpuid.h>
void kmain() {
@@ -16,7 +17,6 @@ void kmain() {
if (uart_init(COM1) != 0) printf("UART self-test failed.\r\n");
printf("glitch [version " VERSION "] [" CC "]\n");
-
{
char vendor[13] = {'\0'};
unsigned int eax;
@@ -26,6 +26,10 @@ void kmain() {
printf("CPU: %s family %u model %u stepping %u\n", vendor, family(v), model(v), v.stepping);
}
+ pic_init();
+ pic_enable();
+ printf("interrupts enabled\n");
+
/*
alloc4M();
char *c = (char *)0xc0700000;