15 #define BUFFER_SIZE 4096
17 enum serial_port_regs
{
32 static const uint16_t debug_base
= DEBUG_PORT
;
34 static void debug_putc(char c
)
39 while ((inb(debug_base
+ LSR
) & 0x20) == 0)
41 outb(c
, debug_base
+ THR
);
44 void vdprintf(const char *format
, va_list ap
)
47 char buffer
[BUFFER_SIZE
];
49 static bool debug_init
= false;
50 static bool debug_ok
= false;
52 rv
= vsnprintf(buffer
, BUFFER_SIZE
, format
, ap
);
56 if (rv
> BUFFER_SIZE
- 1)
60 * This unconditionally outputs to a serial port at 0x3f8 regardless of
61 * if one is enabled or not (this means we don't have to enable the real
62 * serial console and therefore get conflicting output.)
64 if (__unlikely(!debug_init
)) {
65 uint8_t dll
, dlm
, lcr
;
71 /* Initialize the serial port to 115200 n81 with FIFOs enabled */
72 outb(0x83, debug_base
+ LCR
);
73 outb(0x01, debug_base
+ DLL
);
74 outb(0x00, debug_base
+ DLM
);
75 (void)inb(debug_base
+ IER
); /* Synchronize */
76 dll
= inb(debug_base
+ DLL
);
77 dlm
= inb(debug_base
+ DLM
);
78 lcr
= inb(debug_base
+ LCR
);
80 outb(0x03, debug_base
+ LCR
);
81 (void)inb(debug_base
+ IER
); /* Synchronize */
83 outb(0x00, debug_base
+ IER
);
84 (void)inb(debug_base
+ IER
); /* Synchronize */
88 if (dll
!= 0x01 || dlm
!= 0x00 || lcr
!= 0x83) {
89 /* No serial port present */
93 outb(0x01, debug_base
+ FCR
);
94 (void)inb(debug_base
+ IER
); /* Synchronize */
95 if (inb(debug_base
+ IIR
) < 0xc0) {
96 outb(0x00, debug_base
+ FCR
); /* Disable non-functional FIFOs */
97 (void)inb(debug_base
+ IER
); /* Synchronize */
111 #endif /* DEBUG_PORT */