console input and sbrk

This commit is contained in:
Robert Morris 2019-06-03 17:59:17 -04:00
parent efecbee7c0
commit cefe223bf5
6 changed files with 58 additions and 82 deletions

66
proc.c
View file

@ -184,8 +184,6 @@ userinit(void)
release(&ptable.lock);
}
#if 0
// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
@ -196,17 +194,15 @@ growproc(int n)
sz = p->sz;
if(n > 0){
if((sz = allocuvm(p->pagetable, sz, sz + n)) == 0)
if((sz = uvmalloc(p->pagetable, sz, sz + n)) == 0)
return -1;
} else if(n < 0){
if((sz = uvmdealloc(p->pagetable, sz, sz + n)) == 0)
return -1;
}
p->sz = sz;
switchuvm(p);
return 0;
}
#endif
// Create a new process, copying p as the parent.
// Sets up child kernel stack to return as if from system call.
@ -363,24 +359,7 @@ scheduler(void)
c->proc = 0;
for(;;){
// Enable interrupts on this processor.
// XXX riscv
//sti();
if(0){ uint x = * (uint*) 0xc001000;
if(x != 0){
printf("pending %x\n", x);
}
x = *(uint*)0xc001004;
if(x != 0)
printf("pending %x\n", x);
}
if(0){
uint uartgetc(void);
uint x = uartgetc();
if(x != 0)
printf("%x ", x);
}
intr_on();
// Loop over process table looking for process to run.
acquire(&ptable.lock);
@ -394,9 +373,7 @@ scheduler(void)
c->proc = p;
p->state = RUNNING;
printf("switch...\n");
swtch(&c->scheduler, &p->context);
printf("switch returned\n");
// Process is done running for now.
// It should have changed its p->state before coming back.
@ -450,8 +427,6 @@ forkret(void)
// Still holding ptable.lock from scheduler.
release(&ptable.lock);
printf("entering forkret\n");
if (first) {
// Some initialization functions must be run in the context
// of a regular process (e.g., they call sleep), and thus cannot
@ -550,41 +525,4 @@ kill(int pid)
return -1;
}
//PAGEBREAK: 36
// Print a process listing to console. For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void
procdump(void)
{
static char *states[] = {
[UNUSED] "unused",
[EMBRYO] "embryo",
[SLEEPING] "sleep ",
[RUNNABLE] "runble",
[RUNNING] "run ",
[ZOMBIE] "zombie"
};
int i;
struct proc *p;
char *state;
uint64 pc[10];
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->state == UNUSED)
continue;
if(p->state >= 0 && p->state < NELEM(states) && states[p->state])
state = states[p->state];
else
state = "???";
printf("%d %s %s", p->pid, state, p->name);
if(p->state == SLEEPING){
getcallerpcs((uint64*)p->context->rbp+2, pc);
for(i=0; i<10 && pc[i] != 0; i++)
printf(" %p", pc[i]);
}
printf("\n");
}
}
#endif