]>
Commit | Line | Data |
---|---|---|
1 | /** @file | |
2 | Basic serial IO abstaction for GDB | |
3 | ||
4 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> | |
5 | ||
6 | This program and the accompanying materials | |
7 | are licensed and made available under the terms and conditions of the BSD License | |
8 | which accompanies this distribution. The full text of the license may be found at | |
9 | http://opensource.org/licenses/bsd-license.php | |
10 | ||
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
13 | ||
14 | **/ | |
15 | ||
16 | #include <Uefi.h> | |
17 | #include <Library/GdbSerialLib.h> | |
18 | #include <Library/PcdLib.h> | |
19 | #include <Library/IoLib.h> | |
20 | ||
21 | #include <ArmEb/ArmEb.h> | |
22 | ||
23 | RETURN_STATUS | |
24 | EFIAPI | |
25 | GdbSerialLibConstructor ( | |
26 | VOID | |
27 | ) | |
28 | { | |
29 | return GdbSerialInit (115200, 0, 8, 1); | |
30 | } | |
31 | ||
32 | RETURN_STATUS | |
33 | EFIAPI | |
34 | GdbSerialInit ( | |
35 | IN UINT64 BaudRate, | |
36 | IN UINT8 Parity, | |
37 | IN UINT8 DataBits, | |
38 | IN UINT8 StopBits | |
39 | ) | |
40 | { | |
41 | if ((Parity != 0) || (DataBits != 8) || (StopBits != 1)) { | |
42 | return RETURN_UNSUPPORTED; | |
43 | } | |
44 | ||
45 | if (BaudRate != 115200) { | |
46 | // Could add support for different Baud rates.... | |
47 | return RETURN_UNSUPPORTED; | |
48 | } | |
49 | ||
50 | UINT32 Base = PcdGet32 (PcdGdbUartBase);\r | |
51 | \r | |
52 | // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ\r | |
53 | MmioWrite32 (Base + UARTIBRD, UART_115200_IDIV);\r | |
54 | MmioWrite32 (Base + UARTFBRD, UART_115200_FDIV);\r | |
55 | \r | |
56 | // no parity, 1 stop, no fifo, 8 data bits\r | |
57 | MmioWrite32 (Base + UARTLCR_H, 0x60);\r | |
58 | \r | |
59 | // clear any pending errors\r | |
60 | MmioWrite32 (Base + UARTECR, 0);\r | |
61 | \r | |
62 | // enable tx, rx, and uart overall\r | |
63 | MmioWrite32 (Base + UARTCR, 0x301);\r | |
64 | \r | |
65 | return RETURN_SUCCESS;\r | |
66 | } | |
67 | ||
68 | BOOLEAN | |
69 | EFIAPI | |
70 | GdbIsCharAvailable ( | |
71 | VOID | |
72 | ) | |
73 | { | |
74 | UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r | |
75 | \r | |
76 | if ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0) {\r | |
77 | return TRUE;\r | |
78 | } else {\r | |
79 | return FALSE;\r | |
80 | }\r | |
81 | } | |
82 | ||
83 | CHAR8 | |
84 | EFIAPI | |
85 | GdbGetChar ( | |
86 | VOID | |
87 | ) | |
88 | { | |
89 | UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r | |
90 | UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r | |
91 | \r | |
92 | while ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0);\r | |
93 | return MmioRead8 (DR);\r | |
94 | } | |
95 | ||
96 | VOID | |
97 | EFIAPI | |
98 | GdbPutChar ( | |
99 | IN CHAR8 Char | |
100 | ) | |
101 | { | |
102 | UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r | |
103 | UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r | |
104 | \r | |
105 | while ((MmioRead32 (FR) & UART_TX_EMPTY_FLAG_MASK) != 0);\r | |
106 | MmioWrite8 (DR, Char);\r | |
107 | return; | |
108 | } | |
109 | ||
110 | VOID | |
111 | GdbPutString ( | |
112 | IN CHAR8 *String | |
113 | ) | |
114 | { | |
115 | while (*String != '\0') { | |
116 | GdbPutChar (*String); | |
117 | String++; | |
118 | } | |
119 | } | |
120 | ||
121 | ||
122 | ||
123 |