]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/SemihostLib: Add library functions
authorRonald Cron <ronald.cron@arm.com>
Mon, 27 Oct 2014 10:38:18 +0000 (10:38 +0000)
committeroliviermartin <oliviermartin@Edk2>
Mon, 27 Oct 2014 10:38:18 +0000 (10:38 +0000)
Add library functions to rename a file and get a temporary name
for a file through the semi-hosting interface.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16238 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Include/Library/SemihostLib.h
ArmPkg/Library/SemihostLib/SemihostLib.c
ArmPkg/Library/SemihostLib/SemihostPrivate.h

index 4e4f43d8bd8814a69ce1bba119cb75fa183eb1fd..4a91593e31fb9ee2a6c9cb5e96e90ed5964f0fc0 100644 (file)
@@ -73,11 +73,48 @@ SemihostFileLength (
   OUT UINTN  *Length\r
   );\r
 \r
+/**\r
+  Get a temporary name for a file from the host running the debug agent.\r
+\r
+  @param[out]  Buffer      Pointer to the buffer where the temporary name has to\r
+                           be stored\r
+  @param[in]   Identifier  File name identifier (integer in the range 0 to 255)\r
+  @param[in]   Length      Length of the buffer to store the temporary name\r
+\r
+  @retval  RETURN_SUCCESS            Temporary name returned\r
+  @retval  RETURN_INVALID_PARAMETER  Invalid buffer address\r
+  @retval  RETURN_ABORTED            Temporary name not returned\r
+\r
+**/\r
+RETURN_STATUS\r
+SemihostFileTmpName(\r
+  OUT  VOID   *Buffer,\r
+  IN   UINT8  Identifier,\r
+  IN   UINTN  Length\r
+  );\r
+\r
 RETURN_STATUS\r
 SemihostFileRemove (\r
   IN CHAR8 *FileName\r
   );\r
 \r
+/**\r
+  Rename a specified file.\r
+\r
+  @param[in]  FileName     Name of the file to rename.\r
+  @param[in]  NewFileName  The new name of the file.\r
+\r
+  @retval  RETURN_SUCCESS            File Renamed\r
+  @retval  RETURN_INVALID_PARAMETER  Either the current or the new name is not specified\r
+  @retval  RETURN_ABORTED            Rename failed\r
+\r
+**/\r
+RETURN_STATUS\r
+SemihostFileRename(\r
+  IN  CHAR8  *FileName,\r
+  IN  CHAR8  *NewFileName\r
+  );\r
+\r
 CHAR8\r
 SemihostReadCharacter (\r
   VOID\r
index f93d7991d298dbb9b71bae9c8d15d37df075df35..b1bbcbb392797c32be65ae14030e54db38435616 100644 (file)
@@ -172,6 +172,46 @@ SemihostFileLength (
   }\r
 }\r
 \r
+/**\r
+  Get a temporary name for a file from the host running the debug agent.\r
+\r
+  @param[out]  Buffer      Pointer to the buffer where the temporary name has to\r
+                           be stored\r
+  @param[in]   Identifier  File name identifier (integer in the range 0 to 255)\r
+  @param[in]   Length      Length of the buffer to store the temporary name\r
+\r
+  @retval  RETURN_SUCCESS            Temporary name returned\r
+  @retval  RETURN_INVALID_PARAMETER  Invalid buffer address\r
+  @retval  RETURN_ABORTED            Temporary name not returned\r
+\r
+**/\r
+RETURN_STATUS\r
+SemihostFileTmpName(\r
+  OUT  VOID   *Buffer,\r
+  IN   UINT8  Identifier,\r
+  IN   UINTN  Length\r
+  )\r
+{\r
+  SEMIHOST_FILE_TMPNAME_BLOCK  TmpNameBlock;\r
+  INT32                        Result;\r
+\r
+  if (Buffer == NULL) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  TmpNameBlock.Buffer     = Buffer;\r
+  TmpNameBlock.Identifier = Identifier;\r
+  TmpNameBlock.Length     = Length;\r
+\r
+  Result = Semihost_SYS_TMPNAME (&TmpNameBlock);\r
+\r
+  if (Result != 0) {\r
+    return  RETURN_ABORTED;\r
+  } else {\r
+    return  RETURN_SUCCESS;\r
+  }\r
+}\r
+\r
 RETURN_STATUS\r
 SemihostFileRemove (\r
   IN CHAR8 *FileName\r
@@ -197,6 +237,44 @@ SemihostFileRemove (
   }\r
 }\r
 \r
+/**\r
+  Rename a specified file.\r
+\r
+  @param[in]  FileName     Name of the file to rename.\r
+  @param[in]  NewFileName  The new name of the file.\r
+\r
+  @retval  RETURN_SUCCESS            File Renamed\r
+  @retval  RETURN_INVALID_PARAMETER  Either the current or the new name is not specified\r
+  @retval  RETURN_ABORTED            Rename failed\r
+\r
+**/\r
+RETURN_STATUS\r
+SemihostFileRename(\r
+  IN  CHAR8  *FileName,\r
+  IN  CHAR8  *NewFileName\r
+  )\r
+{\r
+  SEMIHOST_FILE_RENAME_BLOCK  RenameBlock;\r
+  INT32                       Result;\r
+\r
+  if ((FileName == NULL) || (NewFileName == NULL)) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  RenameBlock.FileName          = FileName;\r
+  RenameBlock.FileNameLength    = AsciiStrLen (FileName);\r
+  RenameBlock.NewFileName       = NewFileName;\r
+  RenameBlock.NewFileNameLength = AsciiStrLen (NewFileName);\r
+\r
+  Result = Semihost_SYS_RENAME (&RenameBlock);\r
+\r
+  if (Result != 0) {\r
+    return  RETURN_ABORTED;\r
+  } else {\r
+    return  RETURN_SUCCESS;\r
+  }\r
+}\r
+\r
 CHAR8\r
 SemihostReadCharacter (\r
   VOID\r
index bb0a026d4e33c9ca56558f44e5d03597e32536d0..afc53274b094dc0a3cc5b85db71b7d8dbece5783 100644 (file)
@@ -33,11 +33,24 @@ typedef struct {
   UINTN    Location;\r
 } SEMIHOST_FILE_SEEK_BLOCK;\r
 \r
+typedef struct {\r
+  VOID    *Buffer;\r
+  UINTN    Identifier;\r
+  UINTN    Length;\r
+} SEMIHOST_FILE_TMPNAME_BLOCK;\r
+\r
 typedef struct {\r
   CHAR8   *FileName;\r
   UINTN    NameLength;\r
 } SEMIHOST_FILE_REMOVE_BLOCK;\r
 \r
+typedef struct {\r
+  CHAR8   *FileName;\r
+  UINTN    FileNameLength;\r
+  CHAR8   *NewFileName;\r
+  UINTN    NewFileNameLength;\r
+} SEMIHOST_FILE_RENAME_BLOCK;\r
+\r
 typedef struct {\r
   CHAR8   *CommandLine;\r
   UINTN    CommandLength;\r
@@ -116,6 +129,13 @@ _Semihost_SYS_FLEN(
   IN UINT32 *Handle\r
   );\r
 \r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_TMPNAME(\r
+  IN UINTN                       SWI_0x0D,\r
+  IN SEMIHOST_FILE_TMPNAME_BLOCK *TmpNameBlock\r
+  );\r
+\r
 __swi(SWI)\r
 UINT32\r
 _Semihost_SYS_REMOVE(\r
@@ -123,6 +143,13 @@ _Semihost_SYS_REMOVE(
   IN SEMIHOST_FILE_REMOVE_BLOCK *RemoveBlock\r
   );\r
 \r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_RENAME(\r
+  IN UINTN                      SWI_0x0F,\r
+  IN SEMIHOST_FILE_RENAME_BLOCK *RenameBlock\r
+  );\r
+\r
 __swi(SWI)\r
 UINT32\r
 _Semihost_SYS_SYSTEM(\r
@@ -139,7 +166,9 @@ _Semihost_SYS_SYSTEM(
 #define Semihost_SYS_READC()                _Semihost_SYS_READC(0x07, 0)\r
 #define Semihost_SYS_SEEK(SeekBlock)        _Semihost_SYS_SEEK(0x0A, SeekBlock)\r
 #define Semihost_SYS_FLEN(Handle)           _Semihost_SYS_FLEN(0x0C, Handle)\r
+#define Semihost_SYS_TMPNAME(TmpNameBlock)  _Semihost_SYS_TMPNAME(0x0D, TmpNameBlock)\r
 #define Semihost_SYS_REMOVE(RemoveBlock)    _Semihost_SYS_REMOVE(0x0E, RemoveBlock)\r
+#define Semihost_SYS_RENAME(RenameBlock)    _Semihost_SYS_RENAME(0x0F, RenameBlock)\r
 #define Semihost_SYS_SYSTEM(SystemBlock)    _Semihost_SYS_SYSTEM(0x12, SystemBlock)\r
 \r
 #elif defined(__GNUC__) // __CC_ARM\r
@@ -161,7 +190,9 @@ GccSemihostCall (
 #define Semihost_SYS_READC()                GccSemihostCall(0x07, (UINTN)(0))\r
 #define Semihost_SYS_SEEK(SeekBlock)        GccSemihostCall(0x0A, (UINTN)(SeekBlock))\r
 #define Semihost_SYS_FLEN(Handle)           GccSemihostCall(0x0C, (UINTN)(Handle))\r
+#define Semihost_SYS_TMPNAME(TmpNameBlock)  GccSemihostCall(0x0D, (UINTN)(TmpNameBlock))\r
 #define Semihost_SYS_REMOVE(RemoveBlock)    GccSemihostCall(0x0E, (UINTN)(RemoveBlock))\r
+#define Semihost_SYS_RENAME(RenameBlock)    GccSemihostCall(0x0F, (UINTN)(RenameBlock))\r
 #define Semihost_SYS_SYSTEM(SystemBlock)    GccSemihostCall(0x12, (UINTN)(SystemBlock))\r
 \r
 #else // __CC_ARM\r
@@ -177,7 +208,9 @@ GccSemihostCall (
 #define Semihost_SYS_READC()                ('x')\r
 #define Semihost_SYS_SEEK(SeekBlock)        (-1)\r
 #define Semihost_SYS_FLEN(Handle)           (-1)\r
+#define Semihost_SYS_TMPNAME(TmpNameBlock)  (-1)\r
 #define Semihost_SYS_REMOVE(RemoveBlock)    (-1)\r
+#define Semihost_SYS_RENAME(RenameBlock)    (-1)\r
 #define Semihost_SYS_SYSTEM(SystemBlock)    (-1)\r
 \r
 #endif // __CC_ARM\r