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