aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-01 16:50:55 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-01 16:50:55 -0500
commit483754ab27f2a58011f723efa52163a83c63e56e (patch)
treefa50d2afc84b0403db26d92f38226d75adb7f281
parent726684887d414fbefe28d0d210abea8e842ecd21 (diff)
downloadkappa-483754ab27f2a58011f723efa52163a83c63e56e.zip
kappa-483754ab27f2a58011f723efa52163a83c63e56e.tar.gz
kappa-483754ab27f2a58011f723efa52163a83c63e56e.tar.bz2
kappa-483754ab27f2a58011f723efa52163a83c63e56e.tar.xz
lots of stuff
-rw-r--r--Makefile4
-rw-r--r--boot/head.S2
-rw-r--r--drivers/tty.c2
-rw-r--r--kernel/gdt-as.S6
-rw-r--r--kernel/gdt.c3
-rw-r--r--kernel/idt.c1
-rw-r--r--kernel/irq.c4
-rw-r--r--kernel/isr-as.S1
-rw-r--r--kernel/isr.c3
-rw-r--r--kernel/main.c29
-rw-r--r--kernel/panic.c13
-rw-r--r--libc/string.c5
-rw-r--r--libc/string.h3
13 files changed, 49 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 2776f75..2be3779 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-OBJ = drivers/tty.o kernel/main.o boot/head.o kernel/io.o kernel/gdt-as.o kernel/gdt.o
+OBJ = drivers/tty.o kernel/main.o boot/head.o kernel/io.o kernel/gdt-as.o kernel/gdt.o libc/stdio.o libc/string.o kernel/idt.o kernel/idt-as.o kernel/isr.o kernel/irq-as.o kernel/isr-as.o kernel/irq.o kernel/panic.o
CC = gcc
LD = ld
-INCLUDES = -Idrivers -Ikernel/include
+INCLUDES = -Idrivers -Ikernel/include -Ilibc/include
CFLAGS = -std=gnu99 -ffreestanding -fno-stack-protector -nostdlib -Wall -Wextra -m32 $(INCLUDES)
AS = as
diff --git a/boot/head.S b/boot/head.S
index 864ebeb..4143352 100644
--- a/boot/head.S
+++ b/boot/head.S
@@ -22,6 +22,8 @@ stack_top:
.type _start, @function
_start:
movl $stack_top, %esp
+ push %eax # multiboot magic
+ push %ebp # multiboot header
call main
cli
hlt
diff --git a/drivers/tty.c b/drivers/tty.c
index e938abd..c2be189 100644
--- a/drivers/tty.c
+++ b/drivers/tty.c
@@ -11,7 +11,7 @@ static uint16_t *term_buf;
void tty_init(void)
{
term_buf = (uint16_t*)0xB8000;
- term_col = VGA_MAKE_COLOR(VGA_WHITE, VGA_BLACK);
+ tty_set_color(VGA_MAKE_COLOR(VGA_LIGHT_GRAY, VGA_BLACK));
tty_clear();
}
diff --git a/kernel/gdt-as.S b/kernel/gdt-as.S
index 7283dc8..7c8d630 100644
--- a/kernel/gdt-as.S
+++ b/kernel/gdt-as.S
@@ -1,8 +1,7 @@
.global gdt_flush
.type gdt_flush, @function
-gdt_flush: # prototype: void gdt_flush(uint32_t addr)
- cli
- movl 4(%esp), %eax # load the address off the stack (first param)
+gdt_flush: # prototype: void gdt_flush(uint32)
+ movl 4(%esp), %eax
lgdt (%eax)
mov $0x10, %ax
mov %ax, %ds
@@ -10,7 +9,6 @@ gdt_flush: # prototype: void gdt_flush(uint32_t addr)
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
- sti
jmp .flush
.flush:
ret
diff --git a/kernel/gdt.c b/kernel/gdt.c
index f9b2d86..36a0cda 100644
--- a/kernel/gdt.c
+++ b/kernel/gdt.c
@@ -18,9 +18,10 @@ static void gdt_set_gate(int idx, uint32_t base, uint32_t limit, uint8_t access,
void gdt_init(void)
{
- gp.limit = (sizeof(struct gdt_entry) * sizeof(gdt)/sizeof(gdt[0])) - 1;
+ gp.limit = sizeof(gdt) - 1;
gp.base = (uint32_t)&gdt;
+ /* null segment */
gdt_set_gate(0, 0, 0, 0, 0);
/* code segment */
diff --git a/kernel/idt.c b/kernel/idt.c
index e1ff72f..9eda0ce 100644
--- a/kernel/idt.c
+++ b/kernel/idt.c
@@ -13,7 +13,6 @@ void idt_set_gate(uint8_t idx, uint32_t base, uint16_t sel, uint8_t flags)
void idt_init(void)
{
- printf("idt_init()");
idt_pt.limit = sizeof(idt) - 1;
idt_pt.base = (uint32_t)&idt;
diff --git a/kernel/irq.c b/kernel/irq.c
index 5f0a3f5..2498055 100644
--- a/kernel/irq.c
+++ b/kernel/irq.c
@@ -38,8 +38,6 @@ void irq_init(void)
{
irq_remap();
- printf("irq_init()");
-
idt_set_gate(32, (uint32_t)_irq0, 0x08, 0x8E);
idt_set_gate(33, (uint32_t)_irq1, 0x08, 0x8E);
idt_set_gate(34, (uint32_t)_irq2, 0x08, 0x8E);
@@ -64,8 +62,6 @@ void irq_handler(struct regs_t *regs)
handler = irq_callbacks[regs->int_no - 32];
- printf("IRQ called\n");
-
if(handler)
{
handler(regs);
diff --git a/kernel/isr-as.S b/kernel/isr-as.S
index 53e15b4..2bc77f3 100644
--- a/kernel/isr-as.S
+++ b/kernel/isr-as.S
@@ -20,6 +20,7 @@ isr_handler:
pop %ds
popa
add $8, %esp
+ sti
iret
# stub ISR's:
diff --git a/kernel/isr.c b/kernel/isr.c
index fabbf80..424bd22 100644
--- a/kernel/isr.c
+++ b/kernel/isr.c
@@ -6,13 +6,12 @@ void isr_handle(struct regs_t *regs)
{
if(regs->int_no < 32)
{
- printf("received exception!\n");
+ panic("received exception!\n");
}
}
void isr_init(void)
{
- printf("ISR init");
idt_set_gate(0, (uint32_t)_isr0, 0x08, 0x8E);
idt_set_gate(1, (uint32_t)_isr1, 0x08, 0x8E);
idt_set_gate(2, (uint32_t)_isr2, 0x08, 0x8E);
diff --git a/kernel/main.c b/kernel/main.c
index 219e3ee..fd56fb0 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,14 +1,31 @@
-#include "string.h"
+#include "gdt.h"
+#include "idt.h"
+#include "isr.h"
+#include "irq.h"
#include "tty.h"
-#include "vga.h"
+#include <stdio.h>
-void main(void)
+void irq1(struct regs_t *regs)
+{
+ printf("Keypress\n");
+}
+
+void main(struct multiboot_header *hdr, uint32_t magic)
{
tty_init();
+
gdt_init();
- tty_puts("GDT initialized\n");
- tty_set_color(VGA_MAKE_COLOR(VGA_LIGHT_GRAY, VGA_BLACK));
- tty_puts("Hello, world!\n");
+ printf("GDT initialized.\n");
+
+ idt_init();
+ printf("IDT initialized.\n");
+
+ isr_init();
+ irq_init();
+
+ irq_set_handler(1, irq1);
+
+ printf("Hello, world!\n");
while(1)
;
}
diff --git a/kernel/panic.c b/kernel/panic.c
index 106141b..3a2ddf1 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -1,2 +1,13 @@
#include "panic.h"
-#include "
+#include <stdio.h>
+
+__attribute__((noreturn)) void panic(const char *str, ...)
+{
+ /* no printf formatting for now */
+ printf("KERNEL PANIC: %s", str);
+ for(;;)
+ {
+ asm("cli");
+ asm("hlt");
+ }
+}
diff --git a/libc/string.c b/libc/string.c
index 33ccad9..8a9e422 100644
--- a/libc/string.c
+++ b/libc/string.c
@@ -1,10 +1,11 @@
#include <stdint.h>
+#include <stddef.h>
#include "string.h"
int strlen(const char *str)
{
int len = 0;
- while(s++)
+ while(*str++)
len++;
return len;
}
@@ -13,7 +14,7 @@ void* memset(void *buf, int val, size_t sz)
{
for(size_t i = 0; i < sz; ++i)
{
- buf[i] = (uint8_t) val;
+ ((uint8_t*)buf)[i] = (uint8_t) val;
}
return buf;
}
diff --git a/libc/string.h b/libc/string.h
deleted file mode 100644
index 8606fab..0000000
--- a/libc/string.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <stdint.h>
-int strlen(const char*);
-void* memset(void*, int, size_t);