Files
RedBear-OS/graphics/bgad/src/main.rs
T
bjorn3 e7fe3183b0 Make all pcid_interface methods abort the process on errors
Effectively the only way to recover from errors in the communication
with pcid is by restarting the driver from scratch possibly after
restarting pcid. As such moving the aborts from individual drivers to
pcid_interface simplifies drivers while at the same time allowing nicer
error messages.
2025-03-02 12:36:35 +01:00

65 lines
1.6 KiB
Rust

extern crate orbclient;
extern crate syscall;
use std::fs::File;
use std::io::{Read, Write};
use inputd::ProducerHandle;
use pcid_interface::PciFunctionHandle;
use syscall::call::iopl;
use syscall::data::Packet;
use syscall::scheme::SchemeMut;
use crate::bga::Bga;
use crate::scheme::BgaScheme;
mod bga;
mod scheme;
fn main() {
let pcid_handle = PciFunctionHandle::connect_default();
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_bga");
println!(" + BGA {}", pci_config.func.display());
redox_daemon::Daemon::new(move |daemon| {
unsafe { iopl(3).unwrap() };
let mut socket = File::create(":bga").expect("bgad: failed to create bga scheme");
let mut bga = Bga::new();
println!(" - BGA {}x{}", bga.width(), bga.height());
let mut scheme = BgaScheme {
bga,
display: ProducerHandle::new().ok(),
};
scheme.update_size();
libredox::call::setrens(0, 0).expect("bgad: failed to enter null namespace");
daemon.ready().expect("bgad: failed to notify parent");
loop {
let mut packet = Packet::default();
if socket
.read(&mut packet)
.expect("bgad: failed to read events from bga scheme")
== 0
{
break;
}
scheme.handle(&mut packet);
socket
.write(&packet)
.expect("bgad: failed to write responses to bga scheme");
}
std::process::exit(0);
})
.expect("bgad: failed to daemonize");
}