blob: 7990dcb5181576780f9d2bca94de3468952a9e8b [file] [log] [blame]
Eric Biederman6aa31cc2003-06-10 21:22:07 +00001void outb(unsigned char value, unsigned short port)
2{
3 __builtin_outb(value, port);
4}
5
6unsigned char inb(unsigned short port)
7{
8 return __builtin_inb(port);
9}
10
11/* Base Address */
12#ifndef TTYS0_BASE
13#define TTYS0_BASE 0x3f8
14#endif
15
16#ifndef TTYS0_BAUD
17#define TTYS0_BAUD 115200
18#endif
19
20#if ((115200%TTYS0_BAUD) != 0)
21#error Bad ttys0 baud rate
22#endif
23
24#if TTYS0_BAUD == 115200
25#define TTYS0_DIV (1)
26#else
27#define TTYS0_DIV (115200/TTYS0_BAUD)
28#endif
29
30/* Line Control Settings */
31#ifndef TTYS0_LCS
32/* Set 8bit, 1 stop bit, no parity */
33#define TTYS0_LCS 0x3
34#endif
35
36#define UART_LCS TTYS0_LCS
37
38/* Data */
39#define UART_RBR 0x00
40#define UART_TBR 0x00
41
42/* Control */
43#define UART_IER 0x01
44#define UART_IIR 0x02
45#define UART_FCR 0x02
46#define UART_LCR 0x03
47#define UART_MCR 0x04
48#define UART_DLL 0x00
49#define UART_DLM 0x01
50
51/* Status */
52#define UART_LSR 0x05
53#define UART_MSR 0x06
54#define UART_SCR 0x07
55
56int uart_can_tx_byte(void)
57{
58 return inb(TTYS0_BASE + UART_LSR) & 0x20;
59}
60
61void uart_wait_to_tx_byte(void)
62{
63 while(!uart_can_tx_byte())
64 ;
65}
66
67void uart_wait_until_sent(void)
68{
69 while(!(inb(TTYS0_BASE + UART_LSR) & 0x40))
70 ;
71}
72
73static void uart_tx_byte(unsigned char data)
74{
75 uart_wait_to_tx_byte();
76 outb(data, TTYS0_BASE + UART_TBR);
77 /* Make certain the data clears the fifos */
78 uart_wait_until_sent();
79}
80
81
82void uart_init(void)
83{
84 /* disable interrupts */
85 outb(0x0, TTYS0_BASE + UART_IER);
86 /* enable fifo's */
87 outb(0x01, TTYS0_BASE + UART_FCR);
88 /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
89 outb(0x80 | UART_LCS, TTYS0_BASE + UART_LCR);
90 outb(TTYS0_DIV & 0xFF, TTYS0_BASE + UART_DLL);
91 outb((TTYS0_DIV >> 8) & 0xFF, TTYS0_BASE + UART_DLM);
92 outb(UART_LCS, TTYS0_BASE + UART_LCR);
93}
94
95
96void __console_tx_char(unsigned char byte)
97{
98 uart_tx_byte(byte);
99
100}
101
102void __console_tx_string(char *str)
103{
104 unsigned char ch;
105 while((ch = *str++) != '\0') {
106 __console_tx_char(ch);
107 }
108}
109
110
111void print_debug_char(unsigned char byte) { __console_tx_char(byte); }
112void print_debug(char *str) { __console_tx_string(str); }
113
114void main(void)
115{
116 static const char msg[] = "hello world\r\n";
117 uart_init();
118#if 0
119 print_debug(msg);
120#endif
121#if 1
122 print_debug("hello world\r\n");
123#endif
124 while(1) {
125 ;
126 }
127}