oh no
This commit is contained in:
parent
bb0bffbe56
commit
0d83b9d955
6
Makefile
6
Makefile
|
@ -5,14 +5,16 @@ STRIP = $(TARGET)-strip
|
|||
NASM = nasm
|
||||
QEMU = qemu-system-i386
|
||||
|
||||
CFLAGS += -std=gnu18 -ffreestanding -O2 -Wall -Wextra
|
||||
CFLAGS += -std=gnu18 -ffreestanding -O2 -Wall -Wextra -mgeneral-regs-only
|
||||
LDFLAGS += -ffreestanding -O2 -nostdlib -lgcc
|
||||
NASMFLAGS += -felf32
|
||||
|
||||
BIN = sysroot/boot/hhhos.bin
|
||||
ISO = build/HhhOS.iso
|
||||
|
||||
OBJS = build/boot.o build/kernel.o build/string.o build/terminal.o build/idt.o build/isr.o build/util.o build/keyboard.o
|
||||
OBJS = build/boot.o build/kernel.o build/string.o build/terminal.o build/idt.o \
|
||||
build/isr.o build/util.o build/keyboard.o build/pic.o
|
||||
|
||||
ARCHDIR = arch/$(ARCH)/
|
||||
|
||||
.PHONY: all run clean build
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <idt.h>
|
||||
#include <terminal.h>
|
||||
|
||||
idt_gate_t idt[IDT_ENTRIES];
|
||||
idt_register_t idt_reg;
|
||||
|
|
|
@ -1,162 +1,162 @@
|
|||
#include <isr.h>
|
||||
#include <terminal.h>
|
||||
|
||||
void isr0(void) {
|
||||
__attribute__((interrupt)) void isr0(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Division By Zero");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr1(void) {
|
||||
__attribute__((interrupt)) void isr1(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Debug");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr2(void) {
|
||||
__attribute__((interrupt)) void isr2(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Non Maskable Interrupt");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr3(void) {
|
||||
__attribute__((interrupt)) void isr3(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Breakpoint");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr4(void) {
|
||||
__attribute__((interrupt)) void isr4(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Into Detected Overflow");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr5(void) {
|
||||
__attribute__((interrupt)) void isr5(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Out of Bounds");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr6(void) {
|
||||
__attribute__((interrupt)) void isr6(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Invalid Opcode");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr7(void) {
|
||||
__attribute__((interrupt)) void isr7(struct interrupt_frame* frame) {
|
||||
terminal_writeline("No Coprocessor");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr8(void) {
|
||||
__attribute__((interrupt)) void isr8(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Double Fault");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr9(void) {
|
||||
__attribute__((interrupt)) void isr9(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Coprocessor Segment Overrun");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr10(void) {
|
||||
__attribute__((interrupt)) void isr10(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Bad TSS");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr11(void) {
|
||||
__attribute__((interrupt)) void isr11(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Segment Not Present");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr12(void) {
|
||||
__attribute__((interrupt)) void isr12(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Stack Fault");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr13(void) {
|
||||
__attribute__((interrupt)) void isr13(struct interrupt_frame* frame) {
|
||||
terminal_writeline("General Protection Fault");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr14(void) {
|
||||
__attribute__((interrupt)) void isr14(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Page Fault");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr15(void) {
|
||||
__attribute__((interrupt)) void isr15(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Unknown Interrupt");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr16(void) {
|
||||
__attribute__((interrupt)) void isr16(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Coprocessor Fault");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr17(void) {
|
||||
__attribute__((interrupt)) void isr17(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Alignment Check");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr18(void) {
|
||||
__attribute__((interrupt)) void isr18(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Machine Check");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr19(void) {
|
||||
__attribute__((interrupt)) void isr19(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr20(void) {
|
||||
__attribute__((interrupt)) void isr20(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr21(void) {
|
||||
__attribute__((interrupt)) void isr21(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr22(void) {
|
||||
__attribute__((interrupt)) void isr22(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr23(void) {
|
||||
__attribute__((interrupt)) void isr23(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr24(void) {
|
||||
__attribute__((interrupt)) void isr24(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr25(void) {
|
||||
__attribute__((interrupt)) void isr25(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr26(void) {
|
||||
__attribute__((interrupt)) void isr26(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr27(void) {
|
||||
__attribute__((interrupt)) void isr27(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr28(void) {
|
||||
__attribute__((interrupt)) void isr28(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr29(void) {
|
||||
__attribute__((interrupt)) void isr29(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr30(void) {
|
||||
__attribute__((interrupt)) void isr30(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
void isr31(void) {
|
||||
__attribute__((interrupt)) void isr31(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stddef.h>
|
||||
#include <isr.h>
|
||||
#include <keyboard.h>
|
||||
#include <pic.h>
|
||||
|
||||
/* Check if the compiler thinks you are targeting the wrong operating system. */
|
||||
#if defined(__linux__)
|
||||
|
@ -15,15 +16,10 @@
|
|||
|
||||
void kernel_main() {
|
||||
terminal_initialize();
|
||||
remap_pic(0x20, 0x28);
|
||||
keyboard_init();
|
||||
isr_install();
|
||||
|
||||
terminal_writeline("hello yes");
|
||||
terminal_writestring("> ");
|
||||
|
||||
while (true) {
|
||||
if (keycache[key_loc] == '\n') {
|
||||
terminal_writestring(keycache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +1,398 @@
|
|||
#include <keyboard.h>
|
||||
|
||||
uint8_t lastkey = 0;
|
||||
char *keycache = 0;
|
||||
char* keycache = 0;
|
||||
uint16_t key_loc = 0;
|
||||
uint8_t __kbd_enabled = 0;
|
||||
|
||||
enum KEYCODE {
|
||||
NULL_KEY = 0,
|
||||
Q_PRESSED = 0x10,
|
||||
Q_RELEASED = 0x90,
|
||||
W_PRESSED = 0x11,
|
||||
W_RELEASED = 0x91,
|
||||
E_PRESSED = 0x12,
|
||||
E_RELEASED = 0x92,
|
||||
R_PRESSED = 0x13,
|
||||
R_RELEASED = 0x93,
|
||||
T_PRESSED = 0x14,
|
||||
T_RELEASED = 0x94,
|
||||
Z_PRESSED = 0x15,
|
||||
Z_RELEASED = 0x95,
|
||||
U_PRESSED = 0x16,
|
||||
U_RELEASED = 0x96,
|
||||
I_PRESSED = 0x17,
|
||||
I_RELEASED = 0x97,
|
||||
O_PRESSED = 0x18,
|
||||
O_RELEASED = 0x98,
|
||||
P_PRESSED = 0x19,
|
||||
P_RELEASED = 0x99,
|
||||
A_PRESSED = 0x1E,
|
||||
A_RELEASED = 0x9E,
|
||||
S_PRESSED = 0x1F,
|
||||
S_RELEASED = 0x9F,
|
||||
D_PRESSED = 0x20,
|
||||
D_RELEASED = 0xA0,
|
||||
F_PRESSED = 0x21,
|
||||
F_RELEASED = 0xA1,
|
||||
G_PRESSED = 0x22,
|
||||
G_RELEASED = 0xA2,
|
||||
H_PRESSED = 0x23,
|
||||
H_RELEASED = 0xA3,
|
||||
J_PRESSED = 0x24,
|
||||
J_RELEASED = 0xA4,
|
||||
K_PRESSED = 0x25,
|
||||
K_RELEASED = 0xA5,
|
||||
L_PRESSED = 0x26,
|
||||
L_RELEASED = 0xA6,
|
||||
Y_PRESSED = 0x2C,
|
||||
Y_RELEASED = 0xAC,
|
||||
X_PRESSED = 0x2D,
|
||||
X_RELEASED = 0xAD,
|
||||
C_PRESSED = 0x2E,
|
||||
C_RELEASED = 0xAE,
|
||||
V_PRESSED = 0x2F,
|
||||
V_RELEASED = 0xAF,
|
||||
B_PRESSED = 0x30,
|
||||
B_RELEASED = 0xB0,
|
||||
N_PRESSED = 0x31,
|
||||
N_RELEASED = 0xB1,
|
||||
M_PRESSED = 0x32,
|
||||
M_RELEASED = 0xB2,
|
||||
|
||||
ZERO_PRESSED = 0x29,
|
||||
ONE_PRESSED = 0x2,
|
||||
NINE_PRESSED = 0xA,
|
||||
// Alphanumeric keys ////////////////
|
||||
|
||||
POINT_PRESSED = 0x34,
|
||||
POINT_RELEASED = 0xB4,
|
||||
KEY_SPACE = ' ',
|
||||
KEY_0 = '0',
|
||||
KEY_1 = '1',
|
||||
KEY_2 = '2',
|
||||
KEY_3 = '3',
|
||||
KEY_4 = '4',
|
||||
KEY_5 = '5',
|
||||
KEY_6 = '6',
|
||||
KEY_7 = '7',
|
||||
KEY_8 = '8',
|
||||
KEY_9 = '9',
|
||||
|
||||
SLASH_RELEASED = 0xB5,
|
||||
KEY_A = 'a',
|
||||
KEY_B = 'b',
|
||||
KEY_C = 'c',
|
||||
KEY_D = 'd',
|
||||
KEY_E = 'e',
|
||||
KEY_F = 'f',
|
||||
KEY_G = 'g',
|
||||
KEY_H = 'h',
|
||||
KEY_I = 'i',
|
||||
KEY_J = 'j',
|
||||
KEY_K = 'k',
|
||||
KEY_L = 'l',
|
||||
KEY_M = 'm',
|
||||
KEY_N = 'n',
|
||||
KEY_O = 'o',
|
||||
KEY_P = 'p',
|
||||
KEY_Q = 'q',
|
||||
KEY_R = 'r',
|
||||
KEY_S = 's',
|
||||
KEY_T = 't',
|
||||
KEY_U = 'u',
|
||||
KEY_V = 'v',
|
||||
KEY_W = 'w',
|
||||
KEY_X = 'x',
|
||||
KEY_Y = 'y',
|
||||
KEY_Z = 'z',
|
||||
|
||||
BACKSPACE_PRESSED = 0xE,
|
||||
BACKSPACE_RELEASED = 0x8E,
|
||||
SPACE_PRESSED = 0x39,
|
||||
SPACE_RELEASED = 0xB9,
|
||||
ENTER_PRESSED = 0x1C,
|
||||
ENTER_RELEASED = 0x9C
|
||||
KEY_RETURN = '\n',
|
||||
KEY_ESCAPE = 0x1b,
|
||||
KEY_BACKSPACE = 0x7f,
|
||||
|
||||
// Arrow keys ////////////////////////
|
||||
|
||||
KEY_UP = 0x1100,
|
||||
KEY_DOWN = 0x1101,
|
||||
KEY_LEFT = 0x1102,
|
||||
KEY_RIGHT = 0x1103,
|
||||
|
||||
// Function keys /////////////////////
|
||||
|
||||
KEY_F1 = 0x1201,
|
||||
KEY_F2 = 0x1202,
|
||||
KEY_F3 = 0x1203,
|
||||
KEY_F4 = 0x1204,
|
||||
KEY_F5 = 0x1205,
|
||||
KEY_F6 = 0x1206,
|
||||
KEY_F7 = 0x1207,
|
||||
KEY_F8 = 0x1208,
|
||||
KEY_F9 = 0x1209,
|
||||
KEY_F10 = 0x120a,
|
||||
KEY_F11 = 0x120b,
|
||||
KEY_F12 = 0x120b,
|
||||
KEY_F13 = 0x120c,
|
||||
KEY_F14 = 0x120d,
|
||||
KEY_F15 = 0x120e,
|
||||
|
||||
KEY_DOT = '.',
|
||||
KEY_COMMA = ',',
|
||||
KEY_COLON = ':',
|
||||
KEY_SEMICOLON = ';',
|
||||
KEY_SLASH = '/',
|
||||
KEY_BACKSLASH = '\\',
|
||||
KEY_PLUS = '+',
|
||||
KEY_MINUS = '-',
|
||||
KEY_ASTERISK = '*',
|
||||
KEY_EXCLAMATION = '!',
|
||||
KEY_QUESTION = '?',
|
||||
KEY_QUOTEDOUBLE = '\"',
|
||||
KEY_QUOTE = '\'',
|
||||
KEY_EQUAL = '=',
|
||||
KEY_HASH = '#',
|
||||
KEY_PERCENT = '%',
|
||||
KEY_AMPERSAND = '&',
|
||||
KEY_UNDERSCORE = '_',
|
||||
KEY_LEFTPARENTHESIS = '(',
|
||||
KEY_RIGHTPARENTHESIS = ')',
|
||||
KEY_LEFTBRACKET = '[',
|
||||
KEY_RIGHTBRACKET = ']',
|
||||
KEY_LEFTCURL = '{',
|
||||
KEY_RIGHTCURL = '}',
|
||||
KEY_DOLLAR = '$',
|
||||
KEY_POUND = '$',
|
||||
KEY_EURO = '$',
|
||||
KEY_LESS = '<',
|
||||
KEY_GREATER = '>',
|
||||
KEY_BAR = '|',
|
||||
KEY_GRAVE = '`',
|
||||
KEY_TILDE = '~',
|
||||
KEY_AT = '@',
|
||||
KEY_CARRET = '^',
|
||||
|
||||
// Numeric keypad //////////////////////
|
||||
|
||||
KEY_KP_0 = '0',
|
||||
KEY_KP_1 = '1',
|
||||
KEY_KP_2 = '2',
|
||||
KEY_KP_3 = '3',
|
||||
KEY_KP_4 = '4',
|
||||
KEY_KP_5 = '5',
|
||||
KEY_KP_6 = '6',
|
||||
KEY_KP_7 = '7',
|
||||
KEY_KP_8 = '8',
|
||||
KEY_KP_9 = '9',
|
||||
KEY_KP_PLUS = '+',
|
||||
KEY_KP_MINUS = '-',
|
||||
KEY_KP_DECIMAL = '.',
|
||||
KEY_KP_DIVIDE = '/',
|
||||
KEY_KP_ASTERISK = '*',
|
||||
KEY_KP_NUMLOCK = 0x300f,
|
||||
KEY_KP_ENTER = 0x3010,
|
||||
|
||||
KEY_TAB = 0x4000,
|
||||
KEY_CAPSLOCK = 0x4001,
|
||||
|
||||
// Modify keys ////////////////////////////
|
||||
|
||||
KEY_LSHIFT = 0x4002,
|
||||
KEY_LCTRL = 0x4003,
|
||||
KEY_LALT = 0x4004,
|
||||
KEY_LWIN = 0x4005,
|
||||
KEY_RSHIFT = 0x4006,
|
||||
KEY_RCTRL = 0x4007,
|
||||
KEY_RALT = 0x4008,
|
||||
KEY_RWIN = 0x4009,
|
||||
|
||||
KEY_INSERT = 0x400a,
|
||||
KEY_DELETE = 0x400b,
|
||||
KEY_HOME = 0x400c,
|
||||
KEY_END = 0x400d,
|
||||
KEY_PAGEUP = 0x400e,
|
||||
KEY_PAGEDOWN = 0x400f,
|
||||
KEY_SCROLLLOCK = 0x4010,
|
||||
KEY_PAUSE = 0x4011,
|
||||
|
||||
KEY_UNKNOWN,
|
||||
KEY_NUMKEYCODES
|
||||
};
|
||||
|
||||
void keyboard_irq(void) {
|
||||
asm volatile("pusha");
|
||||
char key = keyboard_to_ascii(inb(0x60));
|
||||
static int scancode_std [] = {
|
||||
// key scancode
|
||||
KEY_UNKNOWN, //0
|
||||
KEY_ESCAPE, //1
|
||||
KEY_1, //2
|
||||
KEY_2, //3
|
||||
KEY_3, //4
|
||||
KEY_4, //5
|
||||
KEY_5, //6
|
||||
KEY_6, //7
|
||||
KEY_7, //8
|
||||
KEY_8, //9
|
||||
KEY_9, //0xa
|
||||
KEY_0, //0xb
|
||||
KEY_MINUS, //0xc
|
||||
KEY_EQUAL, //0xd
|
||||
KEY_BACKSPACE, //0xe
|
||||
KEY_TAB, //0xf
|
||||
KEY_Q, //0x10
|
||||
KEY_W, //0x11
|
||||
KEY_E, //0x12
|
||||
KEY_R, //0x13
|
||||
KEY_T, //0x14
|
||||
KEY_Y, //0x15
|
||||
KEY_U, //0x16
|
||||
KEY_I, //0x17
|
||||
KEY_O, //0x18
|
||||
KEY_P, //0x19
|
||||
KEY_LEFTBRACKET,//0x1a
|
||||
KEY_RIGHTBRACKET,//0x1b
|
||||
KEY_RETURN, //0x1c
|
||||
KEY_LCTRL, //0x1d
|
||||
KEY_A, //0x1e
|
||||
KEY_S, //0x1f
|
||||
KEY_D, //0x20
|
||||
KEY_F, //0x21
|
||||
KEY_G, //0x22
|
||||
KEY_H, //0x23
|
||||
KEY_J, //0x24
|
||||
KEY_K, //0x25
|
||||
KEY_L, //0x26
|
||||
KEY_SEMICOLON, //0x27
|
||||
KEY_QUOTE, //0x28
|
||||
KEY_GRAVE, //0x29
|
||||
KEY_LSHIFT, //0x2a
|
||||
KEY_BACKSLASH, //0x2b
|
||||
KEY_Z, //0x2c
|
||||
KEY_X, //0x2d
|
||||
KEY_C, //0x2e
|
||||
KEY_V, //0x2f
|
||||
KEY_B, //0x30
|
||||
KEY_N, //0x31
|
||||
KEY_M, //0x32
|
||||
KEY_COMMA, //0x33
|
||||
KEY_DOT, //0x34
|
||||
KEY_SLASH, //0x35
|
||||
KEY_RSHIFT, //0x36
|
||||
KEY_KP_ASTERISK,//0x37
|
||||
KEY_RALT, //0x38
|
||||
KEY_SPACE, //0x39
|
||||
KEY_CAPSLOCK, //0x3a
|
||||
KEY_F1, //0x3b
|
||||
KEY_F2, //0x3c
|
||||
KEY_F3, //0x3d
|
||||
KEY_F4, //0x3e
|
||||
KEY_F5, //0x3f
|
||||
KEY_F6, //0x40
|
||||
KEY_F7, //0x41
|
||||
KEY_F8, //0x42
|
||||
KEY_F9, //0x43
|
||||
KEY_F10, //0x44
|
||||
KEY_KP_NUMLOCK, //0x45
|
||||
KEY_SCROLLLOCK, //0x46
|
||||
KEY_HOME, //0x47
|
||||
KEY_KP_8, //0x48 //keypad up arrow
|
||||
KEY_PAGEUP, //0x49
|
||||
KEY_KP_2, //0x50 //keypad down arrow
|
||||
KEY_KP_3, //0x51 //keypad page down
|
||||
KEY_KP_0, //0x52 //keypad insert key
|
||||
KEY_KP_DECIMAL, //0x53 //keypad delete key
|
||||
KEY_UNKNOWN, //0x54
|
||||
KEY_UNKNOWN, //0x55
|
||||
KEY_UNKNOWN, //0x56
|
||||
KEY_F11, //0x57
|
||||
KEY_F12 //0x58
|
||||
};
|
||||
|
||||
static uint8_t _shift = 0;
|
||||
static uint8_t _alt = 0;
|
||||
static uint8_t _ctrl = 0;
|
||||
static uint8_t _capslock = 0;
|
||||
|
||||
uint8_t keyboard_to_ascii(uint8_t key) {
|
||||
if(!key) return 0;
|
||||
// if shift key is down or caps lock is on, make the key uppercase
|
||||
if (_shift || _capslock)
|
||||
if (key >= 'a' && key <= 'z')
|
||||
key -= 32;
|
||||
|
||||
if (_shift && !_capslock) {
|
||||
if (key >= '0' && key <= '9') {
|
||||
switch (key) {
|
||||
case '0':
|
||||
key = KEY_RIGHTPARENTHESIS;
|
||||
break;
|
||||
case '1':
|
||||
key = KEY_EXCLAMATION;
|
||||
break;
|
||||
case '2':
|
||||
key = KEY_AT;
|
||||
break;
|
||||
case '3':
|
||||
key = KEY_HASH;
|
||||
break;
|
||||
case '4':
|
||||
key = KEY_DOLLAR;
|
||||
break;
|
||||
case '5':
|
||||
key = KEY_PERCENT;
|
||||
break;
|
||||
case '6':
|
||||
key = KEY_CARRET;
|
||||
break;
|
||||
case '7':
|
||||
key = KEY_AMPERSAND;
|
||||
break;
|
||||
case '8':
|
||||
key = KEY_ASTERISK;
|
||||
break;
|
||||
case '9':
|
||||
key = KEY_LEFTPARENTHESIS;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (key) {
|
||||
case KEY_COMMA:
|
||||
key = KEY_LESS;
|
||||
break;
|
||||
case KEY_DOT:
|
||||
key = KEY_GREATER;
|
||||
break;
|
||||
case KEY_SLASH:
|
||||
key = KEY_QUESTION;
|
||||
break;
|
||||
case KEY_SEMICOLON:
|
||||
key = KEY_COLON;
|
||||
break;
|
||||
case KEY_QUOTE:
|
||||
key = KEY_QUOTEDOUBLE;
|
||||
break;
|
||||
case KEY_LEFTBRACKET:
|
||||
key = KEY_LEFTCURL;
|
||||
break;
|
||||
case KEY_RIGHTBRACKET:
|
||||
key = KEY_RIGHTCURL;
|
||||
break;
|
||||
case KEY_GRAVE:
|
||||
key = KEY_TILDE;
|
||||
break;
|
||||
case KEY_MINUS:
|
||||
key = KEY_UNDERSCORE;
|
||||
break;
|
||||
case KEY_PLUS:
|
||||
key = KEY_EQUAL;
|
||||
break;
|
||||
case KEY_BACKSLASH:
|
||||
key = KEY_BAR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (_ctrl && key >= 'a' && key <= 'z')
|
||||
// return __CONTROL(key - 32);
|
||||
|
||||
// return the key
|
||||
return key;
|
||||
}
|
||||
|
||||
uint8_t _extended = 0;
|
||||
uint8_t parse_keycode(uint8_t code) {
|
||||
if (code == 0xE0 || code == 0xE1) {
|
||||
_extended = 1;
|
||||
} else {
|
||||
_extended = 0;
|
||||
if (code & 0x80) {
|
||||
code -= 0x80;
|
||||
int key = scancode_std[code];
|
||||
switch (key) {
|
||||
case KEY_LCTRL:
|
||||
case KEY_RCTRL:
|
||||
_ctrl = 0;
|
||||
break;
|
||||
case KEY_LSHIFT:
|
||||
case KEY_RSHIFT:
|
||||
_shift = 0;
|
||||
break;
|
||||
case KEY_LALT:
|
||||
case KEY_RALT:
|
||||
_alt = 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
int key = scancode_std[code];
|
||||
switch (key) {
|
||||
case KEY_LCTRL:
|
||||
case KEY_RCTRL:
|
||||
_ctrl = 1;
|
||||
return 0;
|
||||
case KEY_LSHIFT:
|
||||
case KEY_RSHIFT:
|
||||
_shift = 1;
|
||||
return 0;
|
||||
case KEY_LALT:
|
||||
case KEY_RALT:
|
||||
_alt = 1;
|
||||
return 0;
|
||||
case KEY_CAPSLOCK:
|
||||
_capslock = (_capslock) ? 0 : 1;
|
||||
return 0;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void keyboard_irq(struct interrupt_frame* frame) {
|
||||
terminal_writeline("called");
|
||||
char key = keyboard_to_ascii(inportb(0x60));
|
||||
keycache[key_loc++] = key;
|
||||
terminal_putchar(key);
|
||||
asm volatile("popa");
|
||||
asm volatile("iret");
|
||||
send_eoi(33);
|
||||
}
|
||||
|
||||
void keyboard_init(void) {
|
||||
|
@ -100,30 +409,6 @@ uint8_t keyboard_enabled(void) {
|
|||
|
||||
void keyboard_read_key(void) {
|
||||
lastkey = 0;
|
||||
if (inb(0x64) & 1)
|
||||
lastkey = inb(0x60);
|
||||
}
|
||||
|
||||
static char* _qwertzuiop = "qwertzuiop"; // 0x10-0x1c
|
||||
static char* _asdfghjkl = "asdfghjkl";
|
||||
static char* _yxcvbnm = "yxcvbnm";
|
||||
static char* _num = "123456789";
|
||||
|
||||
uint8_t keyboard_to_ascii(uint8_t key) {
|
||||
if (key == 0x1C) return '\n';
|
||||
if (key == 0x39) return ' ';
|
||||
if (key == 0xE) return '\r';
|
||||
if (key == POINT_RELEASED) return '.';
|
||||
if (key == SLASH_RELEASED) return '/';
|
||||
if (key == ZERO_PRESSED) return '0';
|
||||
if (key >= ONE_PRESSED && key <= NINE_PRESSED)
|
||||
return _num[key - ONE_PRESSED];
|
||||
if (key >= 0x10 && key <= 0x1C) {
|
||||
return _qwertzuiop[key - 0x10];
|
||||
} else if(key >= 0x1E && key <= 0x26) {
|
||||
return _asdfghjkl[key - 0x1E];
|
||||
} else if(key >= 0x2C && key <= 0x32) {
|
||||
return _yxcvbnm[key - 0x2C];
|
||||
}
|
||||
return 0;
|
||||
if (inportb(0x64) & 1)
|
||||
lastkey = inportb(0x60);
|
||||
}
|
||||
|
|
42
arch/i386/pic.c
Normal file
42
arch/i386/pic.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <pic.h>
|
||||
|
||||
/*
|
||||
arguments:
|
||||
offset1 - vector offset for master PIC
|
||||
vectors on the master become offset1..offset1+7
|
||||
offset2 - same for slave PIC: offset2..offset2+7
|
||||
*/
|
||||
void remap_pic(int offset1, int offset2) {
|
||||
unsigned char a1, a2;
|
||||
|
||||
a1 = inportb(PIC1_DATA); // save masks
|
||||
a2 = inportb(PIC2_DATA);
|
||||
|
||||
outportb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
||||
io_wait();
|
||||
outportb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, offset1); // ICW2: Master PIC vector offset
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, offset2); // ICW2: Slave PIC vector offset
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||
io_wait();
|
||||
|
||||
outportb(PIC1_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
|
||||
outportb(PIC1_DATA, a1); // restore saved masks.
|
||||
outportb(PIC2_DATA, a2);
|
||||
}
|
||||
|
||||
void send_eoi(uint8_t irq) {
|
||||
if (irq >= 8)
|
||||
outportb(PIC2_COMMAND, PIC_EOI);
|
||||
|
||||
outportb(PIC1_COMMAND, PIC_EOI);
|
||||
}
|
|
@ -44,10 +44,10 @@ void terminal_clearlines(size_t from, size_t to) {
|
|||
|
||||
void terminal_updatecursor(void) {
|
||||
size_t temp = terminal_row * VGA_WIDTH + terminal_column;
|
||||
outb(0x3D4, 14);
|
||||
outb(0x3D5, temp >> 8);
|
||||
outb(0x3D4, 15);
|
||||
outb(0x3D5, temp);
|
||||
outportb(0x3D4, 14);
|
||||
outportb(0x3D5, temp >> 8);
|
||||
outportb(0x3D4, 15);
|
||||
outportb(0x3D5, temp);
|
||||
}
|
||||
|
||||
void terminal_scrollup(void) {
|
||||
|
@ -76,16 +76,16 @@ void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
|
|||
|
||||
void terminal_putchar(char c) {
|
||||
switch (c) {
|
||||
case '\r':
|
||||
terminal_column = 0;
|
||||
break;
|
||||
case '\n':
|
||||
terminal_column = 0;
|
||||
terminal_row++;
|
||||
break;
|
||||
default:
|
||||
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
|
||||
terminal_column++;
|
||||
case '\r':
|
||||
terminal_column = 0;
|
||||
break;
|
||||
case '\n':
|
||||
terminal_column = 0;
|
||||
terminal_row++;
|
||||
break;
|
||||
default:
|
||||
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
|
||||
terminal_column++;
|
||||
}
|
||||
|
||||
if (terminal_column >= VGA_WIDTH) {
|
||||
|
|
|
@ -23,6 +23,14 @@ typedef struct {
|
|||
uint32_t base;
|
||||
} __attribute__((packed)) idt_register_t;
|
||||
|
||||
struct interrupt_frame {
|
||||
size_t ip;
|
||||
size_t cs;
|
||||
size_t flags;
|
||||
size_t sp;
|
||||
size_t ss;
|
||||
};
|
||||
|
||||
#define IDT_ENTRIES 256
|
||||
extern idt_gate_t idt[IDT_ENTRIES];
|
||||
extern idt_register_t idt_reg;
|
||||
|
|
|
@ -8,31 +8,31 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void outb(uint16_t const port, uint8_t const val) {
|
||||
static inline void outportb(uint16_t const port, uint8_t const val) {
|
||||
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
static inline void outw(uint16_t const port, uint16_t const val) {
|
||||
static inline void outportw(uint16_t const port, uint16_t const val) {
|
||||
asm volatile ( "outw %0, %1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
static inline void outl(uint16_t const port, uint32_t const val) {
|
||||
static inline void outportl(uint16_t const port, uint32_t const val) {
|
||||
asm volatile ( "outl %0, %1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
static inline uint8_t inb(uint16_t const port) {
|
||||
static inline uint8_t inportb(uint16_t const port) {
|
||||
uint8_t ret;
|
||||
asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint16_t inw(uint16_t const port) {
|
||||
static inline uint16_t inportw(uint16_t const port) {
|
||||
uint16_t ret;
|
||||
asm volatile ( "inw %1, %0" : "=a"(ret) : "Nd"(port) );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint32_t inl(uint16_t const port) {
|
||||
static inline uint32_t inportl(uint16_t const port) {
|
||||
uint32_t ret;
|
||||
asm volatile ( "inl %1, %0" : "=a"(ret) : "Nd"(port) );
|
||||
return ret;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <terminal.h>
|
||||
#include <util.h>
|
||||
#include <string.h>
|
||||
#include <idt.h>
|
||||
#include <isr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
38
include/pic.h
Normal file
38
include/pic.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef _PIC_H
|
||||
#define _PIC_H 1
|
||||
|
||||
#include <inline.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PIC1 0x20 /* IO base address for master PIC */
|
||||
#define PIC2 0xA0 /* IO base address for slave PIC */
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1+1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2+1)
|
||||
|
||||
#define PIC_EOI 0x20 /* End-of-interrupt command code */
|
||||
|
||||
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
|
||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||
|
||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
void remap_pic(int offset1, int offset2);
|
||||
void send_eoi(uint8_t irq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ISR_H */
|
Loading…
Reference in a new issue