Implement a kernel process
This commit is contained in:
@ -163,9 +163,6 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
proc->state = PROC_READY;
|
||||
proc->pid = pids++;
|
||||
|
||||
proc->pipes[0] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(proc->pipes[0]);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
@ -268,12 +265,6 @@ void proc_killself(void) {
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
}
|
||||
|
||||
void proc_idle(void) {
|
||||
for(;;) {
|
||||
// .
|
||||
}
|
||||
}
|
||||
|
||||
void proc_status(void) {
|
||||
static const char *statuses[] = {"ready", "running", "zombie", "waiting"};
|
||||
for (;;) {
|
||||
@ -290,14 +281,13 @@ void proc_status(void) {
|
||||
}
|
||||
}
|
||||
|
||||
Proc *init_proc = NULL;
|
||||
#define PIPEREADER_BUF_SIZE 100
|
||||
Proc *kproc = NULL;
|
||||
|
||||
void proc_init_pipereader(void) {
|
||||
char buf[PIPEREADER_BUF_SIZE];
|
||||
void proc_kproc(void) {
|
||||
char buf[100];
|
||||
hal_memset(buf, 0, sizeof(buf));
|
||||
for (;;) {
|
||||
int32_t read = ipc_piperead(init_proc->pipes[0], buf, PIPEREADER_BUF_SIZE);
|
||||
int32_t read = ipc_piperead(kproc->pipes[1], buf, sizeof(buf));
|
||||
kprintf("%.*s", read, buf);
|
||||
hal_memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
@ -307,14 +297,15 @@ void proc_init(void) {
|
||||
spinlock_init(&PROCS.spinlock);
|
||||
PROCS.procs = NULL;
|
||||
|
||||
Proc *idle = proc_spawnkern(&proc_idle, "k-idle");
|
||||
proc_register(idle);
|
||||
PROCS.current = idle;
|
||||
kproc = proc_spawnkern(&proc_kproc, "kproc");
|
||||
kproc->pipes[1] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(kproc->pipes[1]);
|
||||
proc_register(kproc);
|
||||
PROCS.current = kproc;
|
||||
|
||||
/* proc_register(proc_spawnkern(&proc_status, "status")); */
|
||||
init_proc = proc_spawnuser("base", "/bin/init");
|
||||
proc_register(init_proc);
|
||||
proc_register(proc_spawnkern(&proc_init_pipereader, "k-init-pipereader"));
|
||||
Proc *init = proc_spawnuser("base", "/bin/init");
|
||||
init->pipes[0] = kproc->pipes[1];
|
||||
proc_register(init);
|
||||
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
Reference in New Issue
Block a user