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
;
180 SEMIHOST_FILE_REMOVE_BLOCK RemoveBlock
;
183 // Remove any leading separator (e.g.: '\'). EFI Shell adds one.
184 if (*FileName
== '\\') {
188 RemoveBlock
.FileName
= FileName
;
189 RemoveBlock
.NameLength
= AsciiStrLen(FileName
);
191 Result
= Semihost_SYS_REMOVE(&RemoveBlock
);
194 return RETURN_SUCCESS
;
196 return RETURN_ABORTED
;
201 SemihostReadCharacter (
205 return Semihost_SYS_READC();
209 SemihostWriteCharacter (
213 Semihost_SYS_WRITEC(&Character
);
217 SemihostWriteString (
221 Semihost_SYS_WRITE0(String
);
226 IN CHAR8
*CommandLine
229 SEMIHOST_SYSTEM_BLOCK SystemBlock
;
231 SystemBlock
.CommandLine
= CommandLine
;
232 SystemBlock
.CommandLength
= AsciiStrLen(CommandLine
);
234 return Semihost_SYS_SYSTEM(&SystemBlock
);