5 Copyright (c) 2012, Intel Corporation. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <WebServer.h>
12 #include <Library/DxeServicesTableLib.h>
15 CONST
char * mpMemoryType
[ ] = {
24 Page to display the memory map
26 @param [in] SocketFD The socket's file descriptor to add to the list.
27 @param [in] pPort The WSDT_PORT structure address
28 @param [out] pbDone Address to receive the request completion status
30 @retval EFI_SUCCESS The request was successfully processed
41 BOOLEAN bSomethingDisplayed
;
43 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryEnd
;
44 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryDescriptor
;
45 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
* pMemoryDescriptorStart
;
51 // Send the memory map page
53 pMemoryDescriptorStart
= NULL
;
56 // Send the page header
58 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"Memory Map" );
59 if ( EFI_ERROR ( Status
)) {
66 Status
= HttpSendAnsiString ( SocketFD
,
68 "<h1>Memory Map</h1>\r\n"
70 " <tr><th align=\"right\">Type</th><th align=\"right\">Start</th><th align=\"right\">End</th><th align=\"right\">Attributes</th></tr>\r\n" );
71 if ( EFI_ERROR ( Status
)) {
78 Status
= gDS
->GetMemorySpaceMap ( &Count
,
80 if ( !EFI_ERROR ( Status
)) {
81 pMemoryDescriptorStart
= pMemoryDescriptor
;
82 pMemoryEnd
= &pMemoryDescriptor
[ Count
];
83 while ( pMemoryEnd
> pMemoryDescriptor
) {
87 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "<tr><td align=\"right\"><code>" );
88 if ( EFI_ERROR ( Status
)) {
91 if ( DIM ( mpMemoryType
) > pMemoryDescriptor
->GcdMemoryType
) {
92 Status
= HttpSendAnsiString ( SocketFD
,
94 mpMemoryType
[ pMemoryDescriptor
->GcdMemoryType
]);
97 Status
= HttpSendValue ( SocketFD
,
99 pMemoryDescriptor
->GcdMemoryType
);
101 if ( EFI_ERROR ( Status
)) {
106 // Display the start address
108 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
109 if ( EFI_ERROR ( Status
)) {
112 Status
= HttpSendHexValue ( SocketFD
,
114 pMemoryDescriptor
->BaseAddress
);
115 if ( EFI_ERROR ( Status
)) {
120 // Display the end address
122 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
123 if ( EFI_ERROR ( Status
)) {
126 Status
= HttpSendHexValue ( SocketFD
,
128 pMemoryDescriptor
->BaseAddress
129 + pMemoryDescriptor
->Length
131 if ( EFI_ERROR ( Status
)) {
136 // Display the attributes
138 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td align=\"right\"><code>0x" );
139 if ( EFI_ERROR ( Status
)) {
142 Status
= HttpSendHexValue ( SocketFD
,
144 pMemoryDescriptor
->Attributes
);
145 if ( EFI_ERROR ( Status
)) {
150 // Decode the attributes
152 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</code></td><td>" );
153 if ( EFI_ERROR ( Status
)) {
156 bSomethingDisplayed
= FALSE
;
157 Attributes
= pMemoryDescriptor
->Attributes
;
159 if ( 0 != ( Attributes
& EFI_MEMORY_RUNTIME
)) {
160 bSomethingDisplayed
= TRUE
;
161 Status
= HttpSendAnsiString ( SocketFD
,
164 if ( EFI_ERROR ( Status
)) {
169 if ( 0 != ( Attributes
& EFI_MEMORY_XP
)) {
170 if ( bSomethingDisplayed
) {
171 Status
= HttpSendAnsiString ( SocketFD
,
174 if ( EFI_ERROR ( Status
)) {
178 bSomethingDisplayed
= TRUE
;
179 Status
= HttpSendAnsiString ( SocketFD
,
182 if ( EFI_ERROR ( Status
)) {
187 if ( 0 != ( Attributes
& EFI_MEMORY_RP
)) {
188 if ( bSomethingDisplayed
) {
189 Status
= HttpSendAnsiString ( SocketFD
,
192 if ( EFI_ERROR ( Status
)) {
196 bSomethingDisplayed
= TRUE
;
197 Status
= HttpSendAnsiString ( SocketFD
,
200 if ( EFI_ERROR ( Status
)) {
205 if ( 0 != ( Attributes
& EFI_MEMORY_WP
)) {
206 if ( bSomethingDisplayed
) {
207 Status
= HttpSendAnsiString ( SocketFD
,
210 if ( EFI_ERROR ( Status
)) {
214 bSomethingDisplayed
= TRUE
;
215 Status
= HttpSendAnsiString ( SocketFD
,
218 if ( EFI_ERROR ( Status
)) {
223 if ( 0 != ( Attributes
& EFI_MEMORY_UCE
)) {
224 if ( bSomethingDisplayed
) {
225 Status
= HttpSendAnsiString ( SocketFD
,
228 if ( EFI_ERROR ( Status
)) {
232 bSomethingDisplayed
= TRUE
;
233 Status
= HttpSendAnsiString ( SocketFD
,
236 if ( EFI_ERROR ( Status
)) {
242 if ( 0 != ( Attributes
& EFI_MEMORY_WB
)) {
243 if ( bSomethingDisplayed
) {
244 Status
= HttpSendAnsiString ( SocketFD
,
247 if ( EFI_ERROR ( Status
)) {
251 bSomethingDisplayed
= TRUE
;
252 Status
= HttpSendAnsiString ( SocketFD
,
255 if ( EFI_ERROR ( Status
)) {
260 if ( 0 != ( Attributes
& EFI_MEMORY_WT
)) {
261 if ( bSomethingDisplayed
) {
262 Status
= HttpSendAnsiString ( SocketFD
,
265 if ( EFI_ERROR ( Status
)) {
269 bSomethingDisplayed
= TRUE
;
270 Status
= HttpSendAnsiString ( SocketFD
,
273 if ( EFI_ERROR ( Status
)) {
278 if ( 0 != ( Attributes
& EFI_MEMORY_WC
)) {
279 if ( bSomethingDisplayed
) {
280 Status
= HttpSendAnsiString ( SocketFD
,
283 if ( EFI_ERROR ( Status
)) {
287 bSomethingDisplayed
= TRUE
;
288 Status
= HttpSendAnsiString ( SocketFD
,
291 if ( EFI_ERROR ( Status
)) {
296 if ( 0 != ( Attributes
& EFI_MEMORY_UC
)) {
297 if ( bSomethingDisplayed
) {
298 Status
= HttpSendAnsiString ( SocketFD
,
301 if ( EFI_ERROR ( Status
)) {
305 bSomethingDisplayed
= TRUE
;
306 Status
= HttpSendAnsiString ( SocketFD
,
309 if ( EFI_ERROR ( Status
)) {
317 Status
= HttpSendAnsiString ( SocketFD
, pPort
, "</td></tr>" );
318 if ( EFI_ERROR ( Status
)) {
323 // Set the next memory descriptor
325 pMemoryDescriptor
+= 1;
332 Status
= HttpSendAnsiString ( SocketFD
,
335 if ( EFI_ERROR ( Status
)) {
340 // Send the page trailer
342 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
347 // Release the memory descriptors
349 if ( NULL
!= pMemoryDescriptorStart
) {
350 FreePool ( pMemoryDescriptorStart
);
354 // Return the operation status
356 DBG_EXIT_STATUS ( Status
);