Serial I/O is toggleable
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 6 Jun 2009 01:17:44 +0000 (18:17 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sat, 6 Jun 2009 01:17:44 +0000 (18:17 -0700)
If you want serial I/O, make with SERIAL_IO defined.  That will turn off
serial console output and enable the serial read/write syscalls.

kern/src/console.c
kern/src/syscall.c

index eb83b1a..6e50ca9 100644 (file)
@@ -507,7 +507,9 @@ cons_getc(void)
        // poll for any pending input characters,
        // so that this function works even when interrupts are disabled
        // (e.g., when called from the kernel monitor).
-       //serial_intr();
+       #ifndef SERIAL_IO
+               serial_intr();
+       #endif
        kbd_intr();
 
        // grab the next character from the input buffer.
@@ -524,7 +526,7 @@ cons_getc(void)
 void
 cons_putc(int c)
 {
-       //serial_putc(c);
+       serial_putc(c);
        //lpt_putc(c);
        cga_putc(c);
 }
@@ -535,7 +537,9 @@ cons_init(void)
 {
        cga_init();
        kbd_init();
-       serial_init();
+       #ifndef SERIAL_IO
+               serial_init();
+       #endif
 
        if (!serial_exists)
                cprintf("Serial port does not exist!\n");
index cb3ded8..87a38f5 100644 (file)
@@ -41,23 +41,31 @@ static void sys_null(void)
 //Write a buffer over the serial port
 static ssize_t sys_serial_write(env_t* e, const char *DANGEROUS buf, size_t len) 
 {
-       char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
-       for(int i =0; i<len; i++)
-               serial_send_byte(buf[i]);       
-       return (ssize_t)len;
+       #ifdef SERIAL_IO
+               char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
+               for(int i =0; i<len; i++)
+                       serial_send_byte(buf[i]);       
+               return (ssize_t)len;
+       #else
+               return -E_INVAL;
+       #endif
 }
 
 //Read a buffer over the serial port
 static ssize_t sys_serial_read(env_t* e, char *DANGEROUS buf, size_t len) 
 {
-    char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
-       size_t bytes_read = 0;
-       int c;
-       while((c = serial_read_byte()) != -1) {
-               buf[bytes_read++] = (uint8_t)c;
-               if(bytes_read == len) break;
-       }
-       return (ssize_t)bytes_read;
+       #ifdef SERIAL_IO
+           char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
+               size_t bytes_read = 0;
+               int c;
+               while((c = serial_read_byte()) != -1) {
+                       buf[bytes_read++] = (uint8_t)c;
+                       if(bytes_read == len) break;
+               }
+               return (ssize_t)bytes_read;
+       #else
+               return -E_INVAL;
+       #endif
 }
 
 // Invalidate the cache of this core