]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/SemiHostingSerialPortLib/SerialPortLib.c
Updated to support passing PE/COFF and LZMA decompress up via HOBS. Currently turned...
[mirror_edk2.git] / EmbeddedPkg / Library / SemiHostingSerialPortLib / SerialPortLib.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Serial I/O Port library functions with no library constructor/destructor\r
3\r
4\r
5 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
6 \r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Uefi.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/SemihostLib.h>\r
20#include <Library/SerialPortLib.h>\r
21\r
22\r
23/*\r
24\r
25 Programmed hardware of Serial port.\r
26\r
27 @return Always return EFI_UNSUPPORTED.\r
28\r
29**/\r
30RETURN_STATUS\r
31EFIAPI\r
32SerialPortInitialize (\r
33 VOID\r
34 )\r
35{\r
36 if (SemihostConnectionSupported ()) {\r
37 return RETURN_SUCCESS;\r
38 } else {\r
39 return RETURN_UNSUPPORTED;\r
40 }\r
41}\r
42\r
43/**\r
44 Write data to serial device.\r
45\r
46 @param Buffer Point of data buffer which need to be writed.\r
47 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
48\r
49 @retval 0 Write data failed.\r
50 @retval !0 Actual number of bytes writed to serial device.\r
51\r
52**/\r
53\r
54#define PRINT_BUFFER_SIZE 512\r
55#define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)\r
56\r
57UINTN\r
58EFIAPI\r
59SerialPortWrite (\r
60 IN UINT8 *Buffer,\r
61 IN UINTN NumberOfBytes\r
62)\r
63{\r
64 UINT8 PrintBuffer[PRINT_BUFFER_SIZE];\r
65 UINTN SourceIndex = 0;\r
66 UINTN DestinationIndex = 0;\r
67 UINT8 CurrentCharacter;\r
68\r
69 while (SourceIndex < NumberOfBytes)\r
70 {\r
71 CurrentCharacter = Buffer[SourceIndex++];\r
72 \r
73 switch (CurrentCharacter)\r
74 {\r
75 case '\r':\r
76 continue;\r
77\r
78 case '\n':\r
79 PrintBuffer[DestinationIndex++] = ' ';\r
80 // fall through\r
81\r
82 default:\r
83 PrintBuffer[DestinationIndex++] = CurrentCharacter;\r
84 break;\r
85 }\r
86\r
87 if (DestinationIndex > PRINT_BUFFER_THRESHOLD)\r
88 {\r
89 PrintBuffer[DestinationIndex] = '\0';\r
90 SemihostWriteString ((CHAR8 *) PrintBuffer);\r
91\r
92 DestinationIndex = 0;\r
93 }\r
94 }\r
95 \r
96 if (DestinationIndex > 0)\r
97 {\r
98 PrintBuffer[DestinationIndex] = '\0';\r
99 SemihostWriteString ((CHAR8 *) PrintBuffer);\r
100 }\r
101\r
102 return 0;\r
103}\r
104\r
105\r
106/**\r
107 Read data from serial device and save the datas in buffer.\r
108\r
109 @param Buffer Point of data buffer which need to be writed.\r
110 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
111\r
112 @retval 0 Read data failed.\r
113 @retval !0 Aactual number of bytes read from serial device.\r
114\r
115**/\r
116UINTN\r
117EFIAPI\r
118SerialPortRead (\r
119 OUT UINT8 *Buffer,\r
120 IN UINTN NumberOfBytes\r
121)\r
122{\r
123 *Buffer = SemihostReadCharacter ();\r
124 return 1;\r
125}\r
126\r
127\r
128\r
129/**\r
130 Check to see if any data is avaiable to be read from the debug device.\r
131\r
132 @retval TRUE At least one byte of data is avaiable to be read\r
133 @retval FALS No data is avaiable to be read\r
134\r
135**/\r
136BOOLEAN\r
137EFIAPI\r
138SerialPortPoll (\r
139 VOID\r
140 )\r
141{\r
142 // Since SemiHosting read character is blocking always say we have a char ready?\r
143 return SemihostConnectionSupported ();\r
144}\r
145\r