Separate keyboard from the kernel

This commit is contained in:
Baptiste Wicht 2013-10-27 16:41:52 +01:00
parent 1732f1fa98
commit 27b13b3762
5 changed files with 94 additions and 62 deletions

View File

@ -1,20 +1,26 @@
default: thor.flp
KERNEL_SRC=$(wildcard micro_kernel/*.asm)
KERNEL_UTILS_SRC=$(wildcard micro_kernel/utils/*.asm)
bootloader.bin: bootloader/bootloader.asm
nasm -w+all -f bin -o bootloader.bin bootloader/bootloader.asm
micro_kernel.bin: $(KERNEL_SRC) $(KERNEL_UTILS_SRC)
MICRO_KERNEL_SRC=$(wildcard micro_kernel/*.asm)
MICRO_KERNEL_UTILS_SRC=$(wildcard micro_kernel/utils/*.asm)
micro_kernel.bin: $(MICRO_KERNEL_SRC) $(MICRO_KERNEL_UTILS_SRC)
nasm -w+all -f bin -o micro_kernel.bin micro_kernel/micro_kernel.asm
nasm -D DEBUG -g -w+all -f elf64 -o micro_kernel.g micro_kernel/micro_kernel.asm
kernel.o: kernel/src/kernel.cpp
g++ -masm=intel -Ikernel/include/ -O2 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding -c kernel/src/kernel.cpp -o kernel.o
KERNEL_FLAGS=-masm=intel -Ikernel/include/ -O2 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding
KERNEL_LINK_FLAGS=-std=c++11 -T linker.ld -ffreestanding -O2 -nostdlib
kernel.bin: kernel.o
g++ -std=c++11 -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o
kernel.o: kernel/src/kernel.cpp
g++ $(KERNEL_FLAGS) -c kernel/src/kernel.cpp -o kernel.o
keyboard.o: kernel/src/keyboard.cpp
g++ $(KERNEL_FLAGS) -c kernel/src/keyboard.cpp -o keyboard.o
kernel.bin: kernel.o keyboard.o
g++ $(KERNEL_LINK_FLAGS) -o kernel.bin.o kernel.o keyboard.o
objcopy -R .note -R .comment -S -O binary kernel.bin.o kernel.bin
filler.bin: kernel.bin

View File

@ -0,0 +1,8 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include "types.hpp"
char key_to_ascii(uint8_t key);
#endif

7
kernel/include/types.hpp Normal file
View File

@ -0,0 +1,7 @@
#ifndef TYPES_H
#define TYPES_H
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
#endif

View File

@ -1,8 +1,8 @@
#include "addresses.hpp"
#include <cstddef>
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
#include "types.hpp"
#include "addresses.hpp"
#include "keyboard.hpp"
void k_print(char key);
void k_print(const char* string);
@ -27,49 +27,21 @@ void register_irq_handler(void (*handler)()){
);
}
void keyboard_handler();
extern "C" {
void __attribute__ ((section ("main_section"))) kernel_main(){
k_print("thor> ");
register_irq_handler<1>(keyboard_handler);
return;
}
}
std::size_t current_input_length = 0;
char current_input[50];
char qwertz[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'z', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'y', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
void keyboard_handler(){
uint8_t key = in_byte(0x60);
@ -81,7 +53,7 @@ void keyboard_handler(){
} else if(key == 0x0E){
//TODO Backspace
} else {
auto qwertz_key = qwertz[key];
auto qwertz_key = key_to_ascii(key);
current_input[current_input_length++] = qwertz_key;
k_print(qwertz_key);
@ -89,16 +61,6 @@ void keyboard_handler(){
}
}
extern "C" {
void __attribute__ ((section ("main_section"))) kernel_main(){
k_print("thor> ");
register_irq_handler<1>(keyboard_handler);
return;
}
}
long current_line = 0;
long current_column = 0;

49
kernel/src/keyboard.cpp Normal file
View File

@ -0,0 +1,49 @@
#include "keyboard.hpp"
namespace {
char qwertz[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'z', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'y', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
}
char key_to_ascii(uint8_t key){
return qwertz[key];
}