]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/SemihostLib/Arm/SemihostLib.c
Update the copyright notice format
[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**/
14#include <Uefi.h>
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
29EFI_STATUS
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) {
2ef2b01e 40 return EFI_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) {
2ef2b01e 50 return EFI_NOT_FOUND;
225290eb 51 } else {
2ef2b01e
A
52 *FileHandle = Result;
53 return EFI_SUCCESS;
54 }
55}
56
57EFI_STATUS
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) {
2ef2b01e 72 return EFI_SUCCESS;
225290eb 73 } else {
2ef2b01e 74 return EFI_ABORTED;
225290eb 75 }
2ef2b01e
A
76}
77
78EFI_STATUS
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
A
88 if ((Length == NULL) || (Buffer == NULL)) {
89 return EFI_INVALID_PARAMETER;
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) {
2ef2b01e 99 return EFI_ABORTED;
225290eb 100 } else {
2ef2b01e
A
101 *Length -= Result;
102 return EFI_SUCCESS;
103 }
104}
105
106EFI_STATUS
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)) {
2ef2b01e 116 return EFI_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
125 return EFI_SUCCESS;
126}
127
128EFI_STATUS
129SemihostFileClose (
130 IN UINT32 FileHandle
131 )
132{
133 INT32 Result = Semihost_SYS_CLOSE(&FileHandle);
134
225290eb 135 if (Result == -1) {
2ef2b01e 136 return EFI_INVALID_PARAMETER;
225290eb 137 } else {
2ef2b01e 138 return EFI_SUCCESS;
225290eb 139 }
2ef2b01e
A
140}
141
142EFI_STATUS
143SemihostFileLength (
144 IN UINT32 FileHandle,
145 OUT UINT32 *Length
146 )
147{
148 INT32 Result;
149
225290eb 150 if (Length == NULL) {
2ef2b01e 151 return EFI_INVALID_PARAMETER;
225290eb 152 }
2ef2b01e
A
153
154 Result = Semihost_SYS_FLEN(&FileHandle);
155
225290eb 156 if (Result == -1) {
2ef2b01e 157 return EFI_ABORTED;
225290eb 158 } else {
2ef2b01e
A
159 *Length = Result;
160 return EFI_SUCCESS;
161 }
162}
163
164EFI_STATUS
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) {
2ef2b01e 178 return EFI_SUCCESS;
225290eb 179 } else {
2ef2b01e 180 return EFI_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}