2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
6 ** Modified 2001/09/05 by Rob Judd<judd@ob-wan.com>
8 #include <kernel/kernel.h>
9 #include <kernel/int.h>
10 #include <kernel/arch/cpu.h>
11 #include <kernel/arch/dbg_console.h>
13 #include <boot/stage2.h>
17 #if _SERIAL_DBG_PORT == 1
18 static const int serial_ioport_base
= 0x3f8;
19 #elif _SERIAL_DBG_PORT == 2
20 static const int serial_ioport_base
= 0x2f8;
21 #elif _SERIAL_DBG_PORT == 0xe9
22 #define BOCHS_E9_HACK 1
24 #error _SERIAL_DBG_PORT set to unsupported com port
27 static const int dbg_baud_rate
= 115200;
29 int arch_dbg_con_init(kernel_args
*ka
)
32 short divisor
= 115200 / dbg_baud_rate
;
34 out8(0x80, serial_ioport_base
+3); /* set up to load divisor latch */
35 out8(divisor
& 0xf, serial_ioport_base
); /* LSB */
36 out8(divisor
>> 8, serial_ioport_base
+1); /* MSB */
37 out8(3, serial_ioport_base
+3); /* 8N1 */
42 int arch_dbg_con_init2(kernel_args
*ka
)
47 char arch_dbg_con_read(void)
52 while ((in8(serial_ioport_base
+5) & 1) == 0)
54 return in8(serial_ioport_base
);
58 static void _arch_dbg_con_putch(const char c
)
64 while ((in8(serial_ioport_base
+5) & 0x20) == 0)
66 out8(c
, serial_ioport_base
);
71 char arch_dbg_con_putch(const char c
)
74 _arch_dbg_con_putch('\r');
75 _arch_dbg_con_putch('\n');
77 _arch_dbg_con_putch(c
);
82 void arch_dbg_con_puts(const char *s
)
85 arch_dbg_con_putch(*s
);
90 ssize_t
arch_dbg_con_write(const void *buf
, ssize_t len
)
92 const char *cbuf
= (const char *)buf
;
96 arch_dbg_con_putch(*cbuf
);