Some cleanup, moved PS2 code to drivers folder in the shared sources.
This commit is contained in:
41
targets/_any/include/drivers/pic.hpp
Normal file
41
targets/_any/include/drivers/pic.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED)
|
||||
#define BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "os/port.hpp"
|
||||
|
||||
inline constexpr std::uint16_t PORT_PIC1 = 0x20;
|
||||
inline constexpr std::uint16_t PORT_PIC2 = 0xA0;
|
||||
inline constexpr std::uint8_t PIC_CMD_EOI = 0x20;
|
||||
|
||||
[[nodiscard]] bool initPICs(std::uint8_t masterOffset, std::uint8_t slaveOffset) noexcept;
|
||||
__attribute__((no_caller_saved_registers))
|
||||
void sendEndOfInterrupt(std::uint8_t irq) noexcept;
|
||||
void maskIRQ(std::uint8_t irq) noexcept;
|
||||
void unmaskIRQ(std::uint8_t irq) noexcept;
|
||||
[[nodiscard]] std::uint16_t readPICIRR() noexcept;
|
||||
[[nodiscard]] std::uint16_t readPICISR() noexcept;
|
||||
|
||||
[[nodiscard]] constexpr bool isValidPICOffset(std::uint8_t offset) noexcept
|
||||
{
|
||||
return (offset & 7) == 0;
|
||||
}
|
||||
|
||||
#if defined(__x86_64__)
|
||||
struct InterruptFrame
|
||||
{
|
||||
std::uint64_t ip;
|
||||
std::uint64_t cs;
|
||||
std::uint64_t flags;
|
||||
std::uint64_t sp;
|
||||
std::uint64_t ss;
|
||||
};
|
||||
#endif
|
||||
|
||||
using interrupt_handler_t = __attribute__((interrupt)) void(*)(InterruptFrame*);
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED)
|
||||
159
targets/_any/include/drivers/ps2.hpp
Normal file
159
targets/_any/include/drivers/ps2.hpp
Normal file
@@ -0,0 +1,159 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED)
|
||||
#define BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED
|
||||
|
||||
#include "drivers/pic.hpp"
|
||||
|
||||
namespace baos::ps2
|
||||
{
|
||||
enum class Scancode
|
||||
{
|
||||
INVALID = 0,
|
||||
|
||||
F9 = 0x01,
|
||||
F5 = 0x03,
|
||||
F3 = 0x04,
|
||||
F1 = 0x05,
|
||||
F2 = 0x06,
|
||||
F12 = 0x07,
|
||||
F10 = 0x09,
|
||||
F8 = 0x0A,
|
||||
F6 = 0x0B,
|
||||
F4 = 0x0C,
|
||||
TAB = 0x0D,
|
||||
BACKTICK = 0x0E,
|
||||
LEFT_ALT = 0x11,
|
||||
LEFT_SHIFT = 0x12,
|
||||
LEFT_CONTROL = 0x14,
|
||||
Q = 0x15,
|
||||
_1 = 0x16,
|
||||
Z = 0x1A,
|
||||
S = 0x1B,
|
||||
A = 0x1C,
|
||||
W = 0x1D,
|
||||
_2 = 0x1E,
|
||||
C = 0x21,
|
||||
X = 0x22,
|
||||
D = 0x23,
|
||||
E = 0x24,
|
||||
_4 = 0x25,
|
||||
_3 = 0x26,
|
||||
SPACE = 0x29,
|
||||
V = 0x2A,
|
||||
F = 0x2B,
|
||||
T = 0x2C,
|
||||
R = 0x2D,
|
||||
_5 = 0x2E,
|
||||
N = 0x31,
|
||||
B = 0x32,
|
||||
H = 0x33,
|
||||
G = 0x34,
|
||||
Y = 0x35,
|
||||
_6 = 0x36,
|
||||
M = 0x3A,
|
||||
J = 0x3B,
|
||||
U = 0x3C,
|
||||
_7 = 0x3D,
|
||||
_8 = 0x3E,
|
||||
COMMA = 0x41,
|
||||
K = 0x42,
|
||||
I = 0x43,
|
||||
O = 0x44,
|
||||
_0 = 0x45,
|
||||
_9 = 0x46,
|
||||
DOT = 0x49,
|
||||
SLASH = 0x4A,
|
||||
L = 0x4B,
|
||||
SEMICOLON = 0x4C,
|
||||
P = 0x4D,
|
||||
MINUS = 0x4E,
|
||||
APOSTROPHE = 0x52,
|
||||
BRACKET_OPEN = 0x54,
|
||||
EQUALS = 0x55,
|
||||
CAPSLOCK = 0x58,
|
||||
RIGHT_SHIFT = 0x59,
|
||||
ENTER = 0x5A,
|
||||
BRACKET_CLOSE = 0x5B,
|
||||
BACKSLASH = 0x5D,
|
||||
BACKSPACE = 0x66,
|
||||
KP_1 = 0x69,
|
||||
KP_4 = 0x6B,
|
||||
KP_7 = 0x6C,
|
||||
KP_0 = 0x70,
|
||||
KP_DOT = 0x71,
|
||||
KP_2 = 0x72,
|
||||
KP_5 = 0x73,
|
||||
KP_6 = 0x74,
|
||||
KP_8 = 0x75,
|
||||
ESCAPE = 0x76,
|
||||
NUMLOCK = 0x77,
|
||||
F11 = 0x78,
|
||||
KP_PLUS = 0x79,
|
||||
KP_3 = 0x7A,
|
||||
KP_MINUS = 0x7B,
|
||||
KP_ASTERISK = 0x7C,
|
||||
KP_9 = 0x7D,
|
||||
SCROLLOCK = 0x7E,
|
||||
F7 = 0x83,
|
||||
|
||||
MM_WWW_SEARCH = 0xE010,
|
||||
RIGHT_ALT = 0xE011,
|
||||
RIGHT_CONTROL = 0xE014,
|
||||
MM_PREV_TRACK = 0xE015,
|
||||
LEFT_GUI = 0xE01F,
|
||||
MM_WWW_FAVORITES = 0xE020,
|
||||
MM_VOLUME_DOWN = 0xE021,
|
||||
MM_MUTE = 0xE023,
|
||||
RIGHT_GUI = 0xE027,
|
||||
MM_WWW_STOP = 0xE028,
|
||||
MM_CALCULATOR = 0xE02B,
|
||||
APPS = 0xE02F,
|
||||
MM_WWW_FORWARD = 0xE030,
|
||||
MM_VOLUME_UP = 0xE032,
|
||||
MM_PLAY_PAUSE = 0xE034,
|
||||
ACPI_POWER = 0xE037,
|
||||
MM_WWW_BACK = 0xE038,
|
||||
MM_WWW_HOME = 0xE03A,
|
||||
MM_STOP = 0xE03B,
|
||||
ACPI_SLEEP = 0xE03F,
|
||||
MM_MY_COMPUTER = 0xE040,
|
||||
MM_EMAIL = 0xE048,
|
||||
KP_SLASH = 0xE04A,
|
||||
MM_NEXT_TRACK = 0xE04D,
|
||||
MM_MEDIA_SELECT = 0xE050,
|
||||
KP_ENTER = 0xE05A,
|
||||
ACPI_WAKE = 0xE05E,
|
||||
END = 0xE069,
|
||||
ARROW_LEFT = 0xE06B,
|
||||
HOME = 0xE06C,
|
||||
INSERT = 0xE070,
|
||||
DELETE = 0xE071,
|
||||
ARROW_DOWN = 0xE072,
|
||||
ARROW_RIGHT = 0xE074,
|
||||
ARROW_UP = 0xE075,
|
||||
PAGE_DOWN = 0xE07A,
|
||||
PAGE_UP = 0xE07D,
|
||||
|
||||
PRINT_SCREEN = 0xF000,
|
||||
PAUSE = 0xF001
|
||||
};
|
||||
|
||||
struct KeyEvent
|
||||
{
|
||||
Scancode scancode = Scancode::INVALID;
|
||||
bool down : 1 = false;
|
||||
bool repeat : 1 = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] bool initialize() noexcept;
|
||||
|
||||
__attribute__((interrupt))
|
||||
void isrKeyboard(InterruptFrame* interruptFrame) noexcept;
|
||||
|
||||
[[nodiscard]] bool readKey(KeyEvent& outEvent) noexcept;
|
||||
[[nodiscard]] const char* keyName(Scancode scancode) noexcept;
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user