]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/SemihostLib/Arm/SemihostLib.c
Updating ArmLib.h to add functions needed to turn on paging in CpuDxe. Also added...
[mirror_edk2.git] / ArmPkg / Library / SemihostLib / Arm / SemihostLib.c
CommitLineData
2ef2b01e
A
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
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
39 if (FileHandle == NULL)
40 return EFI_INVALID_PARAMETER;
41
42 OpenBlock.FileName = FileName;
43 OpenBlock.Mode = Mode;
44 OpenBlock.NameLength = AsciiStrLen(FileName);
45
46 Result = Semihost_SYS_OPEN(&OpenBlock);
47
48 if (Result == -1)
49 {
50 return EFI_NOT_FOUND;
51 }
52 else
53 {
54 *FileHandle = Result;
55 return EFI_SUCCESS;
56 }
57}
58
59EFI_STATUS
60SemihostFileSeek (
61 IN UINT32 FileHandle,
62 IN UINT32 Offset
63 )
64{
65 SEMIHOST_FILE_SEEK_BLOCK SeekBlock;
66 INT32 Result;
67
68 SeekBlock.Handle = FileHandle;
69 SeekBlock.Location = Offset;
70
71 Result = Semihost_SYS_SEEK(&SeekBlock);
72
73 if (Result == 0)
74 return EFI_SUCCESS;
75 else
76 return EFI_ABORTED;
77}
78
79EFI_STATUS
80SemihostFileRead (
81 IN UINT32 FileHandle,
82 IN OUT UINT32 *Length,
83 OUT VOID *Buffer
84 )
85{
86 SEMIHOST_FILE_READ_WRITE_BLOCK ReadBlock;
87 UINT32 Result;
88
89 if ((Length == NULL) || (Buffer == NULL))
90 return EFI_INVALID_PARAMETER;
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 {
100 return EFI_ABORTED;
101 }
102 else
103 {
104 *Length -= Result;
105 return EFI_SUCCESS;
106 }
107}
108
109EFI_STATUS
110SemihostFileWrite (
111 IN UINT32 FileHandle,
112 IN OUT UINT32 *Length,
113 IN VOID *Buffer
114 )
115{
116 SEMIHOST_FILE_READ_WRITE_BLOCK WriteBlock;
117
118 if ((Length == NULL) || (Buffer == NULL))
119 return EFI_INVALID_PARAMETER;
120
121 WriteBlock.Handle = FileHandle;
122 WriteBlock.Buffer = Buffer;
123 WriteBlock.Length = *Length;
124
125 *Length = Semihost_SYS_WRITE(&WriteBlock);
126
127 return EFI_SUCCESS;
128}
129
130EFI_STATUS
131SemihostFileClose (
132 IN UINT32 FileHandle
133 )
134{
135 INT32 Result = Semihost_SYS_CLOSE(&FileHandle);
136
137 if (Result == -1)
138 return EFI_INVALID_PARAMETER;
139 else
140 return EFI_SUCCESS;
141}
142
143EFI_STATUS
144SemihostFileLength (
145 IN UINT32 FileHandle,
146 OUT UINT32 *Length
147 )
148{
149 INT32 Result;
150
151 if (Length == NULL)
152 return EFI_INVALID_PARAMETER;
153
154 Result = Semihost_SYS_FLEN(&FileHandle);
155
156 if (Result == -1)
157 {
158 return EFI_ABORTED;
159 }
160 else
161 {
162 *Length = Result;
163 return EFI_SUCCESS;
164 }
165}
166
167EFI_STATUS
168SemihostFileRemove (
169 IN CHAR8 *FileName
170 )
171{
172 SEMIHOST_FILE_REMOVE_BLOCK RemoveBlock;
173 UINT32 Result;
174
175 RemoveBlock.FileName = FileName;
176 RemoveBlock.NameLength = AsciiStrLen(FileName);
177
178 Result = Semihost_SYS_REMOVE(&RemoveBlock);
179
180 if (Result == 0)
181 return EFI_SUCCESS;
182 else
183 return EFI_ABORTED;
184}
185
186CHAR8
187SemihostReadCharacter (
188 VOID
189 )
190{
191 return Semihost_SYS_READC();
192}
193
194VOID
195SemihostWriteCharacter (
196 IN CHAR8 Character
197 )
198{
199 Semihost_SYS_WRITEC(&Character);
200}
201
202VOID
203SemihostWriteString (
204 IN CHAR8 *String
205 )
206{
207 Semihost_SYS_WRITE0(String);
208}
209
210UINT32
211SemihostSystem (
212 IN CHAR8 *CommandLine
213 )
214{
215 SEMIHOST_SYSTEM_BLOCK SystemBlock;
216
217 SystemBlock.CommandLine = CommandLine;
218 SystemBlock.CommandLength = AsciiStrLen(CommandLine);
219
220 return Semihost_SYS_SYSTEM(&SystemBlock);
221}