Change formatting rules
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m7s
Build documentation / build-and-deploy (push) Successful in 39s

This commit is contained in:
2026-04-24 01:54:48 +02:00
parent 34f7809a2d
commit c8fb575bdd
208 changed files with 6310 additions and 6339 deletions

View File

@@ -108,16 +108,16 @@ static uint8_t ctlmap[256] = {
/* clang-format on */
};
static int32_t ps2kb_keycode (void) {
static int32_t ps2kb_keycode(void) {
static uint8_t shift;
static uint8_t* charcode[4] = {normalmap, shiftmap, ctlmap, ctlmap};
uint32_t st, data, c;
st = inb (KB_CTL_STATUS);
st = inb(KB_CTL_STATUS);
if (!(st & KB_DATA_IN_BUF)) {
return -1;
}
data = inb (KB_DATA);
data = inb(KB_DATA);
if (data == 0xe0) {
shift |= KB_E0ESC;
@@ -145,38 +145,38 @@ static int32_t ps2kb_keycode (void) {
return c;
}
static void ps2kb_irq (void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
static void ps2kb_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
(void)arg, (void)regs, (void)user;
uint64_t frb, fsq;
int32_t keycode = ps2kb_keycode ();
int32_t keycode = ps2kb_keycode();
if (keycode <= 0 || keycode == 0xFA)
return;
spin_lock (&ps2kb_ringbuffer_lock, &frb);
spin_lock (&ps2kb_sq.lock, &fsq);
spin_lock(&ps2kb_ringbuffer_lock, &frb);
spin_lock(&ps2kb_sq.lock, &fsq);
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
ringbuffer_push(uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
struct list_node_link* node = ps2kb_sq.proc_list;
if (node != NULL) {
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
struct proc* resumed_proc = sq_entry->proc;
spin_unlock (&ps2kb_sq.lock, fsq);
spin_unlock (&ps2kb_ringbuffer_lock, frb);
spin_unlock(&ps2kb_sq.lock, fsq);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
proc_sq_resume (resumed_proc, sq_entry, rctx);
proc_sq_resume(resumed_proc, sq_entry, rctx);
return;
}
spin_unlock (&ps2kb_sq.lock, fsq);
spin_unlock (&ps2kb_ringbuffer_lock, frb);
spin_unlock(&ps2kb_sq.lock, fsq);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
}
DEFINE_DEVICE_OP (ps2kb_read_key) {
DEFINE_DEVICE_OP(ps2kb_read_key) {
uint64_t frb, fsq;
uint8_t* chbuf = (uint8_t*)a1;
@@ -184,74 +184,74 @@ DEFINE_DEVICE_OP (ps2kb_read_key) {
if (chbuf == NULL)
return -ST_BAD_ADDRESS_SPACE;
spin_lock (&ps2kb_ringbuffer_lock, &frb);
spin_lock(&ps2kb_ringbuffer_lock, &frb);
size_t prev_count = ps2kb_ringbuffer.count;
ringbuffer_pop (uint8_t, &ps2kb_ringbuffer, chbuf);
ringbuffer_pop(uint8_t, &ps2kb_ringbuffer, chbuf);
size_t new_count = ps2kb_ringbuffer.count;
/* didn't pop anything */
if (prev_count == new_count) {
spin_lock (&ps2kb_sq.lock, &fsq);
spin_lock(&ps2kb_sq.lock, &fsq);
struct list_node_link* node = ps2kb_sq.proc_list;
spin_unlock (&ps2kb_sq.lock, fsq);
spin_unlock(&ps2kb_sq.lock, fsq);
if (node != NULL) {
spin_unlock (&ps2kb_ringbuffer_lock, frb);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
return -ST_PERMISSION_ERROR;
}
proc_sq_suspend (proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, frb, rctx, NULL, NULL);
proc_sq_suspend(proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, frb, rctx, NULL, NULL);
return ST_OK;
}
spin_unlock (&ps2kb_ringbuffer_lock, frb);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
return ST_OK;
}
static void ps2kb_set_typematic (uint8_t delay, uint8_t rate) {
while (inb (KB_CTL_STATUS) & 0x02)
static void ps2kb_set_typematic(uint8_t delay, uint8_t rate) {
while (inb(KB_CTL_STATUS) & 0x02)
;
outb (KB_DATA, 0xF3);
outb(KB_DATA, 0xF3);
while (inb (KB_CTL_STATUS) & 0x02)
while (inb(KB_CTL_STATUS) & 0x02)
;
outb (KB_DATA, (delay << 5) | (rate & 0x1F));
outb(KB_DATA, (delay << 5) | (rate & 0x1F));
}
DEFINE_DEVICE_INIT (ps2kb_init) {
ioapic_route_irq (INTR_PS2KB, 1, 0, thiscpu->lapic_id);
irq_attach (&ps2kb_irq, NULL, INTR_PS2KB);
DEFINE_DEVICE_INIT(ps2kb_init) {
ioapic_route_irq(INTR_PS2KB, 1, 0, thiscpu->lapic_id);
irq_attach(&ps2kb_irq, NULL, INTR_PS2KB);
ringbuffer_init (&ps2kb_ringbuffer, PS2KB_RINGBUFFER_MAX, sizeof (uint8_t));
ringbuffer_init(&ps2kb_ringbuffer, PS2KB_RINGBUFFER_MAX, sizeof(uint8_t));
while (inb (KB_CTL_STATUS) & KB_DATA_IN_BUF)
inb (KB_DATA);
while (inb(KB_CTL_STATUS) & KB_DATA_IN_BUF)
inb(KB_DATA);
outb (KB_CTL_STATUS, 0x20);
outb(KB_CTL_STATUS, 0x20);
uint8_t cb = inb (KB_DATA);
uint8_t cb = inb(KB_DATA);
cb |= 0x01;
cb |= 0x40;
outb (KB_CTL_STATUS, 0x60);
outb (KB_DATA, cb);
outb(KB_CTL_STATUS, 0x60);
outb(KB_DATA, cb);
/* 250ms delay, 30hz rate */
ps2kb_set_typematic (0x00, 0x00);
ps2kb_set_typematic(0x00, 0x00);
return true;
}
DEFINE_DEVICE_FINI (ps2kb_fini) {
DEFINE_DEVICE_FINI(ps2kb_fini) {
(void)device, (void)proc, (void)rctx;
irq_detach (INTR_PS2KB);
ringbuffer_fini (&ps2kb_ringbuffer);
irq_detach(INTR_PS2KB);
ringbuffer_fini(&ps2kb_ringbuffer);
}

View File

@@ -9,10 +9,10 @@
struct device;
DEFINE_DEVICE_OP (ps2kb_read_key);
DEFINE_DEVICE_OP(ps2kb_read_key);
DEFINE_DEVICE_INIT (ps2kb_init);
DEFINE_DEVICE_INIT(ps2kb_init);
DEFINE_DEVICE_FINI (ps2kb_fini);
DEFINE_DEVICE_FINI(ps2kb_fini);
#endif // _KERNEL_DEVICE_PS2_KB_H