First stab at interrupt-driven serial.
[pintos-anon] / src / lib / kernel / printf.c
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include "devices/serial.h"
4 #include "devices/vga.h"
5 #include "threads/interrupt.h"
6
7 static void vprintf_helper (char, void *);
8
9 /* The standard vprintf() function,
10    which is like printf() but uses a va_list.
11    Writes its output to both vga display and serial port. */
12 int
13 vprintf (const char *format, va_list args) 
14 {
15   enum intr_level old_level;
16   int char_cnt = 0;
17
18   old_level = intr_disable ();
19   __vprintf (format, args, vprintf_helper, &char_cnt);
20   intr_set_level (old_level);
21
22   return char_cnt;
23 }
24
25 /* Helper function for vprintf(). */
26 static void
27 vprintf_helper (char c, void *char_cnt_) 
28 {
29   int *char_cnt = char_cnt_;
30   (*char_cnt)++;
31   putchar (c);
32 }
33
34 /* Writes C to the vga display and serial port. */
35 int
36 putchar (int c) 
37 {
38   serial_putc (c);
39   vga_putc (c);
40   return c;
41 }