This commit is contained in:
2025-09-27 15:16:26 +02:00
parent 5af7c5276a
commit 3b1bb9d531
63 changed files with 1087 additions and 407 deletions

View File

@ -15,7 +15,6 @@
#include "ipc/pipe/pipe.h"
#include "kproc/kproc.h"
#include "ps2kbproc/ps2kbproc.h"
#include "termproc/termproc.h"
#include "serialproc/serialproc.h"
#include "sysdefs/processctl.h"
@ -181,6 +180,7 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
proc->mman_map_base = PROC_MMAN_MAP_BASE;
spinlock_init(&proc->bcast_pipes.spinlock);
spinlock_init(&proc->pipes_spinlock);
spinlock_init(&proc->devs_spinlock);
proc->pipes[0] = dlmalloc(sizeof(IpcPipe));
ipc_pipeinit(proc->pipes[0], proc->pid);
@ -308,26 +308,20 @@ 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;
/* 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;
termproc_init(proc_spawnkern(&termproc_fn, "termproc"));
proc_register(TERMPROC);
TERMPROC->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");
ipc_pipefree(init->pipes[0]);
dlfree(init->pipes[0]);
init->pipes[0] = TERMPROC->pipes[1];
PROCS.current = init;
proc_register(init);
init->state = PROC_READY;

View File

@ -8,6 +8,7 @@
#include "vfs/vfs.h"
#include "ipc/pipe/pipe.h"
#include "sysdefs/processctl.h"
#include "dev/dev.h"
#define PROC_NAME_MAX 0x100
@ -18,9 +19,10 @@
#define PROC_VFSHANDLES_MAX 0x80
#define PROC_PIPEHANDLES_MAX 0x20
#define PROC_DEVHANDLES_MAX 0x20
#define PROC_MMAN_MAP_BASE 0x0000100000000000ULL
#define PROC_USER_STACK_TOP 0x0000800000000000ULL
#define PROC_USER_STACK_TOP 0x00007FFFFFFFF000ULL
typedef struct {
IntrStackFrame trapframe;
@ -56,12 +58,18 @@ typedef struct Proc {
VfsObj *vobjs[PROC_VFSHANDLES_MAX];
uint64_t vobjcnt;
IpcPipe *pipes[PROC_PIPEHANDLES_MAX];
SpinLock pipes_spinlock;
struct {
IpcPipe *list;
SpinLock spinlock;
} bcast_pipes;
Dev *devs[PROC_DEVHANDLES_MAX];
SpinLock devs_spinlock;
struct {
ProcArg *list;
size_t len;

View File

@ -7,7 +7,7 @@
#include "ps2kbproc.h"
Proc *PS2KBPROC = NULL;
Ps2KbFastBuf PS2KB_BUF;
Ps2KbFastBuf PS2KB_BUF = {0};
void ps2kbproc_init(Proc *proc) {
PS2KBPROC = proc;
@ -17,22 +17,23 @@ void ps2kbproc_init(Proc *proc) {
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);
/* 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); */
}
}

View File

@ -9,6 +9,7 @@
typedef struct {
RBuf rbuf;
SpinLock spinlock;
bool init;
} Ps2KbFastBuf;
extern Proc *PS2KBPROC;

View File

@ -1,25 +0,0 @@
#include <stdint.h>
#include "proc/proc.h"
#include "ipc/pipe/pipe.h"
#include "kprintf.h"
#include "hal/hal.h"
#include "dlmalloc/malloc.h"
#include "spinlock/spinlock.h"
Proc *TERMPROC;
void termproc_init(Proc *proc) {
TERMPROC = proc;
TERMPROC->pipes[1] = dlmalloc(sizeof(IpcPipe));
ipc_pipeinit(TERMPROC->pipes[1], TERMPROC->pid);
}
void termproc_fn(void) {
for (;;) {
char c = 0;
int32_t read = ipc_piperead(TERMPROC->pipes[1], (uint8_t *)&c, 1);
if (read > 0) {
kprintf("%c", c);
}
}
}

View File

@ -1,11 +0,0 @@
#ifndef PROC_TERMPROC_TERMPROC_H_
#define PROC_TERMPROC_TERMPROC_H_
#include "proc/proc.h"
extern Proc *TERMPROC;
void termproc_init(Proc *proc);
void termproc_fn(void);
#endif // PROC_TERMPROC_TERMPROC_H_