]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/SemihostLib/Arm/SemihostLib.c
MdeModulePkg: Fix EHCI module build warning reported by VS2005 tool chain.
[mirror_edk2.git] / ArmPkg / Library / SemihostLib / Arm / SemihostLib.c
CommitLineData
2ef2b01e
A
1/** @file
2
d6ebcab7 3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
2ef2b01e 4
d6ebcab7 5 This program and the accompanying materials
2ef2b01e
A
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
9
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.
12
13**/
afb9f4da 14#include <Base.h>
2ef2b01e
A
15
16#include <Library/BaseLib.h>
17#include <Library/SemihostLib.h>
18
19#include "SemihostPrivate.h"
20
21BOOLEAN
22SemihostConnectionSupported (
23 VOID
24 )
25{
26 return SEMIHOST_SUPPORTED;
27}
28
afb9f4da 29RETURN_STATUS
2ef2b01e
A
30SemihostFileOpen (
31 IN CHAR8 *FileName,
32 IN UINT32 Mode,
33 OUT UINT32 *FileHandle
34 )
35{
36 SEMIHOST_FILE_OPEN_BLOCK OpenBlock;
37 INT32 Result;
38
225290eb 39 if (FileHandle == NULL) {
afb9f4da 40 return RETURN_INVALID_PARAMETER;
225290eb 41 }
2ef2b01e
A
42
43 OpenBlock.FileName = FileName;
44 OpenBlock.Mode = Mode;
45 OpenBlock.NameLength = AsciiStrLen(FileName);
46
47 Result = Semihost_SYS_OPEN(&OpenBlock);
48
225290eb 49 if (Result == -1) {
afb9f4da 50 return RETURN_NOT_FOUND;
225290eb 51 } else {
2ef2b01e 52 *FileHandle = Result;
afb9f4da 53 return RETURN_SUCCESS;
2ef2b01e
A
54 }
55}
56
afb9f4da 57RETURN_STATUS
2ef2b01e
A
58SemihostFileSeek (
59 IN UINT32 FileHandle,
60 IN UINT32 Offset
61 )
62{
63 SEMIHOST_FILE_SEEK_BLOCK SeekBlock;
64 INT32 Result;
65
66 SeekBlock.Handle = FileHandle;
67 SeekBlock.Location = Offset;
68
69 Result = Semihost_SYS_SEEK(&SeekBlock);
70
225290eb 71 if (Result == 0) {
afb9f4da 72 return RETURN_SUCCESS;
225290eb 73 } else {
afb9f4da 74 return RETURN_ABORTED;
225290eb 75 }
2ef2b01e
A
76}
77
afb9f4da 78RETURN_STATUS
2ef2b01e
A
79SemihostFileRead (
80 IN UINT32 FileHandle,
81 IN OUT UINT32 *Length,
82 OUT VOID *Buffer
83 )
84{
85 SEMIHOST_FILE_READ_WRITE_BLOCK ReadBlock;
86 UINT32 Result;
87
225290eb 88 if ((Length == NULL) || (Buffer == NULL)) {
afb9f4da 89 return RETURN_INVALID_PARAMETER;
225290eb 90 }
2ef2b01e
A
91
92 ReadBlock.Handle = FileHandle;
93 ReadBlock.Buffer = Buffer;
94 ReadBlock.Length = *Length;
95
96 Result = Semihost_SYS_READ(&ReadBlock);
97
225290eb 98 if (Result == *Length) {
afb9f4da 99 return RETURN_ABORTED;
225290eb 100 } else {
2ef2b01e 101 *Length -= Result;
afb9f4da 102 return RETURN_SUCCESS;
2ef2b01e
A
103 }
104}
105
afb9f4da 106RETURN_STATUS
2ef2b01e
A
107SemihostFileWrite (
108 IN UINT32 FileHandle,
109 IN OUT UINT32 *Length,
110 IN VOID *Buffer
111 )
112{
113 SEMIHOST_FILE_READ_WRITE_BLOCK WriteBlock;
114
225290eb 115 if ((Length == NULL) || (Buffer == NULL)) {
afb9f4da 116 return RETURN_INVALID_PARAMETER;
225290eb 117 }
2ef2b01e
A
118
119 WriteBlock.Handle = FileHandle;
120 WriteBlock.Buffer = Buffer;
121 WriteBlock.Length = *Length;
122
123 *Length = Semihost_SYS_WRITE(&WriteBlock);
124
afb9f4da 125 return RETURN_SUCCESS;
2ef2b01e
A
126}
127
afb9f4da 128RETURN_STATUS
2ef2b01e
A
129SemihostFileClose (
130 IN UINT32 FileHandle
131 )
132{
133 INT32 Result = Semihost_SYS_CLOSE(&FileHandle);
134
225290eb 135 if (Result == -1) {
afb9f4da 136 return RETURN_INVALID_PARAMETER;
225290eb 137 } else {
afb9f4da 138 return RETURN_SUCCESS;
225290eb 139 }
2ef2b01e
A
140}
141
afb9f4da 142RETURN_STATUS
2ef2b01e
A
143SemihostFileLength (
144 IN UINT32 FileHandle,
145 OUT UINT32 *Length
146 )
147{
148 INT32 Result;
149
225290eb 150 if (Length == NULL) {
afb9f4da 151 return RETURN_INVALID_PARAMETER;
225290eb 152 }
2ef2b01e
A
153
154 Result = Semihost_SYS_FLEN(&FileHandle);
155
225290eb 156 if (Result == -1) {
afb9f4da 157 return RETURN_ABORTED;
225290eb 158 } else {
2ef2b01e 159 *Length = Result;
afb9f4da 160 return RETURN_SUCCESS;
2ef2b01e
A
161 }
162}
163
afb9f4da 164RETURN_STATUS
2ef2b01e
A
165SemihostFileRemove (
166 IN CHAR8 *FileName
167 )
168{
169 SEMIHOST_FILE_REMOVE_BLOCK RemoveBlock;
170 UINT32 Result;
171
172 RemoveBlock.FileName = FileName;
173 RemoveBlock.NameLength = AsciiStrLen(FileName);
174
175 Result = Semihost_SYS_REMOVE(&RemoveBlock);
176
225290eb 177 if (Result == 0) {
afb9f4da 178 return RETURN_SUCCESS;
225290eb 179 } else {
afb9f4da 180 return RETURN_ABORTED;
225290eb 181 }
2ef2b01e
A
182}
183
184CHAR8
185SemihostReadCharacter (
186 VOID
187 )
188{
189 return Semihost_SYS_READC();
190}
191
192VOID
193SemihostWriteCharacter (
194 IN CHAR8 Character
195 )
196{
197 Semihost_SYS_WRITEC(&Character);
198}
199
200VOID
201SemihostWriteString (
202 IN CHAR8 *String
203 )
204{
205 Semihost_SYS_WRITE0(String);
206}
207
208UINT32
209SemihostSystem (
210 IN CHAR8 *CommandLine
211 )
212{
213 SEMIHOST_SYSTEM_BLOCK SystemBlock;
214
215 SystemBlock.CommandLine = CommandLine;
216 SystemBlock.CommandLength = AsciiStrLen(CommandLine);
217
218 return Semihost_SYS_SYSTEM(&SystemBlock);
219}