diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 791330b..e20e132 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -10,89 +9,3 @@ MODIFIER_RIGHT_CONTROL = 0x01 << 3 }; -const char modifierScancodes[] = {0x2A, 0x36, 0x1D, 0x9D}; - -unsigned char keycodes[128] = { - 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', - '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', - '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', - ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', - '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char *altKeycodes[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, "\e[H", "\e[A", 0, 0, "\e[D", 0, "\e[C", 0, 0, - "\e[B", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char capitalKeycodes[128] = { - 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', - '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', - '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', - ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', - '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -uint8_t modifiers = 0; - -uint8_t getScancode() { - int_fast16_t scancode = -1; - for (uint16_t i = 0; i < 1000; i++) { - if ((ioIn(0x64, 1) & 1) == 0) { - continue; - } - scancode = ioIn(0x60, 1); - break; - } - return scancode; -} - -extern uint32_t ioManager, keyCallback; - -void onKey() { - uint8_t scancode = getScancode(); - if (scancode == 0xE0) { - scancode = getScancode(); - if (scancode & 0x80) { - return; - } - request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); - return; - } - if (scancode & 0x80) { - scancode = scancode & 0x7F; - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers & (0xFF ^ 0x01 << i); - } - } - return; - } - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers | 0x01 << i; - return; - } - } - char data = 0; - if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = capitalKeycodes[scancode]; - } else { - data = keycodes[scancode]; - } - request(ioManager, keyCallback, data, 0); -} - -int32_t main() { - uint32_t service = getService("pic"); - uint32_t event = getEvent(service, "irq1"); - subscribeEvent(service, event, onKey); - printf("keyboard handler installed\n"); -} diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 791330b..e20e132 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -10,89 +9,3 @@ MODIFIER_RIGHT_CONTROL = 0x01 << 3 }; -const char modifierScancodes[] = {0x2A, 0x36, 0x1D, 0x9D}; - -unsigned char keycodes[128] = { - 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', - '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', - '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', - ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', - '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char *altKeycodes[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, "\e[H", "\e[A", 0, 0, "\e[D", 0, "\e[C", 0, 0, - "\e[B", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char capitalKeycodes[128] = { - 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', - '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', - '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', - ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', - '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -uint8_t modifiers = 0; - -uint8_t getScancode() { - int_fast16_t scancode = -1; - for (uint16_t i = 0; i < 1000; i++) { - if ((ioIn(0x64, 1) & 1) == 0) { - continue; - } - scancode = ioIn(0x60, 1); - break; - } - return scancode; -} - -extern uint32_t ioManager, keyCallback; - -void onKey() { - uint8_t scancode = getScancode(); - if (scancode == 0xE0) { - scancode = getScancode(); - if (scancode & 0x80) { - return; - } - request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); - return; - } - if (scancode & 0x80) { - scancode = scancode & 0x7F; - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers & (0xFF ^ 0x01 << i); - } - } - return; - } - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers | 0x01 << i; - return; - } - } - char data = 0; - if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = capitalKeycodes[scancode]; - } else { - data = keycodes[scancode]; - } - request(ioManager, keyCallback, data, 0); -} - -int32_t main() { - uint32_t service = getService("pic"); - uint32_t event = getEvent(service, "irq1"); - subscribeEvent(service, event, onKey); - printf("keyboard handler installed\n"); -} diff --git a/src/userland/ps2/Makefile b/src/userland/ps2/Makefile new file mode 100644 index 0000000..a5855c4 --- /dev/null +++ b/src/userland/ps2/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = ps2 + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 791330b..e20e132 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, @@ -10,89 +9,3 @@ MODIFIER_RIGHT_CONTROL = 0x01 << 3 }; -const char modifierScancodes[] = {0x2A, 0x36, 0x1D, 0x9D}; - -unsigned char keycodes[128] = { - 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', - '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', - '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', - ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', - '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char *altKeycodes[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, "\e[H", "\e[A", 0, 0, "\e[D", 0, "\e[C", 0, 0, - "\e[B", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -const char capitalKeycodes[128] = { - 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', - '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', - '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', - ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', - '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, - '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -uint8_t modifiers = 0; - -uint8_t getScancode() { - int_fast16_t scancode = -1; - for (uint16_t i = 0; i < 1000; i++) { - if ((ioIn(0x64, 1) & 1) == 0) { - continue; - } - scancode = ioIn(0x60, 1); - break; - } - return scancode; -} - -extern uint32_t ioManager, keyCallback; - -void onKey() { - uint8_t scancode = getScancode(); - if (scancode == 0xE0) { - scancode = getScancode(); - if (scancode & 0x80) { - return; - } - request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); - return; - } - if (scancode & 0x80) { - scancode = scancode & 0x7F; - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers & (0xFF ^ 0x01 << i); - } - } - return; - } - for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { - if (scancode == modifierScancodes[i]) { - modifiers = modifiers | 0x01 << i; - return; - } - } - char data = 0; - if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - data = capitalKeycodes[scancode]; - } else { - data = keycodes[scancode]; - } - request(ioManager, keyCallback, data, 0); -} - -int32_t main() { - uint32_t service = getService("pic"); - uint32_t event = getEvent(service, "irq1"); - subscribeEvent(service, event, onKey); - printf("keyboard handler installed\n"); -} diff --git a/src/userland/ps2/Makefile b/src/userland/ps2/Makefile new file mode 100644 index 0000000..a5855c4 --- /dev/null +++ b/src/userland/ps2/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = ps2 + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c new file mode 100644 index 0000000..05e0007 --- /dev/null +++ b/src/userland/ps2/main.c @@ -0,0 +1,87 @@ +#define ALLOC_MAIN + +#include + +const char modifierScancodes[] = {0x2A, 0x36, 0x1D, 0x9D}; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', + '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', + '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', + ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', + '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, + '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +const char *altKeycodes[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, "\e[H", "\e[A", 0, 0, "\e[D", 0, "\e[C", 0, 0, + "\e[B", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +const char capitalKeycodes[128] = { + 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', + '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', + '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, + '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +uint8_t getScancode() { + int_fast16_t scancode = -1; + for (uint16_t i = 0; i < 1000; i++) { + if ((ioIn(0x64, 1) & 1) == 0) { + continue; + } + scancode = ioIn(0x60, 1); + break; + } + return scancode; +} + +void onKey() { + uint8_t scancode = getScancode(); + if (scancode == 0xE0) { + scancode = getScancode(); + if (scancode & 0x80) { + return; + } + request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); + return; + } + if (scancode & 0x80) { + // key release + scancode = scancode & 0x7F; + for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { + if (scancode == modifierScancodes[i]) { + modifiers = modifiers & (0xFF ^ 0x01 << i); + } + } + return; + } + for (uint8_t i = 0; i < sizeof(modifierScancodes); i++) { + if (scancode == modifierScancodes[i]) { + modifiers = modifiers | 0x01 << i; + return; + } + } + char data = 0; + if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { + data = capitalKeycodes[scancode]; + } else { + data = keycodes[scancode]; + } + request(ioManager, keyCallback, data, 0); +} + +int32_t main() { + uint32_t service = getService("pic"); + uint32_t event = getEvent(service, "irq1"); + subscribeEvent(service, event, onKey); + printf("PS/2 keyboard handler installed\n"); +}