Compare commits

..

3 commits

Author SHA1 Message Date
Talha Qamar 501e2f5cb5 work 2024-09-01 14:21:48 +05:00
koniifer 58bc6facbc Merge remote-tracking branch 'origin/kodin/keyboard-driver' 2024-08-30 14:55:22 +01:00
koniifer ad85f82be3 begin work for fb_driver interface
create hardware rng buffer & stn.random.uint_64 (currently weird)
move examples out of fb_driver (currently broken)
remove literal kernel panic from `info!("AHHH")`
re-implement stn.buffer.send_message()
2024-08-29 21:37:49 +01:00
18 changed files with 192 additions and 35 deletions

View file

@ -131,6 +131,10 @@ pub fn handler(vm: &mut Vm) {
_ => {}
}
}
// source of rng
4 => {
vm.registers[1] = hbvm::value::Value(crate::arch::hardware_random_u64());
}
buffer_id => {
let mut buffs = IPC_BUFFERS.lock();
match buffs.get_mut(&buffer_id) {
@ -167,7 +171,7 @@ pub fn handler(vm: &mut Vm) {
if buffs.get_mut(&buffer_id).is_some() {
buff = buffs.get_mut(&buffer_id).unwrap();
} else {
info!("AHHH");
// info!("AHHH");
vm.registers[1] = hbvm::value::Value(0);
return;
}
@ -205,7 +209,6 @@ pub fn handler(vm: &mut Vm) {
vm.registers[3] = x
}
}
// 5
_ => {
log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers);
}

View file

@ -0,0 +1 @@
software := @use("rel:software.hb")

View file

@ -0,0 +1,16 @@
.{buffer} := @use("../../stn/src/lib.hb")
test := fn(): int {
buffer_id := buffer.search("XGraphics\0")
msg := "\0"
buffer.send_message(msg, buffer_id)
return 0
}
put_pixel := fn(): int {
return 0
}
sync := fn(): int {
return 0
}

View file

@ -4,8 +4,9 @@ receive_message := fn(buffer_id: int, memory_map_location: ^u8, length: int): ^u
return @eca(^u8, 4, buffer_id, memory_map_location, length)
}
send_message := fn(buffer_id: int, message: ^u8, message_length: int): void {
@eca(i32, 3, buffer_id, message, message_length)
send_message := fn(msg: ^u8, buffer_id: int): void {
msg_length := string.length(msg)
@eca(i32, 3, buffer_id, msg, msg_length)
return
}

View file

@ -2,4 +2,5 @@ string := @use("rel:string.hb")
log := @use("rel:log.hb")
memory := @use("rel:memory.hb")
buffer := @use("rel:buffer.hb")
math := @use("rel:math.hb")
math := @use("rel:math.hb")
random := @use("rel:random.hb")

View file

@ -0,0 +1,8 @@
uint_64 := fn(min: uint, max: uint): uint {
rng := @eca(uint, 3, 4)
if min != 0 | max != 0 {
return rng % (max - min + 1) + min
}
return rng
}

View file

@ -1,7 +1,20 @@
// change "lines.hb" to another example to see it onscreen
example := @use("examples/lines.hb").example
.{log, memory, string, buffer} := @use("../../../libraries/stn/src/lib.hb");
.{front_buffer_ptr, screenidx, ColorBGRA, Point} := @use("./lib.hb")
main := fn(): int {
example()
buffer_id := buffer.create("XGraphics\0")
memmap := memory.request_page(1)
x := 0
loop {
msg := buffer.receive_message(buffer_id, memmap, 0)
if msg != 0 {
log.info("Hello, Framebuffer!\0")
}
loop if x == 4096 {
*(memmap + x) = 0
x += 1
}
x = 0
}
return 0
}

View file

@ -0,0 +1,11 @@
[package]
name = "fb_driver_stresstest"
authors = ["aurlex"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -0,0 +1,6 @@
.{test, put_pixel, sync} := @use("../../../libraries/render/src/lib.hb").software
main := fn(): int {
test()
return 0
}

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,31 +1,28 @@
.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb")
send_byte := fn(byte: u8): u8 {
memory.outb(0, 96, byte)
input := memory.inb(0, 96)
return input
}
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()
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(buf, keycode_str, string.length(keycode_str))
}
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
}

View file

@ -19,11 +19,12 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.tests]
# path = "boot:///tests.hbf"
[boot.limine.ableos.modules.a_serial_driver]
path = "boot:///a_serial_driver.hbf"
[boot.limine.ableos.modules.ps2_driver]
path = "boot:///ps2_driver.hbf"
path = "boot:///ps2_driver.hbf"
[boot.limine.ableos.modules.diskio_driver]
path = "boot:///diskio_driver.hbf"
@ -31,6 +32,8 @@ path = "boot:///diskio_driver.hbf"
[boot.limine.ableos.modules.fb_driver]
path = "boot:///fb_driver.hbf"
[boot.limine.ableos.modules.serial_driver_test]
path = "boot:///serial_driver_test.hbf"
[boot.limine.ableos.modules.fb_driver_stresstest]
path = "boot:///fb_driver_stresstest.hbf"