]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/SemihostLib/Arm/SemihostLib.c
31efc0a16e53a97ce93b66b4fab47b7a13f626ab
[mirror_edk2.git] / ArmPkg / Library / SemihostLib / Arm / SemihostLib.c
1 /** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. 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
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
21 BOOLEAN
22 SemihostConnectionSupported (
23 VOID
24 )
25 {
26 return SEMIHOST_SUPPORTED;
27 }
28
29 EFI_STATUS
30 SemihostFileOpen (
31 IN CHAR8 *FileName,
32 IN UINT32 Mode,
33 OUT UINT32 *FileHandle
34 )
35 {
36 SEMIHOST_FILE_OPEN_BLOCK OpenBlock;
37 INT32 Result;
38
39 if (FileHandle == NULL) {
40 return EFI_INVALID_PARAMETER;
41 }
42
43 OpenBlock.FileName = FileName;
44 OpenBlock.Mode = Mode;
45 OpenBlock.NameLength = AsciiStrLen(FileName);
46
47 Result = Semihost_SYS_OPEN(&OpenBlock);
48
49 if (Result == -1) {
50 return EFI_NOT_FOUND;
51 } else {
52 *FileHandle = Result;
53 return EFI_SUCCESS;
54 }
55 }
56
57 EFI_STATUS
58 SemihostFileSeek (
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
71 if (Result == 0) {
72 return EFI_SUCCESS;
73 } else {
74 return EFI_ABORTED;
75 }
76 }
77
78 EFI_STATUS
79 SemihostFileRead (
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
88 if ((Length == NULL) || (Buffer == NULL)) {
89 return EFI_INVALID_PARAMETER;
90 }
91
92 ReadBlock.Handle = FileHandle;
93 ReadBlock.Buffer = Buffer;
94 ReadBlock.Length = *Length;
95
96 Result = Semihost_SYS_READ(&ReadBlock);
97
98 if (Result == *Length) {
99 return EFI_ABORTED;
100 } else {
101 *Length -= Result;
102 return EFI_SUCCESS;
103 }
104 }
105
106 EFI_STATUS
107 SemihostFileWrite (
108 IN UINT32 FileHandle,
109 IN OUT UINT32 *Length,
110 IN VOID *Buffer
111 )
112 {
113 SEMIHOST_FILE_READ_WRITE_BLOCK WriteBlock;
114
115 if ((Length == NULL) || (Buffer == NULL)) {
116 return EFI_INVALID_PARAMETER;
117 }
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
128 EFI_STATUS
129 SemihostFileClose (
130 IN UINT32 FileHandle
131 )
132 {
133 INT32 Result = Semihost_SYS_CLOSE(&FileHandle);
134
135 if (Result == -1) {
136 return EFI_INVALID_PARAMETER;
137 } else {
138 return EFI_SUCCESS;
139 }
140 }
141
142 EFI_STATUS
143 SemihostFileLength (
144 IN UINT32 FileHandle,
145 OUT UINT32 *Length
146 )
147 {
148 INT32 Result;
149
150 if (Length == NULL) {
151 return EFI_INVALID_PARAMETER;
152 }
153
154 Result = Semihost_SYS_FLEN(&FileHandle);
155
156 if (Result == -1) {
157 return EFI_ABORTED;
158 } else {
159 *Length = Result;
160 return EFI_SUCCESS;
161 }
162 }
163
164 EFI_STATUS
165 SemihostFileRemove (
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
177 if (Result == 0) {
178 return EFI_SUCCESS;
179 } else {
180 return EFI_ABORTED;
181 }
182 }
183
184 CHAR8
185 SemihostReadCharacter (
186 VOID
187 )
188 {
189 return Semihost_SYS_READC();
190 }
191
192 VOID
193 SemihostWriteCharacter (
194 IN CHAR8 Character
195 )
196 {
197 Semihost_SYS_WRITEC(&Character);
198 }
199
200 VOID
201 SemihostWriteString (
202 IN CHAR8 *String
203 )
204 {
205 Semihost_SYS_WRITE0(String);
206 }
207
208 UINT32
209 SemihostSystem (
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 }