Suspend process waiting for keyboard input
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m35s
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
#define _KERNEL_DEVICE_DEVICE_H
|
||||
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
typedef int (*device_op_func_t) (struct proc* proc, void* a1, void* a2, void* a3, void* a4);
|
||||
typedef bool (*device_op_func_t) (struct proc* proc, struct cpu** reschedule_cpu, int* ret,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
struct device {
|
||||
int id;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <m/status.h>
|
||||
#include <proc/capability.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/suspension_q.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/smp.h>
|
||||
@@ -41,6 +42,7 @@
|
||||
|
||||
static struct ringbuffer ps2kb_ringbuffer;
|
||||
static spin_lock_t ps2kb_ringbuffer_lock = SPIN_LOCK_INIT;
|
||||
static struct proc_suspension_q ps2kb_sq;
|
||||
|
||||
static uint8_t shiftcode[0x100] = {
|
||||
[0x1d] = KB_CTL, [0x2a] = KB_SHIFT, [0x36] = KB_SHIFT,
|
||||
@@ -161,35 +163,61 @@ int32_t ps2kb_keycode (void) {
|
||||
return c;
|
||||
}
|
||||
|
||||
void ps2kb_irq (void* arg, void* regs) {
|
||||
bool ps2kb_irq (struct cpu** reschedule_cpu, void* arg, void* regs) {
|
||||
int32_t keycode = ps2kb_keycode ();
|
||||
|
||||
if (keycode >= 0) {
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
if (keycode <= 0)
|
||||
return PROC_NO_RESCHEDULE;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
spin_lock (&ps2kb_sq.lock);
|
||||
|
||||
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
|
||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||
|
||||
if (node) {
|
||||
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);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return proc_sq_resume (resumed_proc, sq_entry, reschedule_cpu);
|
||||
}
|
||||
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
int ps2kb_read_key (struct proc* proc, void* a1, void* a2, void* a3, void* a4) {
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_KB))
|
||||
return -ST_PERMISSION_ERROR;
|
||||
bool ps2kb_read_key (struct proc* proc, struct cpu** reschedule_cpu, int* ret, void* a1, void* a2,
|
||||
void* a3, void* a4) {
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_KB)) {
|
||||
*ret = -ST_PERMISSION_ERROR;
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
uint8_t* chbuf = (uint8_t*)a1;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
size_t prev_count = ps2kb_ringbuffer.count;
|
||||
|
||||
ringbuffer_pop (uint8_t, &ps2kb_ringbuffer, chbuf);
|
||||
|
||||
size_t new_count = ps2kb_ringbuffer.count;
|
||||
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
*ret = ST_OK;
|
||||
|
||||
/* didn't pop anything */
|
||||
if (prev_count == new_count)
|
||||
return -ST_TRY_AGAIN;
|
||||
return proc_sq_suspend (proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, reschedule_cpu);
|
||||
|
||||
return ST_OK;
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
bool ps2kb_init (void* arg) {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef _KERNEL_DEVICE_PS2_KB_H
|
||||
#define _KERNEL_DEVICE_PS2_KB_H
|
||||
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
int ps2kb_read_key (struct proc* proc, void* a1, void* a2, void* a3, void* a4);
|
||||
bool ps2kb_read_key (struct proc* proc, struct cpu** reschedule_cpu, int* ret, void* a1, void* a2,
|
||||
void* a3, void* a4);
|
||||
bool ps2kb_init (void* arg);
|
||||
void ps2kb_fini (void);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <proc/capability.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
struct flanterm_context* ft_ctx;
|
||||
|
||||
@@ -34,19 +35,25 @@ bool terminal_init (void* arg) {
|
||||
|
||||
void terminal_fini (void) {}
|
||||
|
||||
int terminal_putstr (struct proc* proc, void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)a2, (void)a3, (void)a4;
|
||||
bool terminal_putstr (struct proc* proc, struct cpu** reschedule_cpu, int* ret, void* a1, void* a2,
|
||||
void* a3, void* a4) {
|
||||
(void)reschedule_cpu, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_TERMINAL))
|
||||
return -ST_PERMISSION_ERROR;
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_TERMINAL)) {
|
||||
*ret = -ST_PERMISSION_ERROR;
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
char* string = (char*)a1;
|
||||
size_t* len = (size_t*)a2;
|
||||
|
||||
if (string == NULL || len == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
if (string == NULL || len == NULL) {
|
||||
*ret = -ST_BAD_ADDRESS_SPACE;
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
flanterm_write (ft_ctx, string, *len);
|
||||
|
||||
return ST_OK;
|
||||
*ret = ST_OK;
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#ifndef _KERNEL_DEVICE_TERMINAL_H
|
||||
#define _KERNEL_DEVICE_TERMINAL_H
|
||||
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
bool terminal_init (void* arg);
|
||||
void terminal_fini (void);
|
||||
int terminal_putstr (struct proc* proc, void* a1, void* a2, void* a3, void* a4);
|
||||
bool terminal_putstr (struct proc* proc, struct cpu** reschedule_cpu, int* ret, void* a1, void* a2,
|
||||
void* a3, void* a4);
|
||||
|
||||
#endif // _KERNEL_DEVICE_TERMINAL_H
|
||||
|
||||
Reference in New Issue
Block a user