aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-03-01 13:05:04 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-03-01 13:05:04 -0500
commit6e86a3abee2d9b2c03452cd62997c2152a3332aa (patch)
treeef868a5a58b59fb0fbc215a4dd4367d5fcb4125e
parentd532ad93a42ea95460765d4527b3fb1e4544c154 (diff)
downloadkappa-6e86a3abee2d9b2c03452cd62997c2152a3332aa.zip
kappa-6e86a3abee2d9b2c03452cd62997c2152a3332aa.tar.gz
kappa-6e86a3abee2d9b2c03452cd62997c2152a3332aa.tar.bz2
kappa-6e86a3abee2d9b2c03452cd62997c2152a3332aa.tar.xz
lots of stuff
-rw-r--r--boot/head.S2
-rw-r--r--drivers/gfx.c11
-rw-r--r--drivers/include/ps2kbd.h7
-rw-r--r--drivers/ps2kbd.c21
-rw-r--r--drivers/tty.c12
-rw-r--r--kernel/main.c16
-rw-r--r--kernel/paging.c4
-rw-r--r--libc/include/stdlib.h2
-rw-r--r--libc/stdlib.c14
9 files changed, 72 insertions, 17 deletions
diff --git a/boot/head.S b/boot/head.S
index 8e607e0..9118c20 100644
--- a/boot/head.S
+++ b/boot/head.S
@@ -16,7 +16,7 @@ multiboot_header:
.long 0
.long 0
.long 0
- .long 0 # 1=text mode
+ .long 0 # 1=text mode, 0=graphics mode
.long 0 # screen width (don't care)
.long 0 # screen height (don't care)
.long 32 # screen BPP: MUST be 32
diff --git a/drivers/gfx.c b/drivers/gfx.c
index 3417fda..2f4864b 100644
--- a/drivers/gfx.c
+++ b/drivers/gfx.c
@@ -6,6 +6,7 @@
#include "gfx_font.h"
#include "log.h"
#include "multiboot.h"
+#include "paging.h"
#include "panic.h"
#include "gfx.h"
@@ -178,16 +179,8 @@ void gfx_putchar(int ch)
else if(ch == '\b')
{
int temp_x = cursor_x - FONT_WIDTH;
- if(temp_x < 0)
- {
- cursor_x = 0;
- int temp_y = cursor_y - FONT_HEIGHT;
- cursor_y = (temp_y < 0) ? 0 : temp_y;
- }
- else
- {
+ if(temp_x >= 0)
cursor_x = temp_x;
- }
gfx_drawchar_bg(cursor_x, cursor_y, ' ');
}
}
diff --git a/drivers/include/ps2kbd.h b/drivers/include/ps2kbd.h
index bf4871d..9e353ee 100644
--- a/drivers/include/ps2kbd.h
+++ b/drivers/include/ps2kbd.h
@@ -47,6 +47,11 @@ struct ps2_specialkeys_t {
int f12 :1;
};
+struct ps2_keyevent {
+ const struct ps2_specialkeys_t *special_keys;
+ char ascii;
+};
+
/* returns which arrow keys are down */
uint8_t ps2kbd_button_get(void);
@@ -54,6 +59,8 @@ uint8_t ps2kbd_modifier_get(void);
void ps2kbd_set_leds(uint8_t status);
+void ps2kbd_set_handler(void (*h)(const struct ps2_keyevent*));
+
void ps2kbd_init(void);
#endif
diff --git a/drivers/ps2kbd.c b/drivers/ps2kbd.c
index 27faaf4..29d02dc 100644
--- a/drivers/ps2kbd.c
+++ b/drivers/ps2kbd.c
@@ -138,6 +138,8 @@ static void handle_extended_scancode(void)
//printf("Extended scancode: 0x%x\n", temp);
}
+void (*keyevent_handler)(const struct ps2_keyevent*);
+
static void key_handler(struct regs_t *regs)
{
(void) regs;
@@ -153,6 +155,7 @@ static void key_handler(struct regs_t *regs)
int type = ps2_set1_scancodes[scancode & 0x7F];
int release = (scancode & (1<<7)) >> 7;
+ char ascii = '\0';
switch(type)
{
case PRINTING_KEY:
@@ -163,9 +166,9 @@ static void key_handler(struct regs_t *regs)
if(special_keys.shift)
capitals = ~capitals;
if(capitals)
- putchar(ps2_set1_shift[scancode]);
+ ascii = ps2_set1_shift[scancode];
else
- putchar(ps2_set1_ascii[scancode]);
+ ascii = ps2_set1_ascii[scancode];
}
break;
}
@@ -174,7 +177,14 @@ static void key_handler(struct regs_t *regs)
break;
}
if(special_keys.bksp)
- putchar('\b');
+ ascii = '\b';
+ if(keyevent_handler)
+ {
+ struct ps2_keyevent ev;
+ ev.special_keys = &special_keys;
+ ev.ascii = ascii;
+ keyevent_handler(&ev);
+ }
}
static void ps2_set_scancode_set(uint8_t set)
@@ -191,6 +201,11 @@ static void keyboard_init(void)
memset(&special_keys, 0, sizeof(special_keys));
}
+void ps2kbd_set_handler(void (*handler)(const struct ps2_keyevent*))
+{
+ keyevent_handler = handler;
+}
+
void ps2kbd_init(void)
{
keyboard_init();
diff --git a/drivers/tty.c b/drivers/tty.c
index e39722b..a77071b 100644
--- a/drivers/tty.c
+++ b/drivers/tty.c
@@ -82,7 +82,7 @@ void tty_putchar_at(int ch, uint8_t col, int x, int y)
void tty_putchar(int ch)
{
- if(ch != '\n')
+ if(ch != '\n' && ch != '\b')
{
tty_putchar_at(ch, term_col, term_x, term_y);
if(++term_x == VGA_WIDTH)
@@ -95,7 +95,7 @@ void tty_putchar(int ch)
}
}
}
- else
+ else if(ch == '\n')
{
term_x = 0;
if(++term_y == VGA_HEIGHT)
@@ -104,6 +104,14 @@ void tty_putchar(int ch)
term_y = 0;
}
}
+ else if(ch == '\b')
+ {
+ int temp_x = term_x - 1;
+ if(temp_x >= 0)
+ term_x = temp_x;
+ tty_putchar_at(' ', term_col, term_x, term_y);
+ }
+
update_cursor();
}
diff --git a/kernel/main.c b/kernel/main.c
index cdab037..9311359 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -256,6 +256,20 @@ void run_gfx_benchmark(void)
printf("Resolution: %dx%dx%d\n", *gfx_width, *gfx_height, *gfx_bpp * 8);
}
+static void keyhandler(const struct ps2_keyevent *ev)
+{
+ if(ev->ascii)
+ {
+ if(ev->special_keys->ctrl)
+ {
+ putchar('^');
+ putchar(toupper(ev->ascii));
+ }
+ else
+ putchar(ev->ascii);
+ }
+}
+
void main(struct multiboot_info_t *hdr, uint32_t magic)
{
bool gfx_status = boot(hdr, magic);
@@ -263,6 +277,8 @@ void main(struct multiboot_info_t *hdr, uint32_t magic)
printf("Hello, world!\n");
gfx_set_foreground(GFX_WHITE);
+ ps2kbd_set_handler(keyhandler);
+
while(1)asm("hlt");
//char *ptr = 0xA00000;
diff --git a/kernel/paging.c b/kernel/paging.c
index c9c7e94..9d748ab 100644
--- a/kernel/paging.c
+++ b/kernel/paging.c
@@ -53,8 +53,8 @@ void paging_init(void)
kernel_directory[i] = PAGE_RW;
}
- /* identity map all 4GB */
- for(int i=0; i < 1024; ++i)
+ /* identity map all 4GB (and allocate all page tables) */
+ for(int i = 0; i < 1024; ++i)
kernel_directory[i] = (uint32_t)identity_map_table(i * 1024, PAGE_PRESENT | PAGE_RW) |
PAGE_PRESENT | PAGE_RW;
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 95c7915..f55f0f5 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -22,6 +22,8 @@ int abs(int);
void *malloc(size_t);
int snprintf(char*, int, const char*, ...);
void assert_fail(const char*, const char*, int);
+int toupper(int);
+int tolower(int);
#define assert(x) if(!(x))assert_fail(__func__, __FILE__, __LINE__);
diff --git a/libc/stdlib.c b/libc/stdlib.c
index 4301618..d1d357e 100644
--- a/libc/stdlib.c
+++ b/libc/stdlib.c
@@ -161,3 +161,17 @@ void assert_fail(const char *func, const char *file, int line)
printf("\nAssertion failed in function %s in file %s, line %d\n", func, file, line);
panic("assertion failed!\n");
}
+
+int toupper(int ch)
+{
+ if('a' <= ch && ch <= 'z')
+ return ch ^ (1<<5);
+ return ch;
+}
+
+int tolower(int ch)
+{
+ if('A' <= ch && ch <= 'Z')
+ return ch ^ (1<<5);
+ return ch;
+}