4 #include "devices/serial.h"
5 #include "devices/vga.h"
6 #include "threads/interrupt.h"
7 #include "threads/synch.h"
9 static void vprintf_helper (char, void *);
10 static void putchar_unlocked (uint8_t c);
13 Both the vga and serial layers do their own locking, so it's
14 safe to call them at any time.
15 But this lock is useful to prevent simultaneous printf() calls
16 from mixing their output, which looks confusing. */
17 static struct lock console_lock;
22 lock_init (&console_lock, "console");
25 /* The standard vprintf() function,
26 which is like printf() but uses a va_list.
27 Writes its output to both vga display and serial port. */
29 vprintf (const char *format, va_list args)
34 lock_acquire (&console_lock);
36 __vprintf (format, args, vprintf_helper, &char_cnt);
39 lock_release (&console_lock);
44 /* Writes string S to the console, followed by a new-line
50 lock_acquire (&console_lock);
53 putchar_unlocked (*s++);
54 putchar_unlocked ('\n');
57 lock_release (&console_lock);
62 /* Writes C to the vga display and serial port. */
67 lock_acquire (&console_lock);
72 lock_release (&console_lock);
77 /* Helper function for vprintf(). */
79 vprintf_helper (char c, void *char_cnt_)
81 int *char_cnt = char_cnt_;
86 /* Writes C to the vga display and serial port.
87 The caller has already acquired the console lock if
90 putchar_unlocked (uint8_t c)