diff --git a/CMakeLists.txt b/CMakeLists.txt index 373951613..358e17380 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ add_custom_target (install_applications COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tools/utils.py --cp --source ${VALI_PATH_APPLICATIONS}/bin --dest ${VALI_PATH_DEPLOY_SHARED_MAPS} --pattern *.map #COMMAND ${CMAKE_COMMAND} -E copy_directory ${VALI_PATH_APPLICATIONS}/include/ ${VALI_PATH_DEPLOY_SHARED_INC} #COMMAND ${CMAKE_COMMAND} -E copy_directory ${VALI_PATH_APPLICATIONS}/lib/ ${VALI_PATH_DEPLOY_SHARED_LIB} - COMMAND ${CMAKE_COMMAND} -E copy_directory ${VALI_PATH_APPLICATIONS}/share/ ${VALI_PATH_DEPLOY_SHARED_SHARE} + #COMMAND ${CMAKE_COMMAND} -E copy_directory ${VALI_PATH_APPLICATIONS}/share/ ${VALI_PATH_DEPLOY_SHARED_SHARE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/kernel/system_api/entry.c b/kernel/system_api/entry.c index e75d033c3..6af91f5a0 100644 --- a/kernel/system_api/entry.c +++ b/kernel/system_api/entry.c @@ -136,8 +136,8 @@ extern OsStatus_t ScCreateMemoryHandler(unsigned int Flags, size_t Length, UUId_ extern OsStatus_t ScDestroyMemoryHandler(UUId_t Handle); extern OsStatus_t ScFlushHardwareCache(int Cache, void* Start, size_t Length); extern OsStatus_t ScSystemQuery(SystemDescriptor_t* Descriptor); -extern OsStatus_t ScSystemTime(SystemTime_t* SystemTime); -extern OsStatus_t ScSystemTick(int TickBase, LargeUInteger_t* Tick); +extern OsStatus_t ScSystemTime(SystemTime_t* systemTime); +extern OsStatus_t ScSystemTick(int tickBase, LargeUInteger_t* tick); extern OsStatus_t ScPerformanceFrequency(LargeInteger_t *Frequency); extern OsStatus_t ScPerformanceTick(LargeInteger_t *Value); diff --git a/kernel/system_api/system_api.c b/kernel/system_api/system_api.c index 0f99e3082..b371f67af 100644 --- a/kernel/system_api/system_api.c +++ b/kernel/system_api/system_api.c @@ -98,42 +98,42 @@ ScFlushHardwareCache( OsStatus_t ScSystemTime( - _In_ SystemTime_t* SystemTime) + _In_ SystemTime_t* systemTime) { - if (SystemTime == NULL) { + if (systemTime == NULL) { return OsError; } - memcpy(SystemTime, &GetMachine()->SystemTime, sizeof(SystemTime_t)); + memcpy(systemTime, &GetMachine()->SystemTime, sizeof(SystemTime_t)); return OsSuccess; } OsStatus_t ScSystemTick( - _In_ int TickBase, - _In_ LargeUInteger_t* Tick) + _In_ int tickBase, + _In_ LargeUInteger_t* tick) { - if (Tick == NULL) { + if (tick == NULL) { return OsError; } - if (TimersGetSystemTick((clock_t*)&Tick->QuadPart) == OsSuccess) { - if (TickBase == TIME_PROCESS) { + if (TimersGetSystemTick((clock_t*)&tick->QuadPart) == OsSuccess) { + if (tickBase == TIME_PROCESS) { SystemModule_t* Module = GetCurrentModule(); if (Module != NULL) { - Tick->QuadPart -= Module->StartedAt; + tick->QuadPart -= Module->StartedAt; } } - else if (TickBase == TIME_THREAD) { + else if (tickBase == TIME_THREAD) { Thread_t* Thread = ThreadCurrentForCore(ArchGetProcessorCoreId()); if (Thread != NULL) { - Tick->QuadPart -= ThreadStartTime(Thread); + tick->QuadPart -= ThreadStartTime(Thread); } } return OsSuccess; } // Default the result to 0 to indicate unsupported - Tick->QuadPart = 0; + tick->QuadPart = 0; return OsError; } diff --git a/librt/libc/include/os/keycodes.h b/librt/libc/include/os/keycodes.h index e06c49c45..a5ee3effa 100644 --- a/librt/libc/include/os/keycodes.h +++ b/librt/libc/include/os/keycodes.h @@ -1,4 +1,5 @@ -/* MollenOS +/** + * MollenOS * * Copyright 2011, Philip Meulengracht * @@ -25,8 +26,9 @@ #define _KEYCODES_INTERFACE_H_ #include +#include -typedef enum KeyCode { +enum KeyCode { VK_INVALID = 0x00, // 0-9 @@ -84,103 +86,100 @@ typedef enum KeyCode { VK_SEMICOLON = 0x31, VK_CLEAR = 0x32, VK_ENTER = 0x33, - VK_SHIFT = 0x34, - VK_CONTROL = 0x35, - VK_ALT = 0x36, - VK_PAUSE = 0x37, - VK_CAPSLOCK = 0x38, - VK_HYPHEN = 0x39, - VK_ESCAPE = 0x3A, - VK_SPACE = 0x3B, - VK_SLASH = 0x3C, - VK_BACKSLASH = 0x3D, - VK_APOSTROPHE = 0x3E, - VK_EQUAL = 0x3F, - VK_LBRACKET = 0x40, - VK_RBRACKET = 0x41, - VK_PAGEUP = 0x42, - VK_PAGEDOWN = 0x43, - VK_END = 0x44, - VK_HOME = 0x45, - VK_LEFT = 0x46, - VK_UP = 0x47, - VK_RIGHT = 0x48, - VK_DOWN = 0x49, - VK_SELECT = 0x4A, - VK_PRINT = 0x4B, - VK_EXECUTE = 0x4C, - VK_SNAPSHOT = 0x4D, - VK_INSERT = 0x4E, - VK_DELETE = 0x4F, - VK_HELP = 0x50, + VK_PAUSE = 0x34, + VK_CAPSLOCK = 0x35, + VK_HYPHEN = 0x36, + VK_ESCAPE = 0x37, + VK_SPACE = 0x38, + VK_SLASH = 0x39, + VK_BACKSLASH = 0x3A, + VK_APOSTROPHE = 0x3B, + VK_EQUAL = 0x3C, + VK_LBRACKET = 0x3D, + VK_RBRACKET = 0x3E, + VK_PAGEUP = 0x3F, + VK_PAGEDOWN = 0x40, + VK_END = 0x41, + VK_HOME = 0x42, + VK_LEFT = 0x43, + VK_UP = 0x44, + VK_RIGHT = 0x45, + VK_DOWN = 0x46, + VK_SELECT = 0x47, + VK_PRINT = 0x48, + VK_EXECUTE = 0x49, + VK_SNAPSHOT = 0x4A, + VK_INSERT = 0x4B, + VK_DELETE = 0x4C, + VK_HELP = 0x4D, - VK_NUMLOCK = 0x51, - VK_SCROLL = 0x52, + VK_NUMLOCK = 0x4E, + VK_SCROLL = 0x4F, - VK_LSHIFT = 0x53, - VK_RSHIFT = 0x54, - VK_LCONTROL = 0x55, - VK_RCONTROL = 0x56, - VK_LALT = 0x57, - VK_RALT = 0x58, + VK_LSHIFT = 0x50, + VK_RSHIFT = 0x51, + VK_LCONTROL = 0x52, + VK_RCONTROL = 0x53, + VK_LALT = 0x54, + VK_RALT = 0x55, - VK_LWIN = 0x59, - VK_RWIN = 0x5A, - VK_APPS = 0x5B, + VK_LWIN = 0x56, + VK_RWIN = 0x57, + VK_APPS = 0x58, - VK_F1 = 0x5C, - VK_F2 = 0x5D, - VK_F3 = 0x5E, - VK_F4 = 0x5F, - VK_F5 = 0x60, - VK_F6 = 0x61, - VK_F7 = 0x62, - VK_F8 = 0x63, - VK_F9 = 0x64, - VK_F10 = 0x65, - VK_F11 = 0x66, - VK_F12 = 0x67, - VK_F13 = 0x68, - VK_F14 = 0x69, - VK_F15 = 0x70, - VK_F16 = 0x71, - VK_F17 = 0x72, - VK_F18 = 0x73, - VK_F19 = 0x74, - VK_F20 = 0x75, - VK_F21 = 0x76, - VK_F22 = 0x77, - VK_F23 = 0x78, - VK_F24 = 0x79, + VK_F1 = 0x59, + VK_F2 = 0x5A, + VK_F3 = 0x5B, + VK_F4 = 0x5C, + VK_F5 = 0x5D, + VK_F6 = 0x5E, + VK_F7 = 0x5F, + VK_F8 = 0x60, + VK_F9 = 0x61, + VK_F10 = 0x62, + VK_F11 = 0x63, + VK_F12 = 0x64, + VK_F13 = 0x65, + VK_F14 = 0x66, + VK_F15 = 0x67, + VK_F16 = 0x68, + VK_F17 = 0x69, + VK_F18 = 0x6A, + VK_F19 = 0x6B, + VK_F20 = 0x6C, + VK_F21 = 0x6D, + VK_F22 = 0x6E, + VK_F23 = 0x6F, + VK_F24 = 0x70, - VK_BROWSER_BACK = 0x7A, - VK_BROWSER_FORWARD = 0x7B, - VK_BROWSER_REFRESH = 0x7C, - VK_BROWSER_STOP = 0x7D, - VK_BROWSER_SEARCH = 0x7E, - VK_BROWSER_FAVORITES = 0x7F, - VK_BROWSER_HOME = 0x80, - VK_VOLUME_MUTE = 0x81, - VK_VOLUME_DOWN = 0x82, - VK_VOLUME_UP = 0x83, - VK_MEDIA_NEXT_TRACK = 0x84, - VK_MEDIA_PREV_TRACK = 0x85, - VK_MEDIA_STOP = 0x86, - VK_MEDIA_PLAY_PAUSE = 0x87, - VK_LAUNCH_MAIL = 0x88, - VK_LAUNCH_MEDIA_SELECT = 0x89, - VK_LAUNCH_APP1 = 0x8A, - VK_LAUNCH_APP2 = 0x8B, - VK_POWER = 0x8C, - VK_WAKE = 0x8D, - VK_SLEEP = 0x8E, - VK_PLAY = 0x8F, - VK_ZOOM = 0x90, + VK_BROWSER_BACK = 0x71, + VK_BROWSER_FORWARD = 0x72, + VK_BROWSER_REFRESH = 0x73, + VK_BROWSER_STOP = 0x74, + VK_BROWSER_SEARCH = 0x75, + VK_BROWSER_FAVORITES = 0x76, + VK_BROWSER_HOME = 0x77, + VK_VOLUME_MUTE = 0x78, + VK_VOLUME_DOWN = 0x79, + VK_VOLUME_UP = 0x7A, + VK_MEDIA_NEXT_TRACK = 0x7B, + VK_MEDIA_PREV_TRACK = 0x7C, + VK_MEDIA_STOP = 0x7D, + VK_MEDIA_PLAY_PAUSE = 0x7E, + VK_LAUNCH_MAIL = 0x7F, + VK_LAUNCH_MEDIA_SELECT = 0x80, + VK_LAUNCH_APP1 = 0x81, + VK_LAUNCH_APP2 = 0x82, + VK_POWER = 0x83, + VK_WAKE = 0x84, + VK_SLEEP = 0x85, + VK_PLAY = 0x86, + VK_ZOOM = 0x87, - VK_KEYCOUNT = 0x91 -} KeyCode_t; + VK_KEYCOUNT = 0x88 +}; -typedef enum KeyModifiers { +enum KeyModifiers { VK_MODIFIER_LSHIFT = 0x1, VK_MODIFIER_RSHIFT = 0x2, VK_MODIFIER_LALT = 0x4, @@ -190,8 +189,9 @@ typedef enum KeyModifiers { VK_MODIFIER_SCROLLOCK = 0x40, VK_MODIFIER_NUMLOCK = 0x80, VK_MODIFIER_CAPSLOCK = 0x100, + VK_MODIFIER_REPEATED = 0x200, VK_MODIFIER_RELEASED = 0x1000 -} KeyModifiers_t; +}; _CODE_BEGIN /** @@ -203,8 +203,8 @@ _CODE_BEGIN */ CRTDECL(char, TranslateKeyCode( - _In_ KeyCode_t keyCode, - _In_ KeyModifiers_t keyModifiers)); + _In_ uint8_t keyCode, + _In_ uint16_t keyModifiers)); _CODE_END #endif //!_KEYCODES_INTERFACE_H_ diff --git a/librt/libc/os/keycodes.c b/librt/libc/os/keycodes.c index 06a868a08..5ed2546a4 100644 --- a/librt/libc/os/keycodes.c +++ b/librt/libc/os/keycodes.c @@ -1,4 +1,5 @@ -/* MollenOS +/** + * MollenOS * * Copyright 2017, Philip Meulengracht * @@ -24,12 +25,12 @@ #include -extern char GetASCIIFromKeyCodeEnUs(KeyCode_t, KeyModifiers_t); +extern char GetASCIIFromKeyCodeEnUs(uint8_t, uint16_t); char TranslateKeyCode( - _In_ KeyCode_t keyCode, - _In_ KeyModifiers_t keyModifiers) + _In_ uint8_t keyCode, + _In_ uint16_t keyModifiers) { if (keyCode != VK_INVALID) { return GetASCIIFromKeyCodeEnUs(keyCode, keyModifiers); diff --git a/librt/libc/os/keymaps/en-us.c b/librt/libc/os/keymaps/en-us.c index 54283a6c2..9b589d4c1 100644 --- a/librt/libc/os/keymaps/en-us.c +++ b/librt/libc/os/keymaps/en-us.c @@ -1,4 +1,5 @@ -/* MollenOS +/** + * MollenOS * * Copyright 2018, Philip Meulengracht * @@ -21,44 +22,41 @@ * the standard en-US keyboard. Supports Ascii for now */ -#include #include // Keymap when modifier SHIFT is present -static uint8_t AsciiShiftKeyMap[VK_KEYCOUNT] = { +static uint8_t g_asciiShiftKeyMap[VK_KEYCOUNT] = { 0, ')', '!', '\"', '#', '$', '%', '^', '&', '*', '(', '*', '+', '-', '-', ',', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '`', '~', 0, '\t', '>', - '<', ':', 0, '\n', 0, 0, 0, 0, 0, '_', 0, ' ', '?', '|', - '@', '+', '{', '}', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + '<', ':', 0, '\n', 0, 0, '_', 0, ' ', '?', '|', '@', '+', + '{', '}', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Keymap when no modifier is present -static uint8_t AsciiKeyMap[VK_KEYCOUNT] = { +static uint8_t g_asciiKeyMap[VK_KEYCOUNT] = { 0, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '+', '-', '-', ',', '/', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '`', '`', 0, '\t', '.', - ',', ';', 0, '\n', 0, 0, 0, 0, 0, '-', 0, ' ', '/', '\\', - '\'', '=', '[', ']', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ',', ';', 0, '\n', 0, 0, '-', 0, ' ', '/', '\\', '\'', '=', + '[', ']', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; char GetASCIIFromKeyCodeEnUs( - _In_ KeyCode_t keyCode, - _In_ KeyModifiers_t keyModifiers) + _In_ uint8_t keyCode, + _In_ uint16_t keyModifiers) { - char character = '\0'; int shouldUpperCase = keyModifiers & (VK_MODIFIER_LSHIFT | VK_MODIFIER_RSHIFT); + char character; if (keyModifiers & VK_MODIFIER_CAPSLOCK) { if (shouldUpperCase != 0) { @@ -71,10 +69,10 @@ GetASCIIFromKeyCodeEnUs( // Handle modifiers, caps lock negates shift as seen above if (shouldUpperCase) { - character = AsciiShiftKeyMap[keyCode]; + character = g_asciiShiftKeyMap[keyCode]; } else { - character = AsciiKeyMap[keyCode]; + character = g_asciiKeyMap[keyCode]; } return character; } diff --git a/modules/arch/x86/ps2/devices/keyboard.c b/modules/arch/x86/ps2/devices/keyboard.c index 4e661992f..811e82e8b 100644 --- a/modules/arch/x86/ps2/devices/keyboard.c +++ b/modules/arch/x86/ps2/devices/keyboard.c @@ -20,6 +20,7 @@ * X86 PS2 Controller (Mouse) Driver * http://wiki.osdev.org/PS2 */ + //#define __TRACE #include @@ -33,84 +34,7 @@ #include #include -OsStatus_t -PS2KeyboardHandleModifiers( - _In_ PS2Port_t* port, - _In_ struct ctt_input_button_event* buttonEvent) -{ - uint16_t Flags = *((uint16_t*)&PS2_KEYBOARD_DATA_STATE_LO(port)); - - // Handle modifiers - switch (buttonEvent->key_code) { - case VK_LSHIFT: { - Flags |= VK_MODIFIER_LSHIFT; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_LSHIFT); - } - } break; - case VK_RSHIFT: { - Flags |= VK_MODIFIER_RSHIFT; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_RSHIFT); - } - } break; - - case VK_LCONTROL: { - Flags |= VK_MODIFIER_LCTRL; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_LCTRL); - } - } break; - case VK_RCONTROL: { - Flags |= VK_MODIFIER_RCTRL; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_RCTRL); - } - } break; - - case VK_LALT: { - Flags |= VK_MODIFIER_LALT; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_LALT); - } - } break; - case VK_RALT: { - Flags |= VK_MODIFIER_RALT; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_RALT); - } - } break; - - case VK_SCROLL: { - Flags |= VK_MODIFIER_SCROLLOCK; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_SCROLLOCK); - } - } break; - case VK_NUMLOCK: { - Flags |= VK_MODIFIER_NUMLOCK; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_NUMLOCK); - } - } break; - case VK_CAPSLOCK: { - Flags |= VK_MODIFIER_CAPSLOCK; - if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { - Flags &= ~(VK_MODIFIER_CAPSLOCK); - } - } break; - - default: { - buttonEvent->modifiers |= Flags; - return OsSuccess; - }; - } - - // Update the state flags - buttonEvent->modifiers |= Flags; - *((uint16_t*)&PS2_KEYBOARD_DATA_STATE_LO(port)) = Flags; - return OsError; -} +#define IS_SWITCH(keyCode) (keyCode == VK_CAPSLOCK || keyCode == VK_SCROLL || keyCode == VK_NUMLOCK) InterruptStatus_t PS2KeyboardFastInterrupt( @@ -141,42 +65,150 @@ PS2KeyboardFastInterrupt( return InterruptHandled; } +static inline int __IsKeySet( + _In_ PS2Port_t* port, + _In_ uint8_t keyCode) +{ + int keyBlock = keyCode / sizeof(uint8_t); + int keyIndex = keyCode % sizeof(uint8_t); + return port->device_data.keyboard.key_map[keyBlock] & (1 << keyIndex); +} + +static inline void __SetKey( + _In_ PS2Port_t* port, + _In_ uint8_t keyCode) +{ + int keyBlock = keyCode / sizeof(uint8_t); + int keyIndex = keyCode % sizeof(uint8_t); + port->device_data.keyboard.key_map[keyBlock] |= (1 << keyIndex); +} + +static inline void __ClearKey( + _In_ PS2Port_t* port, + _In_ uint8_t keyCode) +{ + int keyBlock = keyCode / sizeof(uint8_t); + int keyIndex = keyCode % sizeof(uint8_t); + port->device_data.keyboard.key_map[keyBlock] &= ~(1 << keyIndex); +} + +static inline uint16_t __GetModifierFlag( + _In_ uint8_t keyCode) +{ + switch (keyCode) { + case VK_LCONTROL: return VK_MODIFIER_LCTRL; + case VK_RCONTROL: return VK_MODIFIER_RCTRL; + case VK_LALT: return VK_MODIFIER_LALT; + case VK_RALT: return VK_MODIFIER_RALT; + case VK_LSHIFT: return VK_MODIFIER_LSHIFT; + case VK_RSHIFT: return VK_MODIFIER_RSHIFT; + case VK_SCROLL: return VK_MODIFIER_SCROLLOCK; + case VK_NUMLOCK: return VK_MODIFIER_NUMLOCK; + case VK_CAPSLOCK: return VK_MODIFIER_CAPSLOCK; + default: return 0; + } +} + +static void __HandleKeyCode( + _In_ PS2Port_t* port, + _In_ struct ctt_input_button_event* buttonEvent) +{ + uint16_t modifiers = 0; + uint16_t flag = __GetModifierFlag(buttonEvent->key_code); + + // set key pressed if pressed + if (buttonEvent->modifiers & VK_MODIFIER_RELEASED) { + // release event + if (IS_SWITCH(buttonEvent->key_code)) { + // Only clear it if it has been cleared with the second press + if (!(port->device_data.keyboard.modifiers & flag)) { + __ClearKey(port, buttonEvent->key_code); + } + } + else { + __ClearKey(port, buttonEvent->key_code); + if (flag) { + port->device_data.keyboard.modifiers &= ~(flag); + } + } + modifiers |= port->device_data.keyboard.modifiers; + } + else { + // press event - we handle lock-keys a bit different as they are switches + if (IS_SWITCH(buttonEvent->key_code)) { + port->device_data.keyboard.modifiers ^= flag; + if (port->device_data.keyboard.modifiers & flag) { + __SetKey(port, buttonEvent->key_code); + } + } + else { + if (__IsKeySet(port, buttonEvent->key_code)) { + modifiers |= VK_MODIFIER_REPEATED; + } + else { + __SetKey(port, buttonEvent->key_code); + if (flag) { + port->device_data.keyboard.modifiers |= flag; + } + } + } + modifiers |= port->device_data.keyboard.modifiers; + } + + // Update the state flags + buttonEvent->modifiers |= modifiers; +} + +static inline OsStatus_t __ParseKeyCode( + _In_ PS2Port_t* port, + _In_ uint8_t scancodeSet, + _In_ uint32_t* readIndexReference, + _In_ struct ctt_input_button_event* event) +{ + OsStatus_t osStatus = OsError; + uint32_t readIndex = *readIndexReference; + + while (osStatus == OsError && readIndex < port->ResponseWriteIndex) { + uint8_t scancode = port->ResponseBuffer[readIndex % PS2_RINGBUFFER_SIZE]; + if (scancodeSet == 1) { + ERROR("PS2-Keyboard: Scancode set 1"); + break; + } + else if (scancodeSet == 2) { + osStatus = ScancodeSet2ToVKey(event, scancode); + } + readIndex++; + } + + *readIndexReference = readIndex; + return osStatus; +} + void PS2KeyboardInterrupt( _In_ PS2Port_t* port) { - struct ctt_input_button_event buttonEvent; - OsStatus_t status; - uint8_t scancode; - uint8_t scancodeSet = PS2_KEYBOARD_DATA_SCANCODESET(port); - uint32_t readIndex = port->ResponseReadIndex; + OsStatus_t status; + uint8_t scancodeSet = port->device_data.keyboard.scancode_set; + uint32_t readIndex = port->ResponseReadIndex; smp_rmb(); // wait for all loads to be done before reading write_index while (readIndex < port->ResponseWriteIndex) { - memset(&buttonEvent, 0, sizeof(struct ctt_input_button_event)); - status = OsError; - - // Perform scancode-translation - while (status == OsError && readIndex < port->ResponseWriteIndex) { - scancode = port->ResponseBuffer[readIndex % PS2_RINGBUFFER_SIZE]; - if (scancodeSet == 1) { - ERROR("PS2-Keyboard: Scancode set 1"); - break; - } - else if (scancodeSet == 2) { - status = ScancodeSet2ToVKey(&buttonEvent, scancode); - } - readIndex++; - } + struct ctt_input_button_event buttonEvent = { 0 }; + status = __ParseKeyCode(port, scancodeSet, &readIndex, &buttonEvent); if (status == OsSuccess) { port->ResponseReadIndex = readIndex; - // If the key was an actual key and not modifier, remove our flags and send - if (PS2KeyboardHandleModifiers(port, &buttonEvent) == OsSuccess) { - buttonEvent.modifiers &= ~(KEY_MODIFIER_EXTENDED); - ctt_input_event_button_all(port->DeviceId, buttonEvent.key_code, buttonEvent.modifiers); + // we do not handle invalid key-codes + if (buttonEvent.key_code == VK_INVALID) { + continue; } + + buttonEvent.modifiers &= ~(KEY_MODIFIER_EXTENDED); + + __HandleKeyCode(port, &buttonEvent); + ctt_input_event_button_all(port->DeviceId, buttonEvent.key_code, buttonEvent.modifiers); } } } @@ -202,32 +234,32 @@ PS2KeyboardGetScancode( } OsStatus_t PS2KeyboardSetScancode( - _In_ PS2Port_t* Port, - _In_ uint8_t RequestSet) + _In_ PS2Port_t* port, + _In_ uint8_t requestSet) { - if (PS2PortExecuteCommand(Port, PS2_KEYBOARD_SCANCODE, NULL) != OsSuccess || - PS2PortExecuteCommand(Port, RequestSet, NULL) != OsSuccess) { + if (PS2PortExecuteCommand(port, PS2_KEYBOARD_SCANCODE, NULL) != OsSuccess || + PS2PortExecuteCommand(port, requestSet, NULL) != OsSuccess) { return OsError; } else { - PS2_KEYBOARD_DATA_SCANCODESET(Port) = RequestSet; + port->device_data.keyboard.scancode_set = requestSet; return OsSuccess; } } OsStatus_t PS2KeyboardSetTypematics( - _In_ PS2Port_t* Port) + _In_ PS2Port_t* port) { - uint8_t Format = 0; + uint8_t data = 0; // Build the data-packet - Format |= PS2_KEYBOARD_DATA_REPEAT(Port); - Format |= PS2_KEYBOARD_DATA_DELAY(Port); + data |= port->device_data.keyboard.repeat; + data |= port->device_data.keyboard.delay; // Write the command to get scancode set - if (PS2PortExecuteCommand(Port, PS2_KEYBOARD_TYPEMATIC, NULL) != OsSuccess || - PS2PortExecuteCommand(Port, Format, NULL) != OsSuccess) { + if (PS2PortExecuteCommand(port, PS2_KEYBOARD_TYPEMATIC, NULL) != OsSuccess || + PS2PortExecuteCommand(port, data, NULL) != OsSuccess) { return OsError; } else { @@ -237,21 +269,21 @@ PS2KeyboardSetTypematics( OsStatus_t PS2KeyboardSetLEDs( - _In_ PS2Port_t* Port, - _In_ int Scroll, - _In_ int Number, - _In_ int Caps) + _In_ PS2Port_t* port, + _In_ int setScroll, + _In_ int setNumber, + _In_ int setCaps) { - uint8_t Format = 0; + uint8_t data = 0; // Build the data-packet - Format |= ((uint8_t)(Scroll & 0x1) << 0); - Format |= ((uint8_t)(Number & 0x1) << 1); - Format |= ((uint8_t)(Caps & 0x1) << 2); + data |= ((uint8_t)(setScroll & 0x1) << 0); + data |= ((uint8_t)(setNumber & 0x1) << 1); + data |= ((uint8_t)(setCaps & 0x1) << 2); // Write the command to get scancode set - if (PS2PortExecuteCommand(Port, PS2_KEYBOARD_SETLEDS, NULL) != OsSuccess || - PS2PortExecuteCommand(Port, Format, NULL) != OsSuccess) { + if (PS2PortExecuteCommand(port, PS2_KEYBOARD_SETLEDS, NULL) != OsSuccess || + PS2PortExecuteCommand(port, data, NULL) != OsSuccess) { return OsError; } else { @@ -261,21 +293,22 @@ PS2KeyboardSetLEDs( OsStatus_t PS2KeyboardInitialize( - _In_ PS2Controller_t* Controller, - _In_ int port, - _In_ int Translation) + _In_ PS2Controller_t* controller, + _In_ int portIndex, + _In_ int translation) { gracht_client_configuration_t client_config; struct socket_client_configuration link_config; - PS2Port_t* instance = &Controller->Ports[port]; + PS2Port_t* port = &controller->Ports[portIndex]; int status; - TRACE("... [ps2] [keyboard] initialize"); + TRACE("PS2KeyboardInitialize(portIndex=%i, translation=%i)", portIndex, translation); // Initialize keyboard defaults - PS2_KEYBOARD_DATA_XLATION(instance) = (uint8_t)Translation; - PS2_KEYBOARD_DATA_SCANCODESET(instance) = 2; - PS2_KEYBOARD_DATA_REPEAT(instance) = PS2_REPEATS_PERSEC(16); - PS2_KEYBOARD_DATA_DELAY(instance) = PS2_DELAY_500MS; + memset(&port->device_data, 0, sizeof(port->device_data)); + port->device_data.keyboard.xlation = (uint8_t)translation; + port->device_data.keyboard.scancode_set = 2; + port->device_data.keyboard.repeat = PS2_REPEATS_PERSEC(16); + port->device_data.keyboard.delay = PS2_DELAY_500MS; // Open up the input socket so we can send input data to the OS. link_config.type = gracht_link_packet_based; @@ -283,44 +316,44 @@ PS2KeyboardInitialize( status = gracht_link_socket_client_create(&client_config.link, &link_config); if (status) { - ERROR("... [ps2] [keyboard] [initialize] gracht_link_socket_client_create failed %i", errno); + ERROR("PS2KeyboardInitialize gracht_link_socket_client_create failed %i", errno); } - if (status && gracht_client_create(&client_config, &instance->GrachtClient)) { - ERROR("... [ps2] [keyboard] [initialize] gracht_client_create failed %i", errno); + if (status && gracht_client_create(&client_config, &port->GrachtClient)) { + ERROR("PS2KeyboardInitialize gracht_client_create failed %i", errno); } // Initialize interrupt - RegisterFastInterruptIoResource(&instance->Interrupt, Controller->Data); - RegisterFastInterruptHandler(&instance->Interrupt, (InterruptHandler_t)PS2KeyboardFastInterrupt); - instance->InterruptId = RegisterInterruptSource(&instance->Interrupt, INTERRUPT_EXCLUSIVE); + RegisterFastInterruptIoResource(&port->Interrupt, controller->Data); + RegisterFastInterruptHandler(&port->Interrupt, (InterruptHandler_t)PS2KeyboardFastInterrupt); + port->InterruptId = RegisterInterruptSource(&port->Interrupt, INTERRUPT_EXCLUSIVE); // Reset keyboard LEDs status - if (PS2KeyboardSetLEDs(instance, 0, 0, 0) != OsSuccess) { - ERROR("PS2-Keyboard: failed to reset LEDs"); + if (PS2KeyboardSetLEDs(port, 0, 0, 0) != OsSuccess) { + ERROR("PS2KeyboardInitialize: failed to reset LEDs"); } // Update typematics to preffered settings - if (PS2KeyboardSetTypematics(instance) != OsSuccess) { - WARNING("PS2-Keyboard: failed to set typematic settings"); + if (PS2KeyboardSetTypematics(port) != OsSuccess) { + WARNING("PS2KeyboardInitialize: failed to set typematic settings"); } // Select our preffered scancode set - if (PS2KeyboardSetScancode(instance, 2) != OsSuccess) { - WARNING("PS2-Keyboard: failed to select scancodeset 2 (%u)", - PS2_KEYBOARD_DATA_SCANCODESET(instance)); + if (PS2KeyboardSetScancode(port, 2) != OsSuccess) { + WARNING("PS2KeyboardInitialize: failed to select scancodeset 2 (%u)", + port->device_data.keyboard.scancode_set); } - instance->State = PortStateActive; - return PS2PortExecuteCommand(instance, PS2_ENABLE_SCANNING, NULL); + port->State = PortStateActive; + return PS2PortExecuteCommand(port, PS2_ENABLE_SCANNING, NULL); } OsStatus_t PS2KeyboardCleanup( _In_ PS2Controller_t* controller, - _In_ int index) + _In_ int portIndex) { - PS2Port_t* port = &controller->Ports[index]; + PS2Port_t* port = &controller->Ports[portIndex]; // Try to disable the device before cleaning up PS2PortExecuteCommand(port, PS2_DISABLE_SCANNING, NULL); diff --git a/modules/arch/x86/ps2/devices/keyboard.h b/modules/arch/x86/ps2/devices/keyboard.h index cda83291a..f6f64a29c 100644 --- a/modules/arch/x86/ps2/devices/keyboard.h +++ b/modules/arch/x86/ps2/devices/keyboard.h @@ -43,18 +43,11 @@ #define PS2_DELAY_1000MS 0x60 #define KEY_MODIFIER_EXTENDED 0x8000 -#define PS2_KEYBOARD_DATA_XLATION(Port) (Port)->DeviceData[0] -#define PS2_KEYBOARD_DATA_SCANCODESET(Port) (Port)->DeviceData[1] -#define PS2_KEYBOARD_DATA_REPEAT(Port) (Port)->DeviceData[2] -#define PS2_KEYBOARD_DATA_DELAY(Port) (Port)->DeviceData[3] -#define PS2_KEYBOARD_DATA_STATE_LO(Port) (Port)->DeviceData[4] -#define PS2_KEYBOARD_DATA_STATE_HI(Port) (Port)->DeviceData[5] - /* ScancodeSet2ToVKey * Converts a scancode 2 key to the standard-defined virtual key-layout */ __EXTERN OsStatus_t ScancodeSet2ToVKey( - _In_ struct ctt_input_button_event* KeyState, - _In_ uint8_t Scancode); + _In_ struct ctt_input_button_event* keyState, + _In_ uint8_t scancode); #endif //!_DRIVER_PS2_KEYBOARD_H_ diff --git a/modules/arch/x86/ps2/devices/mouse.c b/modules/arch/x86/ps2/devices/mouse.c index c8793a851..1ba1e9f1d 100644 --- a/modules/arch/x86/ps2/devices/mouse.c +++ b/modules/arch/x86/ps2/devices/mouse.c @@ -37,7 +37,7 @@ PS2MouseFastInterrupt( DeviceIo_t* ioSpace = INTERRUPT_IOSPACE(ResourceTable, 0); PS2Port_t* port = (PS2Port_t*)INTERRUPT_RESOURCE(ResourceTable, 0); uint8_t dataRecieved = (uint8_t)InterruptTable->ReadIoSpace(ioSpace, PS2_REGISTER_DATA, 1); - uint8_t breakAtBytes = PS2_MOUSE_DATA_MODE(port) == 0 ? 3 : 4; + uint8_t breakAtBytes = port->device_data.mouse.mode == 0 ? 3 : 4; PS2Command_t* command = &port->ActiveCommand; if (command->State != PS2Free) { @@ -64,7 +64,7 @@ PS2MouseInterrupt( _In_ PS2Port_t* port) { struct ctt_input_cursor_event input; - uint8_t bytesRequired = PS2_MOUSE_DATA_MODE(port) == 0 ? 3 : 4; + uint8_t bytesRequired = port->device_data.mouse.mode == 0 ? 3 : 4; uint32_t index = port->ResponseReadIndex % PS2_RINGBUFFER_SIZE; // Update relative x and y @@ -74,10 +74,10 @@ PS2MouseInterrupt( input.buttons_set = port->ResponseBuffer[0] & 0x7; // L-M-R buttons // Check extended data modes - if (PS2_MOUSE_DATA_MODE(port) == 1) { + if (port->device_data.mouse.mode == 1) { input.rel_z = (int16_t)(char)port->ResponseBuffer[index + 3]; } - else if (PS2_MOUSE_DATA_MODE(port) == 2) { + else if (port->device_data.mouse.mode == 2) { // 4 bit signed value input.rel_z = (int16_t)(char)(port->ResponseBuffer[index + 3] & 0xF); input.buttons_set |= (port->ResponseBuffer[index + 3] & (PS2_MOUSE_4BTN | PS2_MOUSE_5BTN)) >> 1; @@ -161,8 +161,9 @@ PS2MouseInitialize( int status; // Set initial mouse sampling - PS2_MOUSE_DATA_SAMPLING(port) = 100; - PS2_MOUSE_DATA_MODE(port) = 0; + memset(&port->device_data, 0, sizeof(port->device_data)); + port->device_data.mouse.sampling = 100; + port->device_data.mouse.mode = 0; // Open up the input socket so we can send input data to the OS. link_config.type = gracht_link_packet_based; @@ -185,15 +186,15 @@ PS2MouseInitialize( // The mouse is in default state at this point // since all ports suffer a reset - We want to test if the mouse is a 4-byte mouse if (PS2EnableScroll(port) == OsSuccess) { - PS2_MOUSE_DATA_MODE(port) = 1; + port->device_data.mouse.mode = 1; if (PS2EnableExtensions(port) == OsSuccess) { - PS2_MOUSE_DATA_MODE(port) = 2; + port->device_data.mouse.mode = 2; } } // Update sampling to 60, no need for faster updates if (PS2SetSampling(port, 60) == OsSuccess) { - PS2_MOUSE_DATA_SAMPLING(&controller->Ports[index]) = 100; + port->device_data.mouse.sampling = 100; } port->State = PortStateActive; diff --git a/modules/arch/x86/ps2/devices/mouse.h b/modules/arch/x86/ps2/devices/mouse.h index d57750b3e..a0ce8027b 100644 --- a/modules/arch/x86/ps2/devices/mouse.h +++ b/modules/arch/x86/ps2/devices/mouse.h @@ -1,4 +1,5 @@ -/* MollenOS +/** + * MollenOS * * Copyright 2017, Philip Meulengracht * @@ -42,7 +43,4 @@ #define PS2_MOUSE_4BTN 0x10 #define PS2_MOUSE_5BTN 0x20 -#define PS2_MOUSE_DATA_SAMPLING(Port) (Port)->DeviceData[0] -#define PS2_MOUSE_DATA_MODE(Port) (Port)->DeviceData[1] - #endif //!_DRIVER_PS2_MOUSE_H_ diff --git a/modules/arch/x86/ps2/devices/scancodes/scancodes2.c b/modules/arch/x86/ps2/devices/scancodes/scancodes2.c index e3b49a438..c011a7d73 100644 --- a/modules/arch/x86/ps2/devices/scancodes/scancodes2.c +++ b/modules/arch/x86/ps2/devices/scancodes/scancodes2.c @@ -23,7 +23,7 @@ #include "../keyboard.h" #include -static uint8_t ScancodeSet2Table[132] = { +static uint8_t g_scancodeSet2Table[132] = { VK_INVALID, VK_F9, VK_INVALID, VK_F5, VK_F3, VK_F1, VK_F2, VK_F12, VK_INVALID, VK_F10, VK_F8, VK_F6, VK_F4, VK_TAB, VK_BACKTICK, VK_INVALID, VK_INVALID, VK_LALT, VK_LSHIFT, VK_INVALID, VK_LCONTROL, VK_Q, VK_1, VK_INVALID, VK_INVALID, @@ -41,7 +41,7 @@ static uint8_t ScancodeSet2Table[132] = { VK_SCROLL, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_F7 }; -static uint8_t ScancodeSet2ExtendedTable[126] = { +static uint8_t g_scancodeSet2ExtendedTable[126] = { VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_INVALID, VK_BROWSER_SEARCH, VK_RALT, VK_INVALID, VK_INVALID, VK_RCONTROL, @@ -63,25 +63,25 @@ static uint8_t ScancodeSet2ExtendedTable[126] = { OsStatus_t ScancodeSet2ToVKey( - _In_ struct ctt_input_button_event* KeyState, - _In_ uint8_t Scancode) + _In_ struct ctt_input_button_event* keyState, + _In_ uint8_t scancode) { // Handle special cases - if (Scancode == PS2_CODE_EXTENDED) { - KeyState->modifiers |= KEY_MODIFIER_EXTENDED; + if (scancode == PS2_CODE_EXTENDED) { + keyState->modifiers |= KEY_MODIFIER_EXTENDED; return OsError; } - else if (Scancode == PS2_CODE_RELEASED) { - KeyState->modifiers |= VK_MODIFIER_RELEASED; + else if (scancode == PS2_CODE_RELEASED) { + keyState->modifiers |= VK_MODIFIER_RELEASED; return OsError; } // Get appropriate scancode - if (KeyState->modifiers & KEY_MODIFIER_EXTENDED) { - KeyState->key_code = ScancodeSet2ExtendedTable[Scancode]; + if (keyState->modifiers & KEY_MODIFIER_EXTENDED) { + keyState->key_code = g_scancodeSet2ExtendedTable[scancode]; } else { - KeyState->key_code = ScancodeSet2Table[Scancode]; + keyState->key_code = g_scancodeSet2Table[scancode]; } return OsSuccess; } diff --git a/modules/arch/x86/ps2/ps2.h b/modules/arch/x86/ps2/ps2.h index ff6309f9c..31e40214b 100644 --- a/modules/arch/x86/ps2/ps2.h +++ b/modules/arch/x86/ps2/ps2.h @@ -90,6 +90,8 @@ #define SIGNATURE_IS_KEYBOARD(sig) (sig == 0xAB41 || sig == 0xABC1 || sig == 0xAB83) #define SIGNATURE_IS_MOUSE(sig) (sig != 0xFFFFFFFF && !SIGNATURE_IS_KEYBOARD(sig)) +#define PS2_KEYMAP_SIZE ((256) / (sizeof(uint8_t) * 8)) + typedef enum PS2CommandState { PS2Free = 0, PS2InQueue = 1, @@ -124,10 +126,24 @@ typedef struct PS2Port { int event_descriptor; // Device state information - uint8_t DeviceData[6]; uint8_t ResponseBuffer[PS2_RINGBUFFER_SIZE]; unsigned int ResponseWriteIndex; unsigned int ResponseReadIndex; + + union { + struct { + uint8_t xlation; + uint8_t scancode_set; + uint8_t repeat; + uint8_t delay; + uint16_t modifiers; + uint8_t key_map[PS2_KEYMAP_SIZE]; + } keyboard; + struct { + uint8_t sampling; + uint8_t mode; + } mouse; + } device_data; } PS2Port_t; typedef struct PS2Controller { @@ -200,16 +216,16 @@ PS2MouseInterrupt( * Initializes an instance of an ps2-keyboard on the given PS2-Controller port */ __EXTERN OsStatus_t PS2KeyboardInitialize( - _In_ PS2Controller_t* Controller, - _In_ int port, - _In_ int Translation); + _In_ PS2Controller_t* controller, + _In_ int portIndex, + _In_ int translation); /* PS2KeyboardCleanup * Cleans up the ps2-keyboard instance on the given PS2-Controller port */ __EXTERN OsStatus_t PS2KeyboardCleanup( _In_ PS2Controller_t* controller, - _In_ int index); + _In_ int portIndex); /* PS2KeyboardInterrupt * Handles the ps2-keyboard interrupt and processes the captured data */ diff --git a/protocols/contract_protocols.xml b/protocols/contract_protocols.xml index 15642f9e8..14385061e 100644 --- a/protocols/contract_protocols.xml +++ b/protocols/contract_protocols.xml @@ -3,11 +3,10 @@ + - - @@ -235,8 +234,8 @@ - - + + diff --git a/services/processmanager/process.c b/services/processmanager/process.c index ef26e5dbb..ee02a6ae7 100644 --- a/services/processmanager/process.c +++ b/services/processmanager/process.c @@ -705,26 +705,23 @@ void svc_library_load_callback(struct gracht_recv_message* message, uintptr_t ResolveProcessLibraryFunction( - _In_ - Process_t *Process, - _In_ - Handle_t Handle, - _In_ - const char *Function) + _In_ Process_t* process, + _In_ Handle_t handle, + _In_ const char* function) { - PeExecutable_t *Image = Process->Executable; + PeExecutable_t* executable = process->Executable; TRACE("ResolveProcessLibraryFunction(%u, %s)", - (UUId_t) (uintptr_t) Process->Header.key, Function); - if (Handle != HANDLE_GLOBAL) { - Image = (PeExecutable_t *) Handle; + (UUId_t) (uintptr_t) process->Header.key, function); + if (handle != HANDLE_GLOBAL) { + executable = (PeExecutable_t *) handle; } - return PeResolveFunction(Image, Function); + return PeResolveFunction(executable, function); } void svc_library_get_function_callback(struct gracht_recv_message *message, struct svc_library_get_function_args *args) { - Process_t *process = AcquireProcess(args->process_handle); + Process_t* process = AcquireProcess(args->process_handle); OsStatus_t status = OsInvalidParameters; uintptr_t address = 0; @@ -779,9 +776,10 @@ void svc_process_get_tick_base_callback(struct gracht_recv_message *message, struct svc_process_get_tick_base_args *args) { - Process_t *process = AcquireProcess(args->handle); + Process_t* process = AcquireProcess(args->handle); OsStatus_t status = OsInvalidParameters; LargeUInteger_t tick; + if (process) { tick.QuadPart = clock() - process->StartedAt; status = OsSuccess; diff --git a/unit_tests/stdio_mock.h b/unit_tests/stdio_mock.h index 2629f1edc..bd4060723 100644 --- a/unit_tests/stdio_mock.h +++ b/unit_tests/stdio_mock.h @@ -84,6 +84,14 @@ typedef struct stdio_handle { #define _FBYTE 0x0400 #define _IOVRT 0x0800 +#define STDIO_HANDLE_INVALID 0 +#define STDIO_HANDLE_PIPE 1 +#define STDIO_HANDLE_FILE 2 +#define STDIO_HANDLE_SOCKET 3 +#define STDIO_HANDLE_IPCONTEXT 4 +#define STDIO_HANDLE_SET 5 +#define STDIO_HANDLE_EVENT 6 + #define EOF (-1) #define SEEK_SET 0 /* Seek from beginning of file. */ #define SEEK_CUR 1 /* Seek from current position. */