5 Copyright (c) 2012, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <WebServer.h>
18 #include <Library/DxeServicesTableLib.h>
21 CONST
char * mpMemoryType
[ ] = {
30 Page to display the memory map
32 @param [in] SocketFD The socket's file descriptor to add to the list.
33 @param [in] pPort The WSDT_PORT structure address
34 @param [out] pbDone Address to receive the request completion status
36 @retval EFI_SUCCESS The request was successfully processed
47 BOOLEAN bSomethingDisplayed
;
49 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryEnd
;
50 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryDescriptor
;
51 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryDescriptorStart
;
57 // Send the memory map page
59 pMemoryDescriptorStart
= NULL
;
62 // Send the page header
64 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"Memory Map" );
65 if ( EFI_ERROR ( Status
)) {
72 Status
= HttpSendAnsiString ( SocketFD
,
74 "<h1>Memory Map</h1>\r\n"
76 " <tr><th align=\"right\">Type</th><th align=\"right\">Start</th><th align=\"right\">End</th><th align=\"right\">Attributes</th></tr>\r\n" );
77 if ( EFI_ERROR ( Status
)) {
84 Status
= gDS
->GetMemorySpaceMap ( &Count
,
86 if ( !EFI_ERROR ( Status
)) {
87 pMemoryDescriptorStart
= pMemoryDescriptor
;
88 pMemoryEnd
= &pMemoryDescriptor
[ Count
];
89 while ( pMemoryEnd
> pMemoryDescriptor
) {
93 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "<tr><td align=\"right\"><code>" );
94 if ( EFI_ERROR ( Status
)) {
97 if ( DIM ( mpMemoryType
) > pMemoryDescriptor
->GcdMemoryType
) {
98 Status
= HttpSendAnsiString ( SocketFD
,
100 mpMemoryType
[ pMemoryDescriptor
->GcdMemoryType
]);
103 Status
= HttpSendValue ( SocketFD
,
105 pMemoryDescriptor
->GcdMemoryType
);
107 if ( EFI_ERROR ( Status
)) {
112 // Display the start address
114 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
115 if ( EFI_ERROR ( Status
)) {
118 Status
= HttpSendHexValue ( SocketFD
,
120 pMemoryDescriptor
->BaseAddress
);
121 if ( EFI_ERROR ( Status
)) {
126 // Display the end address
128 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
129 if ( EFI_ERROR ( Status
)) {
132 Status
= HttpSendHexValue ( SocketFD
,
134 pMemoryDescriptor
->BaseAddress
135 + pMemoryDescriptor
->Length
137 if ( EFI_ERROR ( Status
)) {
142 // Display the attributes
144 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
145 if ( EFI_ERROR ( Status
)) {
148 Status
= HttpSendHexValue ( SocketFD
,
150 pMemoryDescriptor
->Attributes
);
151 if ( EFI_ERROR ( Status
)) {
156 // Decode the attributes
158 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td>" );
159 if ( EFI_ERROR ( Status
)) {
162 bSomethingDisplayed
= FALSE
;
163 Attributes
= pMemoryDescriptor
->Attributes
;
165 if ( 0 != ( Attributes
& EFI_MEMORY_RUNTIME
)) {
166 bSomethingDisplayed
= TRUE
;
167 Status
= HttpSendAnsiString ( SocketFD
,
170 if ( EFI_ERROR ( Status
)) {
175 if ( 0 != ( Attributes
& EFI_MEMORY_XP
)) {
176 if ( bSomethingDisplayed
) {
177 Status
= HttpSendAnsiString ( SocketFD
,
180 if ( EFI_ERROR ( Status
)) {
184 bSomethingDisplayed
= TRUE
;
185 Status
= HttpSendAnsiString ( SocketFD
,
188 if ( EFI_ERROR ( Status
)) {
193 if ( 0 != ( Attributes
& EFI_MEMORY_RP
)) {
194 if ( bSomethingDisplayed
) {
195 Status
= HttpSendAnsiString ( SocketFD
,
198 if ( EFI_ERROR ( Status
)) {
202 bSomethingDisplayed
= TRUE
;
203 Status
= HttpSendAnsiString ( SocketFD
,
206 if ( EFI_ERROR ( Status
)) {
211 if ( 0 != ( Attributes
& EFI_MEMORY_WP
)) {
212 if ( bSomethingDisplayed
) {
213 Status
= HttpSendAnsiString ( SocketFD
,
216 if ( EFI_ERROR ( Status
)) {
220 bSomethingDisplayed
= TRUE
;
221 Status
= HttpSendAnsiString ( SocketFD
,
224 if ( EFI_ERROR ( Status
)) {
229 if ( 0 != ( Attributes
& EFI_MEMORY_UCE
)) {
230 if ( bSomethingDisplayed
) {
231 Status
= HttpSendAnsiString ( SocketFD
,
234 if ( EFI_ERROR ( Status
)) {
238 bSomethingDisplayed
= TRUE
;
239 Status
= HttpSendAnsiString ( SocketFD
,
242 if ( EFI_ERROR ( Status
)) {
248 if ( 0 != ( Attributes
& EFI_MEMORY_WB
)) {
249 if ( bSomethingDisplayed
) {
250 Status
= HttpSendAnsiString ( SocketFD
,
253 if ( EFI_ERROR ( Status
)) {
257 bSomethingDisplayed
= TRUE
;
258 Status
= HttpSendAnsiString ( SocketFD
,
261 if ( EFI_ERROR ( Status
)) {
266 if ( 0 != ( Attributes
& EFI_MEMORY_WT
)) {
267 if ( bSomethingDisplayed
) {
268 Status
= HttpSendAnsiString ( SocketFD
,
271 if ( EFI_ERROR ( Status
)) {
275 bSomethingDisplayed
= TRUE
;
276 Status
= HttpSendAnsiString ( SocketFD
,
279 if ( EFI_ERROR ( Status
)) {
284 if ( 0 != ( Attributes
& EFI_MEMORY_WC
)) {
285 if ( bSomethingDisplayed
) {
286 Status
= HttpSendAnsiString ( SocketFD
,
289 if ( EFI_ERROR ( Status
)) {
293 bSomethingDisplayed
= TRUE
;
294 Status
= HttpSendAnsiString ( SocketFD
,
297 if ( EFI_ERROR ( Status
)) {
302 if ( 0 != ( Attributes
& EFI_MEMORY_UC
)) {
303 if ( bSomethingDisplayed
) {
304 Status
= HttpSendAnsiString ( SocketFD
,
307 if ( EFI_ERROR ( Status
)) {
311 bSomethingDisplayed
= TRUE
;
312 Status
= HttpSendAnsiString ( SocketFD
,
315 if ( EFI_ERROR ( Status
)) {
323 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</td></tr>" );
324 if ( EFI_ERROR ( Status
)) {
329 // Set the next memory descriptor
331 pMemoryDescriptor
+= 1;
338 Status
= HttpSendAnsiString ( SocketFD
,
341 if ( EFI_ERROR ( Status
)) {
346 // Send the page trailer
348 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
353 // Release the memory descriptors
355 if ( NULL
!= pMemoryDescriptorStart
) {
356 FreePool ( pMemoryDescriptorStart
);
360 // Return the operation status
362 DBG_EXIT_STATUS ( Status
);