POK(kernelpart)
cons.c
Go to the documentation of this file.
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 
18 #include <errno.h>
19 
20 #include "ioports.h"
21 #include <libc.h>
22 #include <core/debug.h>
23 #include <core/cons.h>
24 #include "cons.h"
25 
26 #if defined (POK_NEEDS_CONSOLE) || defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_INSTRUMENTATION) || defined (POK_NEEDS_COVERAGE_INFOS)
27 
28 #define COM1 0x3F8
29 
30 static int is_transmit_empty(void)
31 {
32  return inb(COM1 + 5) & 0x20;
33 }
34 
35 static void write_serial(char a)
36 {
37  while (is_transmit_empty() == 0)
38  ;
39 
40  outb(COM1,a);
41 }
42 
43 pok_bool_t pok_cons_write (const char *s, size_t length)
44 {
45  for (; length > 0; length--)
46  write_serial (*s++);
47  return 0;
48 }
49 
50 
51 int pok_cons_init (void)
52 {
53  outb(COM1 + 1, 0x00); // Disable all interrupts
54  outb(COM1 + 3, 0x80); // Enable DLAB (set baud rate divisor)
55  outb(COM1 + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
56  outb(COM1 + 1, 0x00); // (hi byte)
57  outb(COM1 + 3, 0x03); // 8 bits, no parity, one stop bit
58  outb(COM1 + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
59  outb(COM1 + 4, 0x0B); // IRQs enabled, RTS/DSR set
60 
61  pok_print_init (write_serial, NULL);
62 
63  return 0;
64 
65 
66 }
67 #else
68 int pok_cons_init (void)
69 {
70  return 0;
71 }
72 #endif
73 
74