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