]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdMemory.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCmdMemory.c
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6
7 **/
8
9 #include "Edb.h"
10
11 /**
12
13 Display memory unit.
14
15 @param Address - Memory Address
16 @param Width - Memory Width
17
18 @return Length of the memory unit
19
20 **/
21 UINTN
22 EdbDisplayMemoryUnit (
23 IN UINTN Address,
24 IN EDB_DATA_WIDTH Width
25 )
26 {
27 UINT8 Data8;
28 UINT16 Data16;
29 UINT32 Data32;
30 UINT64 Data64;
31
32 //
33 // Print according to width
34 //
35 switch (Width) {
36 case EdbWidthUint8:
37 CopyMem (&Data8, (VOID *)Address, sizeof (UINT8));
38 EDBPrint (L"%02x ", Data8);
39 return sizeof (UINT8);
40 case EdbWidthUint16:
41 CopyMem (&Data16, (VOID *)Address, sizeof (UINT16));
42 EDBPrint (L"%04x ", Data16);
43 return sizeof (UINT16);
44 case EdbWidthUint32:
45 CopyMem (&Data32, (VOID *)Address, sizeof (UINT32));
46 EDBPrint (L"%08x ", Data32);
47 return sizeof (UINT32);
48 case EdbWidthUint64:
49 CopyMem (&Data64, (VOID *)Address, sizeof (UINT64));
50 EDBPrint (L"%016lx ", Data64);
51 return sizeof (UINT64);
52 default:
53 ASSERT (FALSE);
54 break;
55 }
56
57 //
58 // something wrong
59 //
60 return 0;
61 }
62
63 /**
64
65 Display memory.
66
67 @param Address - Memory Address
68 @param Count - Memory Count
69 @param Width - Memory Width
70
71 **/
72 VOID
73 EdbDisplayMemory (
74 IN UINTN Address,
75 IN UINTN Count,
76 IN EDB_DATA_WIDTH Width
77 )
78 {
79 UINTN LineNumber;
80 UINTN ByteNumber;
81 UINTN LineIndex;
82 UINTN ByteIndex;
83 UINTN NumberInLine;
84
85 if (Count == 0) {
86 return;
87 }
88
89 //
90 // Get line number and byte number
91 //
92 switch (Width) {
93 case EdbWidthUint8:
94 NumberInLine = 16;
95 break;
96 case EdbWidthUint16:
97 NumberInLine = 8;
98 break;
99 case EdbWidthUint32:
100 NumberInLine = 4;
101 break;
102 case EdbWidthUint64:
103 NumberInLine = 2;
104 break;
105 default:
106 return;
107 }
108
109 LineNumber = Count / NumberInLine;
110 ByteNumber = Count % NumberInLine;
111 if (ByteNumber == 0) {
112 LineNumber -= 1;
113 ByteNumber = NumberInLine;
114 }
115
116 //
117 // Print each line
118 //
119 for (LineIndex = 0; LineIndex < LineNumber; LineIndex++) {
120 //
121 // Break check
122 //
123 if (((LineIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&
124 (LineIndex != 0))
125 {
126 if (SetPageBreak ()) {
127 break;
128 }
129 }
130
131 EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)Address);
132 for (ByteIndex = 0; ByteIndex < NumberInLine; ByteIndex++) {
133 Address += EdbDisplayMemoryUnit (Address, Width);
134 }
135
136 EDBPrint (L"\n");
137 }
138
139 //
140 // Break check
141 //
142 if (((LineIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&
143 (LineIndex != 0))
144 {
145 if (SetPageBreak ()) {
146 return;
147 }
148 }
149
150 //
151 // Print last line
152 //
153 EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)Address);
154 for (ByteIndex = 0; ByteIndex < ByteNumber; ByteIndex++) {
155 Address += EdbDisplayMemoryUnit (Address, Width);
156 }
157
158 return;
159 }
160
161 /**
162
163 Entry memory.
164
165 @param Address - Memory Address
166 @param Value - Memory Value
167 @param Width - Memory Width
168
169 **/
170 VOID
171 EdbEnterMemory (
172 IN UINTN Address,
173 IN VOID *Value,
174 IN EDB_DATA_WIDTH Width
175 )
176 {
177 switch (Width) {
178 case EdbWidthUint8:
179 CopyMem ((VOID *)Address, Value, sizeof (UINT8));
180 break;
181 case EdbWidthUint16:
182 CopyMem ((VOID *)Address, Value, sizeof (UINT16));
183 break;
184 case EdbWidthUint32:
185 CopyMem ((VOID *)Address, Value, sizeof (UINT32));
186 break;
187 case EdbWidthUint64:
188 CopyMem ((VOID *)Address, Value, sizeof (UINT64));
189 break;
190 default:
191 break;
192 }
193
194 return;
195 }
196
197 /**
198
199 Get memory address and count.
200
201 @param CommandArg - The argument for this command
202 @param Address - Memory Address
203 @param Count - Memory Count
204
205 @retval EFI_SUCCESS - memory address and count are got
206 @retval EFI_INVALID_PARAMETER - something wrong
207
208 **/
209 EFI_STATUS
210 EdbGetMemoryAddressCount (
211 IN CHAR16 *CommandArg,
212 IN UINTN *Address,
213 IN UINTN *Count
214 )
215 {
216 CHAR16 *CommandStr;
217 UINTN MemAddress;
218 EFI_STATUS Status;
219
220 //
221 // Get Address
222 //
223 CommandStr = CommandArg;
224 if (CommandStr == NULL) {
225 EDBPrint (L"Memory: Address error!\n");
226 return EFI_INVALID_PARAMETER;
227 }
228
229 Status = Symboltoi (CommandStr, &MemAddress);
230 if (EFI_ERROR (Status)) {
231 if (Status == EFI_NOT_FOUND) {
232 MemAddress = Xtoi (CommandStr);
233 } else {
234 //
235 // Something wrong, let Symboltoi print error info.
236 //
237 EDBPrint (L"Command Argument error!\n");
238 return EFI_INVALID_PARAMETER;
239 }
240 }
241
242 *Address = MemAddress;
243
244 //
245 // Get Count
246 //
247 CommandStr = StrGetNextTokenLine (L" ");
248 if (CommandStr == NULL) {
249 *Count = 1;
250 } else {
251 *Count = Xtoi (CommandStr);
252 }
253
254 //
255 // Done
256 //
257 return EFI_SUCCESS;
258 }
259
260 /**
261
262 Get memory address and value.
263
264 @param CommandArg - The argument for this command
265 @param Address - Memory Address
266 @param Value - Memory Value
267
268 @retval EFI_SUCCESS - memory address and value are got
269 @retval EFI_INVALID_PARAMETER - something wrong
270
271 **/
272 EFI_STATUS
273 EdbGetMemoryAddressValue (
274 IN CHAR16 *CommandArg,
275 IN UINTN *Address,
276 IN UINT64 *Value
277 )
278 {
279 CHAR16 *CommandStr;
280 UINTN MemAddress;
281 EFI_STATUS Status;
282
283 //
284 // Get Address
285 //
286 CommandStr = CommandArg;
287 if (CommandStr == NULL) {
288 EDBPrint (L"Memory: Address error!\n");
289 return EFI_INVALID_PARAMETER;
290 }
291
292 Status = Symboltoi (CommandStr, &MemAddress);
293 if (EFI_ERROR (Status)) {
294 if (Status == EFI_NOT_FOUND) {
295 MemAddress = Xtoi (CommandStr);
296 } else {
297 //
298 // Something wrong, let Symboltoi print error info.
299 //
300 EDBPrint (L"Command Argument error!\n");
301 return EFI_INVALID_PARAMETER;
302 }
303 }
304
305 *Address = MemAddress;
306
307 //
308 // Get Value
309 //
310 CommandStr = StrGetNextTokenLine (L" ");
311 if (CommandStr == NULL) {
312 EDBPrint (L"Memory: Value error!\n");
313 return EFI_INVALID_PARAMETER;
314 }
315
316 *Value = LXtoi (CommandStr);
317
318 //
319 // Done
320 //
321 return EFI_SUCCESS;
322 }
323
324 /**
325
326 Display memory.
327
328 @param CommandArg - The argument for this command
329 @param Width - Memory Width
330
331 @retval EFI_DEBUG_RETURN - formal return value
332
333 **/
334 EFI_DEBUG_STATUS
335 DebuggerMemoryDisplay (
336 IN CHAR16 *CommandArg,
337 IN EDB_DATA_WIDTH Width
338 )
339 {
340 EFI_STATUS Status;
341 UINTN Address;
342 UINTN Count;
343
344 //
345 // Get memory address and count
346 //
347 Status = EdbGetMemoryAddressCount (CommandArg, &Address, &Count);
348 if (EFI_ERROR (Status)) {
349 return EFI_DEBUG_CONTINUE;
350 }
351
352 //
353 // Display memory
354 //
355 EdbDisplayMemory (Address, Count, Width);
356
357 //
358 // Done
359 //
360 return EFI_DEBUG_CONTINUE;
361 }
362
363 /**
364
365 Enter memory.
366
367 @param CommandArg - The argument for this command
368 @param Width - Memory Width
369
370 @retval EFI_DEBUG_RETURN - formal return value
371
372 **/
373 EFI_DEBUG_STATUS
374 DebuggerMemoryEnter (
375 IN CHAR16 *CommandArg,
376 IN EDB_DATA_WIDTH Width
377 )
378 {
379 EFI_STATUS Status;
380 UINTN Address;
381 UINT64 Value;
382
383 //
384 // Get memory address and value
385 //
386 Status = EdbGetMemoryAddressValue (CommandArg, &Address, &Value);
387 if (EFI_ERROR (Status)) {
388 return EFI_DEBUG_CONTINUE;
389 }
390
391 //
392 // Enter memory
393 //
394 EdbEnterMemory (Address, &Value, Width);
395
396 //
397 // Done
398 //
399 return EFI_DEBUG_CONTINUE;
400 }
401
402 /**
403
404 DebuggerCommand - DB.
405
406 @param CommandArg - The argument for this command
407 @param DebuggerPrivate - EBC Debugger private data structure
408 @param ExceptionType - Interrupt type.
409 @param SystemContext - EBC system context.
410
411 @retval EFI_DEBUG_RETURN - formal return value
412
413 **/
414 EFI_DEBUG_STATUS
415 DebuggerMemoryDB (
416 IN CHAR16 *CommandArg,
417 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
418 IN EFI_EXCEPTION_TYPE ExceptionType,
419 IN OUT EFI_SYSTEM_CONTEXT SystemContext
420 )
421 {
422 return DebuggerMemoryDisplay (CommandArg, EdbWidthUint8);
423 }
424
425 /**
426
427 DebuggerCommand - DW.
428
429 @param CommandArg - The argument for this command
430 @param DebuggerPrivate - EBC Debugger private data structure
431 @param ExceptionType - Interrupt type.
432 @param SystemContext - EBC system context.
433
434 @retval EFI_DEBUG_RETURN - formal return value
435
436 **/
437 EFI_DEBUG_STATUS
438 DebuggerMemoryDW (
439 IN CHAR16 *CommandArg,
440 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
441 IN EFI_EXCEPTION_TYPE ExceptionType,
442 IN OUT EFI_SYSTEM_CONTEXT SystemContext
443 )
444 {
445 return DebuggerMemoryDisplay (CommandArg, EdbWidthUint16);
446 }
447
448 /**
449
450 DebuggerCommand - DD.
451
452 @param CommandArg - The argument for this command
453 @param DebuggerPrivate - EBC Debugger private data structure
454 @param ExceptionType - Interrupt type.
455 @param SystemContext - EBC system context.
456
457 @retval EFI_DEBUG_RETURN - formal return value
458
459 **/
460 EFI_DEBUG_STATUS
461 DebuggerMemoryDD (
462 IN CHAR16 *CommandArg,
463 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
464 IN EFI_EXCEPTION_TYPE ExceptionType,
465 IN OUT EFI_SYSTEM_CONTEXT SystemContext
466 )
467 {
468 return DebuggerMemoryDisplay (CommandArg, EdbWidthUint32);
469 }
470
471 /**
472
473 DebuggerCommand - DQ.
474
475 @param CommandArg - The argument for this command
476 @param DebuggerPrivate - EBC Debugger private data structure
477 @param ExceptionType - Exception type.
478 @param SystemContext - EBC system context.
479
480 @retval EFI_DEBUG_RETURN - formal return value
481
482 **/
483 EFI_DEBUG_STATUS
484 DebuggerMemoryDQ (
485 IN CHAR16 *CommandArg,
486 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
487 IN EFI_EXCEPTION_TYPE ExceptionType,
488 IN OUT EFI_SYSTEM_CONTEXT SystemContext
489 )
490 {
491 return DebuggerMemoryDisplay (CommandArg, EdbWidthUint64);
492 }
493
494 /**
495
496 DebuggerCommand - EB.
497
498 @param CommandArg - The argument for this command
499 @param DebuggerPrivate - EBC Debugger private data structure
500 @param ExceptionType - Exception type.
501 @param SystemContext - EBC system context.
502
503 @retval EFI_DEBUG_RETURN - formal return value
504
505 **/
506 EFI_DEBUG_STATUS
507 DebuggerMemoryEB (
508 IN CHAR16 *CommandArg,
509 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
510 IN EFI_EXCEPTION_TYPE ExceptionType,
511 IN OUT EFI_SYSTEM_CONTEXT SystemContext
512 )
513 {
514 return DebuggerMemoryEnter (CommandArg, EdbWidthUint8);
515 }
516
517 /**
518
519 DebuggerCommand - EW.
520
521 @param CommandArg - The argument for this command
522 @param DebuggerPrivate - EBC Debugger private data structure
523 @param ExceptionType - Interrupt type.
524 @param SystemContext - EBC system context.
525
526 @retval EFI_DEBUG_RETURN - formal return value
527
528 **/
529 EFI_DEBUG_STATUS
530 DebuggerMemoryEW (
531 IN CHAR16 *CommandArg,
532 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
533 IN EFI_EXCEPTION_TYPE ExceptionType,
534 IN OUT EFI_SYSTEM_CONTEXT SystemContext
535 )
536 {
537 return DebuggerMemoryEnter (CommandArg, EdbWidthUint16);
538 }
539
540 /**
541
542 DebuggerCommand - ED.
543
544 @param CommandArg - The argument for this command
545 @param DebuggerPrivate - EBC Debugger private data structure
546 @param ExceptionType - Exception type.
547 @param SystemContext - EBC system context.
548
549 @retval EFI_DEBUG_RETURN - formal return value
550
551 **/
552 EFI_DEBUG_STATUS
553 DebuggerMemoryED (
554 IN CHAR16 *CommandArg,
555 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
556 IN EFI_EXCEPTION_TYPE ExceptionType,
557 IN OUT EFI_SYSTEM_CONTEXT SystemContext
558 )
559 {
560 return DebuggerMemoryEnter (CommandArg, EdbWidthUint32);
561 }
562
563 /**
564
565 DebuggerCommand - EQ.
566
567 @param CommandArg - The argument for this command
568 @param DebuggerPrivate - EBC Debugger private data structure
569 @param ExceptionType - Exception type.
570 @param SystemContext - EBC system context.
571
572 @retval EFI_DEBUG_RETURN - formal return value
573
574 **/
575 EFI_DEBUG_STATUS
576 DebuggerMemoryEQ (
577 IN CHAR16 *CommandArg,
578 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
579 IN EFI_EXCEPTION_TYPE ExceptionType,
580 IN OUT EFI_SYSTEM_CONTEXT SystemContext
581 )
582 {
583 return DebuggerMemoryEnter (CommandArg, EdbWidthUint64);
584 }