diff options
| author | Robert Morris <rtm@csail.mit.edu> | 2019-06-03 17:59:17 -0400 | 
|---|---|---|
| committer | Robert Morris <rtm@csail.mit.edu> | 2019-06-03 17:59:17 -0400 | 
| commit | cefe223bf5e4b68e5c1202f2f089a164ad656621 (patch) | |
| tree | b2bf9fdb2c94e3159ce595c6b4a88daf5c35e878 | |
| parent | efecbee7c0c265b0b2fe956f308e1a73cc63eda6 (diff) | |
| download | xv6-labs-cefe223bf5e4b68e5c1202f2f089a164ad656621.tar.gz xv6-labs-cefe223bf5e4b68e5c1202f2f089a164ad656621.tar.bz2 xv6-labs-cefe223bf5e4b68e5c1202f2f089a164ad656621.zip | |
console input and sbrk
| -rw-r--r-- | console.c | 35 | ||||
| -rw-r--r-- | defs.h | 3 | ||||
| -rw-r--r-- | proc.c | 66 | ||||
| -rw-r--r-- | syscall.c | 2 | ||||
| -rw-r--r-- | sysproc.c | 22 | ||||
| -rw-r--r-- | uart.c | 12 | 
6 files changed, 58 insertions, 82 deletions
| @@ -208,6 +208,41 @@ consolewrite(struct inode *ip, char *buf, int n)  }  void +consoleintr(int c) +{ +  acquire(&cons.lock); + +  switch(c){ +  case C('U'):  // Kill line. +    while(input.e != input.w && +          input.buf[(input.e-1) % INPUT_BUF] != '\n'){ +      input.e--; +      consputc(BACKSPACE); +    } +    break; +  case C('H'): case '\x7f':  // Backspace +    if(input.e != input.w){ +      input.e--; +      consputc(BACKSPACE); +    } +    break; +  default: +    if(c != 0 && input.e-input.r < INPUT_BUF){ +      c = (c == '\r') ? '\n' : c; +      input.buf[input.e++ % INPUT_BUF] = c; +      consputc(c); +      if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){ +        input.w = input.e; +        wakeup(&input.r); +      } +    } +    break; +  } +   +  release(&cons.lock); +} + +void  consoleinit(void)  {    initlock(&cons.lock, "console"); @@ -20,7 +20,7 @@ void            bwrite(struct buf*);  // console.c  void            consoleinit(void);  void            printf(char*, ...); -void            consoleintr(int(*)(void)); +void            consoleintr(int);  void            panic(char*) __attribute__((noreturn));  // exec.c @@ -114,7 +114,6 @@ struct cpu*     mycpu(void);  struct cpu*     getmycpu(void);  struct proc*    myproc();  void            procinit(void); -void            procdump(void);  void            scheduler(void) __attribute__((noreturn));  void            sched(void);  void            setproc(struct proc*); @@ -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 @@ -150,7 +150,7 @@ static int (*syscalls[])(void) = {  [SYS_chdir]   sys_chdir,  [SYS_dup]     sys_dup,  [SYS_getpid]  sys_getpid, -//[SYS_sbrk]    sys_sbrk, +[SYS_sbrk]    sys_sbrk,  //[SYS_sleep]   sys_sleep,  //[SYS_uptime]  sys_uptime,  [SYS_open]    sys_open, @@ -31,17 +31,6 @@ sys_wait(void)    return wait();  } -#if 0 -int -sys_kill(void) -{ -  int pid; - -  if(argint(0, &pid) < 0) -    return -1; -  return kill(pid); -} -  int  sys_sbrk(void)  { @@ -56,6 +45,17 @@ sys_sbrk(void)    return addr;  } +#if 0 +int +sys_kill(void) +{ +  int pid; + +  if(argint(0, &pid) < 0) +    return -1; +  return kill(pid); +} +  int  sys_sleep(void)  { @@ -52,17 +52,21 @@ uartputc(int c)  int  uartgetc(void)  { -  if(*(5) & 0x01){ +  if(*R(5) & 0x01){      // input data is ready.      return *R(0);    } else {      return -1; -  }; +  }  }  void  uartintr(void)  { -  int c = uartgetc(); -  printf("%x ", c & 0xff); +  while(1){ +    int c = uartgetc(); +    if(c == -1) +      break; +    consoleintr(c); +  }  } | 
