Add special event pipes, rework ps2kb process
This commit is contained in:
@ -101,6 +101,7 @@ Proc *proc_spawnkern(void (*ent)(void), char *name) {
|
||||
proc->platformdata.cr3 = hal_vmm_current_cr3();
|
||||
proc->state = PROC_READY;
|
||||
proc->pid = pids++;
|
||||
spinlock_init(&proc->eventpipes_spinlock);
|
||||
|
||||
return proc;
|
||||
}
|
||||
@ -166,6 +167,7 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
proc->platformdata.trapframe.rip = aux.entry;
|
||||
proc->state = PROC_READY;
|
||||
proc->pid = pids++;
|
||||
spinlock_init(&proc->eventpipes_spinlock);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ typedef struct Proc {
|
||||
uint64_t vobjcnt;
|
||||
|
||||
IpcPipe *pipes[PROC_PIPEHANDLES_MAX];
|
||||
IpcPipe *eventpipes;
|
||||
SpinLock eventpipes_spinlock;
|
||||
} Proc;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2,18 +2,45 @@
|
||||
#include "proc/proc.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "kprintf.h"
|
||||
#include "rbuf/rbuf.h"
|
||||
#include "ps2kbproc.h"
|
||||
|
||||
Proc *PS2KBPROC = NULL;
|
||||
Ps2KbFastBuf PS2KB_BUF;
|
||||
|
||||
Proc *PS2KBPROC;
|
||||
|
||||
void ps2kbproc_init(Proc *proc) {
|
||||
PS2KBPROC = proc;
|
||||
PS2KBPROC->pipes[0] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(PS2KBPROC->pipes[0]);
|
||||
|
||||
PS2KBPROC->eventpipes = NULL;
|
||||
|
||||
PS2KB_BUF.rbuf.buffer = dlmalloc(IPC_PIPE_MAX);
|
||||
PS2KB_BUF.rbuf.cap = IPC_PIPE_MAX;
|
||||
spinlock_init(&PS2KB_BUF.spinlock);
|
||||
}
|
||||
|
||||
void ps2kbproc_fn(void) {
|
||||
for (;;) {
|
||||
|
||||
int32_t kbchr;
|
||||
uint8_t *buf = (uint8_t *)&kbchr;
|
||||
size_t i = 0;
|
||||
spinlock_acquire(&PS2KB_BUF.spinlock);
|
||||
for (; i < sizeof(kbchr); i++) {
|
||||
if (rbuf_pop(&PS2KB_BUF.rbuf, &buf[i]) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
spinlock_release(&PS2KB_BUF.spinlock);
|
||||
if (i > 0) {
|
||||
spinlock_acquire(&PS2KBPROC->eventpipes_spinlock);
|
||||
IpcPipe *head = PS2KBPROC->eventpipes;
|
||||
while (head != NULL) {
|
||||
ipc_pipewrite(head, (uint8_t *)&kbchr, sizeof(kbchr));
|
||||
head = head->next;
|
||||
}
|
||||
spinlock_release(&PS2KBPROC->eventpipes_spinlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,16 @@
|
||||
#define PROC_PS2KB_PS2KBPROC_H_
|
||||
|
||||
#include "proc/proc.h"
|
||||
#include "rbuf/rbuf.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
|
||||
typedef struct {
|
||||
RBuf rbuf;
|
||||
SpinLock spinlock;
|
||||
} Ps2KbFastBuf;
|
||||
|
||||
extern Proc *PS2KBPROC;
|
||||
extern Ps2KbFastBuf PS2KB_BUF;
|
||||
|
||||
void ps2kbproc_fn(void);
|
||||
void ps2kbproc_init(Proc *proc);
|
||||
|
Reference in New Issue
Block a user