3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR>
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
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.
17 #include <Library/BaseLib.h>
18 #include <Library/SemihostLib.h>
20 #include "SemihostPrivate.h"
23 SemihostConnectionSupported (
27 return SEMIHOST_SUPPORTED
;
37 SEMIHOST_FILE_OPEN_BLOCK OpenBlock
;
40 if (FileHandle
== NULL
) {
41 return RETURN_INVALID_PARAMETER
;
44 // Remove any leading separator (e.g.: '\'). EFI Shell adds one.
45 if (*FileName
== '\\') {
49 OpenBlock
.FileName
= FileName
;
50 OpenBlock
.Mode
= Mode
;
51 OpenBlock
.NameLength
= AsciiStrLen(FileName
);
53 Result
= Semihost_SYS_OPEN(&OpenBlock
);
56 return RETURN_NOT_FOUND
;
59 return RETURN_SUCCESS
;
69 SEMIHOST_FILE_SEEK_BLOCK SeekBlock
;
72 SeekBlock
.Handle
= FileHandle
;
73 SeekBlock
.Location
= Offset
;
75 Result
= Semihost_SYS_SEEK(&SeekBlock
);
77 // Semihosting does not behave as documented. It returns the offset on
80 return RETURN_ABORTED
;
82 return RETURN_SUCCESS
;
93 SEMIHOST_FILE_READ_WRITE_BLOCK ReadBlock
;
96 if ((Length
== NULL
) || (Buffer
== NULL
)) {
97 return RETURN_INVALID_PARAMETER
;
100 ReadBlock
.Handle
= FileHandle
;
101 ReadBlock
.Buffer
= Buffer
;
102 ReadBlock
.Length
= *Length
;
104 Result
= Semihost_SYS_READ(&ReadBlock
);
106 if ((*Length
!= 0) && (Result
== *Length
)) {
107 return RETURN_ABORTED
;
110 return RETURN_SUCCESS
;
117 IN OUT UINTN
*Length
,
121 SEMIHOST_FILE_READ_WRITE_BLOCK WriteBlock
;
123 if ((Length
== NULL
) || (Buffer
== NULL
)) {
124 return RETURN_INVALID_PARAMETER
;
127 WriteBlock
.Handle
= FileHandle
;
128 WriteBlock
.Buffer
= Buffer
;
129 WriteBlock
.Length
= *Length
;
131 *Length
= Semihost_SYS_WRITE(&WriteBlock
);
134 return RETURN_ABORTED
;
136 return RETURN_SUCCESS
;
144 INT32 Result
= Semihost_SYS_CLOSE(&FileHandle
);
147 return RETURN_INVALID_PARAMETER
;
149 return RETURN_SUCCESS
;
161 if (Length
== NULL
) {
162 return RETURN_INVALID_PARAMETER
;
165 Result
= Semihost_SYS_FLEN(&FileHandle
);
168 return RETURN_ABORTED
;
171 return RETURN_SUCCESS
;
176 Get a temporary name for a file from the host running the debug agent.
178 @param[out] Buffer Pointer to the buffer where the temporary name has to
180 @param[in] Identifier File name identifier (integer in the range 0 to 255)
181 @param[in] Length Length of the buffer to store the temporary name
183 @retval RETURN_SUCCESS Temporary name returned
184 @retval RETURN_INVALID_PARAMETER Invalid buffer address
185 @retval RETURN_ABORTED Temporary name not returned
195 SEMIHOST_FILE_TMPNAME_BLOCK TmpNameBlock
;
198 if (Buffer
== NULL
) {
199 return RETURN_INVALID_PARAMETER
;
202 TmpNameBlock
.Buffer
= Buffer
;
203 TmpNameBlock
.Identifier
= Identifier
;
204 TmpNameBlock
.Length
= Length
;
206 Result
= Semihost_SYS_TMPNAME (&TmpNameBlock
);
209 return RETURN_ABORTED
;
211 return RETURN_SUCCESS
;
220 SEMIHOST_FILE_REMOVE_BLOCK RemoveBlock
;
223 // Remove any leading separator (e.g.: '\'). EFI Shell adds one.
224 if (*FileName
== '\\') {
228 RemoveBlock
.FileName
= FileName
;
229 RemoveBlock
.NameLength
= AsciiStrLen(FileName
);
231 Result
= Semihost_SYS_REMOVE(&RemoveBlock
);
234 return RETURN_SUCCESS
;
236 return RETURN_ABORTED
;
241 Rename a specified file.
243 @param[in] FileName Name of the file to rename.
244 @param[in] NewFileName The new name of the file.
246 @retval RETURN_SUCCESS File Renamed
247 @retval RETURN_INVALID_PARAMETER Either the current or the new name is not specified
248 @retval RETURN_ABORTED Rename failed
254 IN CHAR8
*NewFileName
257 SEMIHOST_FILE_RENAME_BLOCK RenameBlock
;
260 if ((FileName
== NULL
) || (NewFileName
== NULL
)) {
261 return RETURN_INVALID_PARAMETER
;
264 RenameBlock
.FileName
= FileName
;
265 RenameBlock
.FileNameLength
= AsciiStrLen (FileName
);
266 RenameBlock
.NewFileName
= NewFileName
;
267 RenameBlock
.NewFileNameLength
= AsciiStrLen (NewFileName
);
269 Result
= Semihost_SYS_RENAME (&RenameBlock
);
272 return RETURN_ABORTED
;
274 return RETURN_SUCCESS
;
279 SemihostReadCharacter (
283 return Semihost_SYS_READC();
287 SemihostWriteCharacter (
291 Semihost_SYS_WRITEC(&Character
);
295 SemihostWriteString (
299 Semihost_SYS_WRITE0(String
);
304 IN CHAR8
*CommandLine
307 SEMIHOST_SYSTEM_BLOCK SystemBlock
;
309 SystemBlock
.CommandLine
= CommandLine
;
310 SystemBlock
.CommandLength
= AsciiStrLen(CommandLine
);
312 return Semihost_SYS_SYSTEM(&SystemBlock
);