Compare commits
32 commits
Author | SHA1 | Date | |
---|---|---|---|
peony | 5028062e39 | ||
peony | f7f9fece4f | ||
peony | f4ceab972c | ||
peony | 96c07e137b | ||
peony | d78878a12f | ||
peony | 8f265ebf40 | ||
peony | 3d5a8f6f10 | ||
peony | f11122e58e | ||
peony | 2fdede7199 | ||
peony | 13422dfd9f | ||
peony | 90a97cd160 | ||
peony | 23b45b1887 | ||
peony | cf37eaf086 | ||
peony | 284aa5a5e6 | ||
peony | 11976b752f | ||
peony | 98b15d4c10 | ||
peony | f5c6d7d822 | ||
peony | efcd6c0631 | ||
peony | b795aced8e | ||
peony | 08099b0877 | ||
peony | a1bfd8e85f | ||
peony | edfb588060 | ||
peony | cc4a32afaa | ||
peony | be6a095c14 | ||
peony | aac1164d55 | ||
peony | 89d08d8a62 | ||
peony | 8f5833955f | ||
peony | 4c0adbe15d | ||
peony | 3708acc077 | ||
peony | b5b122f451 | ||
peony | 39ebaa03ba | ||
peony | de8000f596 |
23
sysdata/programs/ps2_driver/README.md
Normal file
23
sysdata/programs/ps2_driver/README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Unified PS/2 Driver
|
||||
|
||||
Te entire thing is held together inspite
|
||||
|
||||
## !!Assumptions!!
|
||||
Anyone who works on this should work to keep this list as small as possible/remove as many of these as possible.
|
||||
- Bit 5 of the response form 0x64 indicates which port the data is coming from. (Not true on all systems)
|
||||
- A parity or timeout error never occurs.
|
||||
- PS/2 controller exists.
|
||||
- Both PS/2 ports being broken doesn't need handling.
|
||||
- One PS/2 port being broken doesn't need special attention.
|
||||
- PS/2 controller doesn't need to perform a self-check.
|
||||
- These DeviceIDs never exist:
|
||||
- 0xFFFD
|
||||
- 0xFFFE
|
||||
- 0xFFFF
|
||||
- 0x01xx
|
||||
- 0x03xx
|
||||
- 0x04xx
|
||||
- Literally all PS/2 keyboards can be handeled the exact same way. We have the capability for detecting different keyboard types, I just don't bother with it because that would litreally take months to get working.
|
||||
- The device doesn't send any data while we're waiting for an `ACK`.
|
||||
|
||||
Supporting mice in the keyboard port and vice versa was a ***bad*** idea, but I do not regret it because it means we're "superior" to real world operating systems.
|
11
sysdata/programs/ps2_driver/meta.toml
Normal file
11
sysdata/programs/ps2_driver/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "ps2_driver"
|
||||
authors = ["Peony"]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
26
sysdata/programs/ps2_driver/src/bits.hb
Normal file
26
sysdata/programs/ps2_driver/src/bits.hb
Normal file
|
@ -0,0 +1,26 @@
|
|||
//Do not question.
|
||||
|
||||
$bit0 := fn(value: u8): bool {
|
||||
return (value & 0x1) > 0
|
||||
}
|
||||
$bit1 := fn(value: u8): bool {
|
||||
return (value & 0x2) > 0
|
||||
}
|
||||
$bit2 := fn(value: u8): bool {
|
||||
return (value & 0x4) > 0
|
||||
}
|
||||
$bit3 := fn(value: u8): bool {
|
||||
return (value & 0x8) > 0
|
||||
}
|
||||
$bit4 := fn(value: u8): bool {
|
||||
return (value & 0x10) > 0
|
||||
}
|
||||
$bit5 := fn(value: u8): bool {
|
||||
return (value & 0x20) > 0
|
||||
}
|
||||
$bit6 := fn(value: u8): bool {
|
||||
return (value & 0x40) > 0
|
||||
}
|
||||
$bit7 := fn(value: u8): bool {
|
||||
return (value & 0x80) > 0
|
||||
}
|
95
sysdata/programs/ps2_driver/src/controller.hb
Normal file
95
sysdata/programs/ps2_driver/src/controller.hb
Normal file
|
@ -0,0 +1,95 @@
|
|||
.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb");
|
||||
.{Port, PORT_AT_STARTUP} := @use("port.hb")
|
||||
|
||||
port1 := @as(Port, PORT_AT_STARTUP)
|
||||
port2 := @as(Port, PORT_AT_STARTUP)
|
||||
|
||||
$disable_port1 := fn(): void memory.outb(0x64, 0xAD)
|
||||
$enable_port1 := fn(): void memory.outb(0x64, 0xAE)
|
||||
$disable_port2 := fn(): void memory.outb(0x64, 0xA7)
|
||||
$enable_port2 := fn(): void memory.outb(0x64, 0xA8)
|
||||
|
||||
test_port1 := fn(): bool {
|
||||
memory.outb(0x64, 0xAB)
|
||||
loop if has_input(get_info()) break
|
||||
input := get_input()
|
||||
return input == 0x0
|
||||
}
|
||||
|
||||
test_port2 := fn(): bool {
|
||||
memory.outb(0x64, 0xA9)
|
||||
loop if has_input(get_info()) break
|
||||
input := get_input()
|
||||
return input == 0x0
|
||||
}
|
||||
|
||||
get_config_byte := fn(): u8 {
|
||||
memory.outb(0x64, 0x20)
|
||||
loop if has_input(get_info()) break
|
||||
return get_input()
|
||||
}
|
||||
|
||||
Info := struct {d: u8}
|
||||
|
||||
$get_info := fn(): Info return .(memory.inb(0x64))
|
||||
//inline when can
|
||||
has_input := fn(info: Info): bool return bit0(info.d)
|
||||
can_send := fn(info: Info): bool return bit1(info.d) == false
|
||||
timed_out := fn(info: Info): bool return bit6(info.d)
|
||||
check_parity := fn(info: Info): bool return bit7(info.d)
|
||||
get_port := fn(info: Info): ^Port {
|
||||
if bit5(info.d) {
|
||||
return &port2
|
||||
} else {
|
||||
return &port1
|
||||
}
|
||||
}
|
||||
|
||||
send_byte := fn(port: ^Port, byte: u8): void {
|
||||
if port == &port2 {
|
||||
memory.outb(0x64, 0xD4)
|
||||
}
|
||||
loop if can_send(get_info()) break
|
||||
memory.outb(0x60, byte)
|
||||
}
|
||||
|
||||
$get_input := fn(): u8 return memory.inb(0x60)
|
||||
$write_out := fn(data: u8): void memory.outb(0x60, data)
|
||||
|
||||
flush_input := fn(): void {
|
||||
loop if has_input(get_info()) == false break else get_info()
|
||||
}
|
||||
|
||||
init := fn(): void {
|
||||
disable_port1()
|
||||
disable_port2()
|
||||
//Disables ports to make sure that they won't interfere with the setup process.
|
||||
|
||||
flush_input()
|
||||
|
||||
enable_port2()
|
||||
port2.exists = bit5(@inline(get_config_byte)) == false
|
||||
disable_port2()
|
||||
|
||||
flush_input()
|
||||
|
||||
port1.exists = test_port1()
|
||||
|
||||
if port2.exists {
|
||||
port2.exists = test_port2()
|
||||
}
|
||||
|
||||
if (port1.exists | port2.exists) == false {
|
||||
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
|
||||
}
|
||||
|
||||
if port1.exists {
|
||||
log.info("Port 1 exists.\0")
|
||||
enable_port1()
|
||||
}
|
||||
if port2.exists {
|
||||
log.info("Port 2 exists.\0")
|
||||
enable_port2()
|
||||
}
|
||||
}
|
15
sysdata/programs/ps2_driver/src/devices.hb
Normal file
15
sysdata/programs/ps2_driver/src/devices.hb
Normal file
|
@ -0,0 +1,15 @@
|
|||
DeviceID := struct {value: u16}
|
||||
|
||||
$MOUSE_3_BUTTON := DeviceID.(0x0)
|
||||
$MOUSE_SCROLLWHEEL := DeviceID.(0x3)
|
||||
$MOUSE_5_BUTTON := DeviceID.(0x4)
|
||||
$KEYBOARD_SPACESAVER := DeviceID.(0x84AB)
|
||||
$KEYBOARD_122_KEY := DeviceID.(0x86AB)
|
||||
$KEYBOARD_JAPANESE_G := DeviceID.(0x90AB)
|
||||
$KEYBOARD_JAPANESE_P := DeviceID.(0x91AB)
|
||||
$KEYBOARD_JAPANESE_A := DeviceID.(0x92AB)
|
||||
$KEYBOARD_NCD_SUN := DeviceID.(0xA1AC)
|
||||
|
||||
$MOUSE_INIT_1 := DeviceID.(0xFFFD)
|
||||
$MOUSE_INIT_2 := DeviceID.(0xFFFE)
|
||||
$NO_DEVICE := DeviceID.(0xFFFF)
|
152
sysdata/programs/ps2_driver/src/main.hb
Normal file
152
sysdata/programs/ps2_driver/src/main.hb
Normal file
|
@ -0,0 +1,152 @@
|
|||
.{memory, log, buffer, string} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{MouseEvent} := @use("../../../libraries/intouch/src/lib.hb").events;
|
||||
.{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb")
|
||||
devices := @use("devices.hb")
|
||||
controller := @use("controller.hb");
|
||||
.{Info, Port} := controller
|
||||
mouse := @use("mouse.hb")
|
||||
format_page := memory.dangling(u8)
|
||||
|
||||
mouse_buffer := 0
|
||||
keyboard_buffer := 0
|
||||
info := Info.(0)
|
||||
|
||||
send_command := fn(port: ^Port, byte: u8): void {
|
||||
tries := 3
|
||||
loop if tries == 0 break else {
|
||||
controller.send_byte(port, byte)
|
||||
loop {
|
||||
info = controller.get_info()
|
||||
if controller.has_input(info) == false {
|
||||
continue
|
||||
}
|
||||
input := controller.get_input()
|
||||
if controller.get_port(info) != port {
|
||||
if check_complete(port) == false {
|
||||
port.packet[port.packet_length] = input
|
||||
port.packet_length += 1
|
||||
}
|
||||
continue
|
||||
}
|
||||
if input == 0xFA {
|
||||
return
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
tries -= 1
|
||||
}
|
||||
}
|
||||
|
||||
enable_streaming := fn(port: ^Port): void {
|
||||
@inline(send_command, port, 0xF4)
|
||||
}
|
||||
|
||||
process := fn(port: ^controller.Port): void {
|
||||
if port.device.value < devices.MOUSE_5_BUTTON.value {
|
||||
event := MouseEvent.(0, 0, false, false, false)
|
||||
|
||||
event.left = bit0(port.packet[0])
|
||||
event.right = bit1(port.packet[0])
|
||||
event.middle = bit2(port.packet[0])
|
||||
|
||||
event.x_change = @intcast(port.packet[1])
|
||||
event.y_change = @intcast(port.packet[2])
|
||||
|
||||
buffer.write(MouseEvent, mouse_buffer, &event)
|
||||
} else if port.device == devices.MOUSE_INIT_1 {
|
||||
port.device.value = port.packet[0]
|
||||
if port.device != devices.MOUSE_SCROLLWHEEL {
|
||||
enable_streaming(port)
|
||||
return
|
||||
}
|
||||
port.device = devices.MOUSE_INIT_2
|
||||
} else if port.device == devices.MOUSE_INIT_2 {
|
||||
port.device.value = port.packet[0]
|
||||
} else if port.device == devices.NO_DEVICE {
|
||||
if port.packet_length == 1 {
|
||||
port.device.value = port.packet[0]
|
||||
enable_streaming(port)
|
||||
//TODO: Upgrade mouse.
|
||||
} else {
|
||||
port.device.value = port.packet[1] | port.packet[0] << 8
|
||||
enable_streaming(port)
|
||||
}
|
||||
log.info("Identified device!\0")
|
||||
log.info(string.display_int(port.device.value, format_page, 16))
|
||||
} else {
|
||||
log.info("KEY PRESSED\0")
|
||||
}
|
||||
}
|
||||
|
||||
check_complete := fn(port: ^controller.Port): bool {
|
||||
last_value := port.packet[port.packet_length - 1]
|
||||
if port.device == devices.NO_DEVICE {
|
||||
if last_value == 0 | last_value == 3 | last_value == 4 {
|
||||
return true
|
||||
} else if port.packet_length == 2 {
|
||||
return true
|
||||
}
|
||||
} else if port.device == devices.MOUSE_3_BUTTON {
|
||||
if port.packet_length == 3 return true
|
||||
} else if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON {
|
||||
if port.packet_length == 4 return true
|
||||
} else {
|
||||
if port.packet[0] == 0xE1 {
|
||||
if port.packet_length == 6 {
|
||||
return true
|
||||
}
|
||||
} else if port.packet[0] != 0xE0 {
|
||||
return true
|
||||
} else if port.packet_length == 2 & port.packet[1] != 0x2A & port.packet[1] != 0xB7 {
|
||||
return true
|
||||
} else if port.packet_length == 4 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
main := fn(): void {
|
||||
mouse_buffer = buffer.create("PS/2 Mouse\0")
|
||||
format_page = memory.alloc(u8, 1024)
|
||||
|
||||
controller.init()
|
||||
|
||||
if controller.port1.exists {
|
||||
//log.info("Port 1 exists.\0")
|
||||
controller.send_byte(@bitcast(0), 0xF4)
|
||||
}
|
||||
if controller.port2.exists {
|
||||
//controller.send_byte(&controller.port2, 0xF4)
|
||||
}
|
||||
|
||||
loop {
|
||||
info = controller.get_info()
|
||||
|
||||
if controller.timed_out(info) {
|
||||
log.error("Timeout error! Cannot handle these!\0")
|
||||
}
|
||||
if controller.check_parity(info) {
|
||||
log.error("Parity error! Cannot handle these!\0")
|
||||
}
|
||||
/*
|
||||
if controller.has_input(info) {
|
||||
port := controller.get_port(info)
|
||||
if port.packet_length > 0 & check_complete(port) {
|
||||
process(port)
|
||||
}
|
||||
input := controller.get_input()
|
||||
/*if input == 0xAA & port.can_hot_plug {
|
||||
port.device = devices.NO_DEVICE
|
||||
controller.send_byte(port, 0xF4)
|
||||
}*/
|
||||
port.packet[port.packet_length] = input
|
||||
port.packet_length += 1
|
||||
if check_complete(port) {
|
||||
process(port)
|
||||
port.packet_length = 0
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
|
@ -0,0 +1,21 @@
|
|||
Button := struct {id: u8}
|
||||
$LEFT_BUTTON := Button.(1)
|
||||
$RIGHT_BUTTON := Button.(2)
|
||||
$MIDDLE_BUTTON := Button.(4)
|
||||
$BUTTON4 := Button.(8)
|
||||
$BUTTON5 := Button.(16)
|
||||
|
||||
SampleRate := struct {value: u8}
|
||||
$SR10 := SampleRate.(10)
|
||||
$SR20 := SampleRate.(20)
|
||||
$SR40 := SampleRate.(40)
|
||||
$SR60 := SampleRate.(60)
|
||||
$SR80 := SampleRate.(80)
|
||||
$SR100 := SampleRate.(100)
|
||||
$SR200 := SampleRate.(200)
|
||||
|
||||
Resolution := struct {value: u8}
|
||||
$RES_1COUNT_PER_MM := Resolution.(0)
|
||||
$RES_2COUNT_PER_MM := Resolution.(1)
|
||||
$RES_4COUNT_PER_MM := Resolution.(2)
|
||||
$RES_8COUNT_PER_MM := Resolution.(3)
|
21
sysdata/programs/ps2_driver/src/port.hb
Normal file
21
sysdata/programs/ps2_driver/src/port.hb
Normal file
|
@ -0,0 +1,21 @@
|
|||
.{DeviceID, NO_DEVICE} := @use("devices.hb")
|
||||
|
||||
State := struct {s: u8}
|
||||
$Recive := State.(0)
|
||||
$Reboot := State.(1)
|
||||
|
||||
Port := packed struct {
|
||||
exists: bool,
|
||||
device: DeviceID,
|
||||
packet: [u8; 8],
|
||||
packet_length: u8,
|
||||
can_hot_plug: bool,
|
||||
}
|
||||
|
||||
$PORT_AT_STARTUP := Port.(
|
||||
true,
|
||||
NO_DEVICE,
|
||||
.(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
0,
|
||||
true,
|
||||
)
|
|
@ -28,20 +28,17 @@ resolution = "1024x768x24"
|
|||
# [boot.limine.ableos.modules.horizon]
|
||||
# path = "boot:///horizon.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
path = "boot:///ps2_mouse_driver.hbf"
|
||||
# [boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
# path = "boot:///ps2_mouse_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.sunset_client]
|
||||
path = "boot:///sunset_client.hbf"
|
||||
[boot.limine.ableos.modules.ps2_driver]
|
||||
path = "boot:///ps2_driver.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.sunset_client_2]
|
||||
path = "boot:///sunset_client_2.hbf"
|
||||
# [boot.limine.ableos.modules.sunset_client]
|
||||
# path = "boot:///sunset_client.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.sunset_server]
|
||||
path = "boot:///sunset_server.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.processes]
|
||||
# path = "boot:///processes.hbf"
|
||||
# [boot.limine.ableos.modules.sunset_server]
|
||||
# path = "boot:///sunset_server.hbf"
|
||||
|
|
Loading…
Reference in a new issue