3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/SemihostLib.h>
19 #include "SemihostPrivate.h"
22 SemihostConnectionSupported (
26 return SEMIHOST_SUPPORTED
;
36 SEMIHOST_FILE_OPEN_BLOCK OpenBlock
;
39 if (FileHandle
== NULL
) {
40 return RETURN_INVALID_PARAMETER
;
43 // Remove any leading separator (e.g.: '\'). EFI Shell adds one.
44 if (*FileName
== '\\') {
48 OpenBlock
.FileName
= FileName
;
49 OpenBlock
.Mode
= Mode
;
50 OpenBlock
.NameLength
= AsciiStrLen(FileName
);
52 Result
= Semihost_SYS_OPEN(&OpenBlock
);
55 return RETURN_NOT_FOUND
;
58 return RETURN_SUCCESS
;
68 SEMIHOST_FILE_SEEK_BLOCK SeekBlock
;
71 SeekBlock
.Handle
= FileHandle
;
72 SeekBlock
.Location
= Offset
;
74 Result
= Semihost_SYS_SEEK(&SeekBlock
);
77 return RETURN_SUCCESS
;
79 return RETURN_ABORTED
;
90 SEMIHOST_FILE_READ_WRITE_BLOCK ReadBlock
;
93 if ((Length
== NULL
) || (Buffer
== NULL
)) {
94 return RETURN_INVALID_PARAMETER
;
97 ReadBlock
.Handle
= FileHandle
;
98 ReadBlock
.Buffer
= Buffer
;
99 ReadBlock
.Length
= *Length
;
101 Result
= Semihost_SYS_READ(&ReadBlock
);
103 if (Result
== *Length
) {
104 return RETURN_ABORTED
;
107 return RETURN_SUCCESS
;
114 IN OUT UINTN
*Length
,
118 SEMIHOST_FILE_READ_WRITE_BLOCK WriteBlock
;
120 if ((Length
== NULL
) || (Buffer
== NULL
)) {
121 return RETURN_INVALID_PARAMETER
;
124 WriteBlock
.Handle
= FileHandle
;
125 WriteBlock
.Buffer
= Buffer
;
126 WriteBlock
.Length
= *Length
;
128 *Length
= Semihost_SYS_WRITE(&WriteBlock
);
130 return RETURN_SUCCESS
;
138 INT32 Result
= Semihost_SYS_CLOSE(&FileHandle
);
141 return RETURN_INVALID_PARAMETER
;
143 return RETURN_SUCCESS
;
155 if (Length
== NULL
) {
156 return RETURN_INVALID_PARAMETER
;
159 Result
= Semihost_SYS_FLEN(&FileHandle
);
162 return RETURN_ABORTED
;
165 return RETURN_SUCCESS
;
174 SEMIHOST_FILE_REMOVE_BLOCK RemoveBlock
;
177 RemoveBlock
.FileName
= FileName
;
178 RemoveBlock
.NameLength
= AsciiStrLen(FileName
);
180 Result
= Semihost_SYS_REMOVE(&RemoveBlock
);
183 return RETURN_SUCCESS
;
185 return RETURN_ABORTED
;
190 SemihostReadCharacter (
194 return Semihost_SYS_READC();
198 SemihostWriteCharacter (
202 Semihost_SYS_WRITEC(&Character
);
206 SemihostWriteString (
210 Semihost_SYS_WRITE0(String
);
215 IN CHAR8
*CommandLine
218 SEMIHOST_SYSTEM_BLOCK SystemBlock
;
220 SystemBlock
.CommandLine
= CommandLine
;
221 SystemBlock
.CommandLength
= AsciiStrLen(CommandLine
);
223 return Semihost_SYS_SYSTEM(&SystemBlock
);