1
0
Fork 0
forked from koniifer/ableos
This commit is contained in:
Talha Qamar 2024-09-01 14:21:48 +05:00
parent 58bc6facbc
commit 501e2f5cb5
2 changed files with 119 additions and 24 deletions

View file

@ -0,0 +1,97 @@
.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb")
init := fn(): void {
send_byte_to_controller(173)
send_byte_to_controller(167)
// flush output buffer
memory.inb(0, 96)
send_byte_to_controller(32)
config_byte := read_byte()
log.info("What\0")
// TODO: We just assume there's a second device here and set up the
// controller as such. We should probably look for the second device FIRST
// The OSWiki has a page about this
// https://wiki.osdev.org/%228042%22_PS/2_Controller#Step_7:_Determine_If_There_Are_2_Channels
config_byte &= 32
send_byte_to_controller(96)
send_byte(config_byte)
if perform_self_test() {
log.info("PS/2 Controller self test successful\0")
send_byte_to_controller(171)
if read_byte() != 0 {
log.error("PS/2 First port test failed\0")
}
send_byte_to_controller(169)
if read_byte() != 0 {
log.error("PS/2 Second port test failed\0")
}
} else {
log.error("PS/2 Controller self test failed\0")
}
return
}
perform_self_test := fn(): bool {
send_byte_to_controller(32)
config_byte := read_byte()
send_byte_to_controller(170)
response := read_byte()
send_byte_to_controller(96)
send_byte(config_byte)
return response == 85
}
send_byte_to_controller := fn(byte: u8): void {
loop {
status := memory.inb(0, 100)
// Bitwise OR with 1011 1111
// If the second bit was set in the status register,
// status is now equal to 255
status |= 191
if status != 255 {
memory.outb(0, 100, byte)
break
}
}
return
}
send_byte := fn(byte: u8): void {
loop {
status := memory.inb(0, 100)
// Bitwise OR with 1011 1111
// If the second bit was set in the status register,
// status is now equal to 255
status |= 191
if status != 255 {
memory.outb(0, 96, byte)
break
}
}
return
}
read_byte := fn(): u8 {
ptr := memory.request_page(1)
loop {
status := memory.inb(0, 100)
// Bitwise OR with 0111 1111
// If the first bit was set in the status register,
// status is now equal to 255
status |= 127
str := string.display_int(status, ptr)
log.info(ptr)
if status == 255 {
return memory.inb(0, 96)
}
}
}

View file

@ -1,30 +1,28 @@
.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb")
send_byte := fn(byte: u8): u8 {
memory.outb(0, 96, byte)
return memory.inb(0, 96)
}
controller := @use("./controller.hb")
main := fn(): int {
log.info("PS/2 Driver Loaded\0")
if send_byte(238) == 238 {
log.info("PS/2 Keyboard Echoed\0")
}
if send_byte(244) == 250 {
log.info("Enabled scanning\0")
}
buf := buffer.create("XKeyboard\0")
ptr := memory.request_page(1)
prev_input := 250
loop {
input := memory.inb(0, 96)
if input == prev_input {
continue
}
prev_input = input
keycode_str := string.display_int(input, ptr)
log.info(string.display_int(buf))
buffer.send_message(keycode_str, buf)
}
controller.init()
return 0
// if send_byte(238) == 238 {
// log.info("PS/2 Keyboard Echoed\0")
// }
// if send_byte(244) == 250 {
// log.info("Enabled scanning\0")
// }
// buf := buffer.create("XKeyboard\0")
// ptr := memory.request_page(1)
// prev_input := 250
// loop {
// input := memory.inb(0, 96)
// if input == prev_input {
// continue
// }
// prev_input = input
// keycode_str := string.display_int(input, ptr)
// log.info(string.display_int(buf))
// buffer.send_message(keycode_str, buf)
// }
// return 0
}