Rewrite PS2KB using the new devctl interface
This commit is contained in:
@ -54,7 +54,6 @@ SRCFILES += $(call GRABSRC, \
|
||||
baseimg \
|
||||
proc \
|
||||
proc/kproc \
|
||||
proc/ps2kbproc \
|
||||
proc/serialproc \
|
||||
hal \
|
||||
hal/$(ARCH) \
|
||||
|
35
kernel/dev/ps2kbdev.c
Normal file
35
kernel/dev/ps2kbdev.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "kprintf.h"
|
||||
#include "hal/hal.h"
|
||||
#include "ps2kbdev.h"
|
||||
#include "dev.h"
|
||||
#include "errors.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
|
||||
Dev PS2KBDEV;
|
||||
Ps2KbFastBuf PS2KB_BUF;
|
||||
|
||||
int32_t ps2kbdev_readch(uint8_t *buffer, size_t len, void *extra) {
|
||||
(void)buffer; (void)len; (void)extra;
|
||||
uint8_t b = 0;
|
||||
spinlock_acquire(&PS2KB_BUF.spinlock);
|
||||
int32_t r = rbuf_pop(&PS2KB_BUF.rbuf, &b);
|
||||
spinlock_release(&PS2KB_BUF.spinlock);
|
||||
|
||||
if (r == 0) {
|
||||
return b;
|
||||
} else {
|
||||
return E_NOTYET;
|
||||
}
|
||||
}
|
||||
|
||||
void ps2kbdev_init(void) {
|
||||
hal_memset(&PS2KBDEV, 0, sizeof(PS2KBDEV));
|
||||
PS2KBDEV.fns[0] = &ps2kbdev_readch;
|
||||
|
||||
const int bufsz = 0x1000;
|
||||
uint8_t *buf = dlmalloc(bufsz);
|
||||
rbuf_init(&PS2KB_BUF.rbuf, buf, bufsz);
|
||||
PS2KB_BUF.init = true;
|
||||
}
|
22
kernel/dev/ps2kbdev.h
Normal file
22
kernel/dev/ps2kbdev.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef DEV_PS2KBDEV_H_
|
||||
#define DEV_PS2KBDEV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "dev.h"
|
||||
#include "rbuf/rbuf.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
|
||||
typedef struct {
|
||||
RBuf rbuf;
|
||||
SpinLock spinlock;
|
||||
bool init;
|
||||
} Ps2KbFastBuf;
|
||||
|
||||
void ps2kbdev_init(void);
|
||||
|
||||
extern Dev PS2KBDEV;
|
||||
|
||||
extern Ps2KbFastBuf PS2KB_BUF;
|
||||
|
||||
#endif // DEV_PS2KBDEV_H_
|
@ -14,8 +14,8 @@
|
||||
#include "errors.h"
|
||||
#include "drivers/ps2kb/ps2kb.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "proc/ps2kbproc/ps2kbproc.h"
|
||||
#include "rbuf/rbuf.h"
|
||||
#include "dev/ps2kbdev.h"
|
||||
|
||||
typedef struct BackTraceFrame {
|
||||
struct BackTraceFrame *rbp;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "util/util.h"
|
||||
#include "proc/proc.h"
|
||||
#include "dev/termdev.h"
|
||||
#include "dev/ps2kbdev.h"
|
||||
|
||||
const char *human_size(uint64_t bytes, char *buf, size_t bufsize) {
|
||||
static const char *units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB" };
|
||||
@ -66,6 +67,7 @@ void kmain(void) {
|
||||
baseimg_init();
|
||||
vfs_init();
|
||||
termdev_init();
|
||||
ps2kbdev_init();
|
||||
proc_init();
|
||||
|
||||
for(;;);
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "bootinfo/bootinfo.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "kproc/kproc.h"
|
||||
#include "ps2kbproc/ps2kbproc.h"
|
||||
#include "serialproc/serialproc.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
|
||||
@ -308,18 +307,6 @@ void proc_init(void) {
|
||||
spinlock_init(&PROCS.spinlock);
|
||||
PROCS.procs = NULL;
|
||||
|
||||
/* kproc_init(proc_spawnkern(&kproc_fn, "kproc")); */
|
||||
/* proc_register(KPROC); */
|
||||
/* PROCS.current = KPROC; */
|
||||
/* KPROC->state = PROC_READY; */
|
||||
|
||||
/* ps2kbproc_init(proc_spawnkern(&ps2kbproc_fn, "ps2kbproc")); */
|
||||
/* proc_register(PS2KBPROC); */
|
||||
/* PS2KBPROC->state = PROC_READY; */
|
||||
|
||||
/* serialproc_init(proc_spawnkern(&serialproc_fn, "serialproc")); */
|
||||
/* proc_register(SERIALPROC); */
|
||||
|
||||
Proc *init = proc_spawnuser("base", "/bin/init");
|
||||
PROCS.current = init;
|
||||
proc_register(init);
|
||||
|
@ -1,39 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#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 = {0};
|
||||
|
||||
void ps2kbproc_init(Proc *proc) {
|
||||
PS2KBPROC = proc;
|
||||
|
||||
PS2KBPROC->bcast_pipes.list = NULL;
|
||||
|
||||
uint8_t *buf = dlmalloc(IPC_PIPE_MAX);
|
||||
rbuf_init(&PS2KB_BUF.rbuf, buf, IPC_PIPE_MAX);
|
||||
spinlock_init(&PS2KB_BUF.spinlock);
|
||||
PS2KB_BUF.init = true;
|
||||
}
|
||||
|
||||
void ps2kbproc_fn(void) {
|
||||
for (;;) {
|
||||
/* uint8_t b = 0; */
|
||||
/* spinlock_acquire(&PS2KB_BUF.spinlock); */
|
||||
/* if (rbuf_pop(&PS2KB_BUF.rbuf, &b) == 0) { */
|
||||
/* spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock); */
|
||||
/* IpcPipe *head = PS2KBPROC->bcast_pipes.list; */
|
||||
/* while (head != NULL) { */
|
||||
/* ipc_pipewrite(head, &b, 1); */
|
||||
/* head = head->next; */
|
||||
/* } */
|
||||
/* spinlock_release(&PS2KBPROC->bcast_pipes.spinlock); */
|
||||
/* } */
|
||||
/* spinlock_release(&PS2KB_BUF.spinlock); */
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#ifndef PROC_PS2KB_PS2KBPROC_H_
|
||||
#define PROC_PS2KB_PS2KBPROC_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "proc/proc.h"
|
||||
#include "rbuf/rbuf.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
|
||||
typedef struct {
|
||||
RBuf rbuf;
|
||||
SpinLock spinlock;
|
||||
bool init;
|
||||
} Ps2KbFastBuf;
|
||||
|
||||
extern Proc *PS2KBPROC;
|
||||
extern Ps2KbFastBuf PS2KB_BUF;
|
||||
|
||||
void ps2kbproc_fn(void);
|
||||
void ps2kbproc_init(Proc *proc);
|
||||
|
||||
#endif // PROC_PS2KB_PS2KBPROC_H_
|
@ -7,10 +7,12 @@
|
||||
#include "proc/proc.h"
|
||||
#include "sysdefs/devctl.h"
|
||||
#include "dev/termdev.h"
|
||||
#include "dev/ps2kbdev.h"
|
||||
#include "util/util.h"
|
||||
|
||||
Dev *DEVS[] = {
|
||||
[0x10] = &TERMDEV,
|
||||
[0x11] = &PS2KBDEV,
|
||||
};
|
||||
|
||||
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
||||
@ -35,6 +37,7 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
|
||||
if (proc->devs[i] == NULL) {
|
||||
found = true;
|
||||
proc->devs[i] = DEVS[devid];
|
||||
*devh = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ enum {
|
||||
E_INVALIDOPER = -11,
|
||||
E_RESOURCEAVAIL = -12,
|
||||
E_SPAWNERROR = -13,
|
||||
E_NOTYET = -14,
|
||||
};
|
||||
|
||||
static const char *_ERROR_STRINGS[] = {
|
||||
|
Reference in New Issue
Block a user