]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/SemiHostingSerialPortLib/SerialPortLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Library / SemiHostingSerialPortLib / SerialPortLib.c
index bd8f5b81994c198c911e34e1fc39ac334e76e600..5ff8a5b7a62e1e0291d6247dce8c87947e0a53be 100644 (file)
@@ -2,14 +2,9 @@
   Serial I/O Port library functions with no library constructor/destructor\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,7 +13,6 @@
 #include <Library/SemihostLib.h>\r
 #include <Library/SerialPortLib.h>\r
 \r
-\r
 /*\r
 \r
   Programmed hardware of Serial port.\r
@@ -42,11 +36,11 @@ SerialPortInitialize (
 /**\r
   Write data to serial device.\r
 \r
-  @param  Buffer           Point of data buffer which need to be writed.\r
+  @param  Buffer           Point of data buffer which need to be written.\r
   @param  NumberOfBytes    Number of output bytes which are cached in Buffer.\r
 \r
   @retval 0                Write data failed.\r
-  @retval !0               Actual number of bytes writed to serial device.\r
+  @retval !0               Actual number of bytes written to serial device.\r
 \r
 **/\r
 \r
@@ -56,80 +50,76 @@ SerialPortInitialize (
 UINTN\r
 EFIAPI\r
 SerialPortWrite (\r
-  IN UINT8     *Buffer,\r
-  IN UINTN     NumberOfBytes\r
-)\r
+  IN UINT8  *Buffer,\r
+  IN UINTN  NumberOfBytes\r
+  )\r
 {\r
-  UINT8 PrintBuffer[PRINT_BUFFER_SIZE];\r
-  UINTN SourceIndex      = 0;\r
-  UINTN DestinationIndex = 0;\r
-  UINT8 CurrentCharacter;\r
-\r
-  while (SourceIndex < NumberOfBytes)\r
-  {\r
-      CurrentCharacter = Buffer[SourceIndex++];\r
-      \r
-      switch (CurrentCharacter)\r
-      {\r
+  UINT8  PrintBuffer[PRINT_BUFFER_SIZE];\r
+  UINTN  SourceIndex;\r
+  UINTN  DestinationIndex;\r
+  UINT8  CurrentCharacter;\r
+\r
+  SourceIndex      = 0;\r
+  DestinationIndex = 0;\r
+\r
+  while (SourceIndex < NumberOfBytes) {\r
+    CurrentCharacter = Buffer[SourceIndex++];\r
+\r
+    switch (CurrentCharacter) {\r
       case '\r':\r
-          continue;\r
+        continue;\r
 \r
       case '\n':\r
-          PrintBuffer[DestinationIndex++] = ' ';\r
-          // fall through\r
+        PrintBuffer[DestinationIndex++] = ' ';\r
+      // fall through\r
 \r
       default:\r
-          PrintBuffer[DestinationIndex++] = CurrentCharacter;\r
-          break;\r
-      }\r
+        PrintBuffer[DestinationIndex++] = CurrentCharacter;\r
+        break;\r
+    }\r
 \r
-      if (DestinationIndex > PRINT_BUFFER_THRESHOLD)\r
-      {\r
-          PrintBuffer[DestinationIndex] = '\0';\r
-          SemihostWriteString ((CHAR8 *) PrintBuffer);\r
+    if (DestinationIndex > PRINT_BUFFER_THRESHOLD) {\r
+      PrintBuffer[DestinationIndex] = '\0';\r
+      SemihostWriteString ((CHAR8 *)PrintBuffer);\r
 \r
-          DestinationIndex = 0;\r
-      }\r
+      DestinationIndex = 0;\r
+    }\r
   }\r
-  \r
-  if (DestinationIndex > 0)\r
-  {\r
-      PrintBuffer[DestinationIndex] = '\0';\r
-      SemihostWriteString ((CHAR8 *) PrintBuffer);\r
+\r
+  if (DestinationIndex > 0) {\r
+    PrintBuffer[DestinationIndex] = '\0';\r
+    SemihostWriteString ((CHAR8 *)PrintBuffer);\r
   }\r
 \r
-  return 0;\r
+  return NumberOfBytes;\r
 }\r
 \r
-\r
 /**\r
   Read data from serial device and save the datas in buffer.\r
 \r
-  @param  Buffer           Point of data buffer which need to be writed.\r
+  @param  Buffer           Point of data buffer which need to be written.\r
   @param  NumberOfBytes    Number of output bytes which are cached in Buffer.\r
 \r
   @retval 0                Read data failed.\r
-  @retval !0               Aactual number of bytes read from serial device.\r
+  @retval !0               Actual number of bytes read from serial device.\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 SerialPortRead (\r
-  OUT UINT8     *Buffer,\r
-  IN  UINTN     NumberOfBytes\r
-)\r
+  OUT UINT8  *Buffer,\r
+  IN  UINTN  NumberOfBytes\r
+  )\r
 {\r
   *Buffer = SemihostReadCharacter ();\r
   return 1;\r
 }\r
 \r
-\r
-\r
 /**\r
-  Check to see if any data is avaiable to be read from the debug device.\r
+  Check to see if any data is available to be read from the debug device.\r
 \r
-  @retval TRUE       At least one byte of data is avaiable to be read\r
-  @retval FALSE      No data is avaiable to be read\r
+  @retval TRUE       At least one byte of data is available to be read\r
+  @retval FALSE      No data is available to be read\r
 \r
 **/\r
 BOOLEAN\r
@@ -141,4 +131,3 @@ SerialPortPoll (
   // Since SemiHosting read character is blocking always say we have a char ready?\r
   return SemihostConnectionSupported ();\r
 }\r
-\r