aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-03 18:23:04 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-03 18:23:04 -0500
commite065a7048aa98d253cdcc9298c934bb7af7feaa9 (patch)
tree99768597eda705f9ea1947c96c899a74e3bdc97c
parentc8a195e1eb19d346c03c1dfa6ed66c6215caefa2 (diff)
downloadkappa-e065a7048aa98d253cdcc9298c934bb7af7feaa9.zip
kappa-e065a7048aa98d253cdcc9298c934bb7af7feaa9.tar.gz
kappa-e065a7048aa98d253cdcc9298c934bb7af7feaa9.tar.bz2
kappa-e065a7048aa98d253cdcc9298c934bb7af7feaa9.tar.xz
some work
-rw-r--r--Makefile3
-rw-r--r--README.md4
-rw-r--r--boot/head.S5
-rw-r--r--drivers/ps2.c11
-rw-r--r--drivers/tty.c25
-rw-r--r--kernel/main.c12
-rw-r--r--kernel/timer.c1
-rw-r--r--libc/stdio.c6
8 files changed, 54 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 8045046..ccb2f63 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-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 kernel/timer.o drivers/ps2.o
+OBJ := $(shell cat OBJ)
CC = gcc
LD = ld
INCLUDES = -Idrivers/include -Ikernel/include -Ilibc/include
@@ -32,3 +32,4 @@ kappa.bin: $(OBJ) $(SOURCES) Makefile
clean:
rm -f $(OBJ) kappa.iso kappa.bin
+ rm -rf isodir
diff --git a/README.md b/README.md
index 5f8e290..9f26ade 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
-# kappa
+# Kappa
+
+A little kernel, a rewrite of Gamma.
diff --git a/boot/head.S b/boot/head.S
index f8e5a36..42b1e69 100644
--- a/boot/head.S
+++ b/boot/head.S
@@ -13,8 +13,8 @@ multiboot_header:
.section .stack
stack_bottom: # Stack grows up in addresses, so bottom is
- # lower than the top
- .skip 16384 # 32KB stack
+ # lower in memory than the top
+ .skip 16384 # 16KB stack
stack_top:
.section .text
@@ -30,4 +30,3 @@ _start:
hlt
.Lhang: # Idle
jmp .Lhang
- .size _start, . - _start
diff --git a/drivers/ps2.c b/drivers/ps2.c
index ff85091..0d466aa 100644
--- a/drivers/ps2.c
+++ b/drivers/ps2.c
@@ -4,20 +4,31 @@
#include "isr.h"
#include "ps2.h"
+static void ps2_wait(void)
+{
+ /* wait for the keyboard */
+ while(1)
+ if ((inb(0x64) & 2) == 0) break;
+}
+
void ps2_set_leds(uint8_t status)
{
+ ps2_wait();
outb(0x60, 0xED);
outb(0x60, status);
}
static void ps2_handler(struct regs_t regs)
{
+ (void) regs;
uint8_t scancode = inb(0x60);
/* TODO: handle scancode */
+ printf("key %x\n", scancode);
}
static void ps2_set_scancode_set(uint8_t set)
{
+ ps2_wait();
outb(0x60, 0xF0);
outb(0x60, set);
}
diff --git a/drivers/tty.c b/drivers/tty.c
index 6668be7..6b83232 100644
--- a/drivers/tty.c
+++ b/drivers/tty.c
@@ -1,16 +1,37 @@
#include <stdint.h>
#include "io.h"
+#include "panic.h"
#include "tty.h"
#include "vga.h"
static int term_x, term_y;
static uint8_t term_col;
-/* VGA buffer starts at 0xB8000 */
+/* VGA buffer starts at 0xB8000 on color or 0xB0000 on monochrome */
static uint16_t *term_buf;
+static uint16_t video_detect_hardware(void)
+{
+ const uint16_t *ptr = (const uint16_t*)0x410;
+ return *ptr;
+}
+
void tty_init(void)
{
- term_buf = (uint16_t*)0xB8000;
+ uint16_t vid_type = video_detect_hardware() & 0x30;
+ if(vid_type == 0x20)
+ {
+ /* color */
+ term_buf = (uint16_t*)0xB8000;
+ }
+ else if(vid_type == 0x30)
+ {
+ term_buf = (uint16_t*)0xB0000;
+ }
+ else
+ {
+ /* none */
+ panic("TTY init failed!");
+ }
tty_set_color(VGA_MAKE_COLOR(VGA_LIGHT_GRAY, VGA_BLACK));
tty_clear();
}
diff --git a/kernel/main.c b/kernel/main.c
index 119cf15..62fa8ca 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,3 +1,4 @@
+#include <stdint.h>
#include <stdio.h>
#include "gdt.h"
#include "idt.h"
@@ -26,15 +27,16 @@ void main(struct multiboot_header *hdr, uint32_t magic)
asm("sti");
- for(;;)
+ printf("Boot finished.\n");
+ while(1)
{
ps2_set_leds(0x01);
+ for(int i=0;i<1000000;++i);
ps2_set_leds(0x02);
+ for(int i=0;i<1000000;++i);
ps2_set_leds(0x04);
+ for(int i=0;i<1000000;++i);
ps2_set_leds(0x02);
+ for(int i=0;i<1000000;++i);
}
-
- printf("Boot finished.\n");
- while(1)
- ;
}
diff --git a/kernel/timer.c b/kernel/timer.c
index 4b700d7..571fcbe 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -8,6 +8,7 @@ const uint64_t *current_tick = &current_tick_data;
static void timer_callback(struct regs_t regs)
{
+ (void) regs;
++current_tick_data;
}
diff --git a/libc/stdio.c b/libc/stdio.c
index 17c5a2f..92fba27 100644
--- a/libc/stdio.c
+++ b/libc/stdio.c
@@ -1,6 +1,7 @@
-#include "stdio.h"
#include "tty.h"
#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
int putchar(int ch)
{
@@ -51,6 +52,9 @@ int printf(const char *fmt, ...)
case 'x':
print_hex(va_arg(ap, unsigned));
break;
+ case 'd':
+ puts(itoa(va_arg(ap, unsigned), 10));
+ break;
default:
puts("printf: unknown format\n");
break;