-1

I want use kbdgetc() in user mode. I need to use it to program a vim-like software in xv6. I try to use kernel mode, but I totally don't know how to do it.

  • Why do you need to call an interrupt handler from user space? `kbdgetc()` is called when it's needed (when an interrupt is generated by the keyboard (`IRQ_KBD`). If you need to read for the console, you can use `read(0,...)` – Mathieu Jun 04 '20 at 14:06

1 Answers1

0

I guess that you want some non-buffering reading on fd 0?

To achieve this behavior, you can modify consoleintr function that is responsible of it.

First add some variable internal to the kernel to disable or not buffering.

Lets call it non_buffering and set its default values to 0.

Then add a system call to change this value (or modify an existing, as you want)

Change consoleintr this way (modification is line 221):

191 void
192 consoleintr(int (*getc)(void))
193 {
194   int c, doprocdump = 0;
195
196   acquire(&cons.lock);
197   while((c = getc()) >= 0){
198     switch(c){
   ....
216     default:
217       if(c != 0 && input.e-input.r < INPUT_BUF){
218         c = (c == '\r') ? '\n' : c;
219         input.buf[input.e++ % INPUT_BUF] = c;
220         consputc(c);

       /* NON_BUFFERING added here */
221         if(non_buffering || c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){
222           input.w = input.e;
223           wakeup(&input.r);
224         }
225       }
226       break;
227     }
228   }
229   release(&cons.lock);
230   if(doprocdump) {
231     procdump();  // now call procdump() wo. cons.lock held
232   }
233 }

Mathieu
  • 6,922
  • 6
  • 27
  • 37