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