1 /** @file 2 3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR> 4 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 13 **/ 14 15 #ifndef _EFI_EDB_DISASM_SUPPORT_H_ 16 #define _EFI_EDB_DISASM_SUPPORT_H_ 17 18 #include <Uefi.h> 19 20 #define EDB_BYTECODE_NUMBER_IN_LINE 5 21 22 #ifdef EFI32 23 #define EDB_PRINT_ADDRESS_FORMAT L"%08x: " 24 #else 25 // To use 012l instead of 016l because space is not enough 26 #define EDB_PRINT_ADDRESS_FORMAT L"%012lx: " 27 #endif 28 29 #define OPCODE_MAX 0x40 30 31 #define EDB_INSTRUCTION_NAME_MAX_LENGTH 10 32 #define EDB_INSTRUCTION_NAME_MAX_SIZE (EDB_INSTRUCTION_NAME_MAX_LENGTH * sizeof(CHAR16)) 33 #define EDB_INSTRUCTION_CONTENT_MAX_LENGTH 30 34 #define EDB_INSTRUCTION_CONTENT_MAX_SIZE (EDB_INSTRUCTION_CONTENT_MAX_LENGTH * sizeof(CHAR16)) 35 36 /** 37 38 Set offset for Instruction name and content. 39 40 @param InstructionNameOffset - Instruction name offset 41 @param InstructionContentOffset - Instruction content offset 42 43 **/ 44 VOID 45 EdbSetOffset ( 46 IN UINTN InstructionNameOffset, 47 IN UINTN InstructionContentOffset 48 ); 49 50 /** 51 52 Pre instruction string construction. 53 54 @return Instruction string 55 56 **/ 57 CHAR16 * 58 EdbPreInstructionString ( 59 VOID 60 ); 61 62 /** 63 64 Post instruction string construction. 65 66 @return Instruction string 67 68 **/ 69 CHAR16 * 70 EdbPostInstructionString ( 71 VOID 72 ); 73 74 /** 75 76 Print the instruction name. 77 78 @param Name - instruction name 79 80 @return Instruction name offset 81 82 **/ 83 UINTN 84 EdbPrintInstructionName ( 85 IN CHAR16 *Name 86 ); 87 88 /** 89 90 Get Sign, NaturalUnits, and ConstantUnits of the WORD data. 91 92 @param Data16 - WORD data 93 @param NaturalUnits - Natural Units of the WORD 94 @param ConstantUnits - Constant Units of the WORD 95 96 @return Sign value of WORD 97 98 **/ 99 BOOLEAN 100 EdbGetNaturalIndex16 ( 101 IN UINT16 Data16, 102 OUT UINTN *NaturalUnits, 103 OUT UINTN *ConstantUnits 104 ); 105 106 /** 107 108 Get Sign, NaturalUnits, and ConstantUnits of the DWORD data. 109 110 @param Data32 - DWORD data 111 @param NaturalUnits - Natural Units of the DWORD 112 @param ConstantUnits - Constant Units of the DWORD 113 114 @return Sign value of DWORD 115 116 **/ 117 BOOLEAN 118 EdbGetNaturalIndex32 ( 119 IN UINT32 Data32, 120 OUT UINTN *NaturalUnits, 121 OUT UINTN *ConstantUnits 122 ); 123 124 /** 125 126 Get Sign, NaturalUnits, and ConstantUnits of the QWORD data. 127 128 @param Data64 - QWORD data 129 @param NaturalUnits - Natural Units of the QWORD 130 @param ConstantUnits - Constant Units of the QWORD 131 132 @return Sign value of QWORD 133 134 **/ 135 BOOLEAN 136 EdbGetNaturalIndex64 ( 137 IN UINT64 Data64, 138 OUT UINT64 *NaturalUnits, 139 OUT UINT64 *ConstantUnits 140 ); 141 142 /** 143 144 Print the hexical WORD raw index data to instruction content. 145 146 @param Data16 - WORD data 147 148 @return Instruction content offset 149 150 **/ 151 UINTN 152 EdbPrintRawIndexData16 ( 153 IN UINT16 Data16 154 ); 155 156 /** 157 158 Print the hexical DWORD raw index data to instruction content. 159 160 @param Data32 - DWORD data 161 162 @return Instruction content offset 163 164 **/ 165 UINTN 166 EdbPrintRawIndexData32 ( 167 IN UINT32 Data32 168 ); 169 170 /** 171 172 Print the hexical QWORD raw index data to instruction content. 173 174 @param Data64 - QWORD data 175 176 @return Instruction content offset 177 178 **/ 179 UINTN 180 EdbPrintRawIndexData64 ( 181 IN UINT64 Data64 182 ); 183 184 /** 185 186 Print register 1 in operands. 187 188 @param Operands - instruction operands 189 190 @return Instruction content offset 191 192 **/ 193 UINTN 194 EdbPrintRegister1 ( 195 IN UINT8 Operands 196 ); 197 198 /** 199 200 Print register 2 in operands. 201 202 @param Operands - instruction operands 203 204 @return Instruction content offset 205 206 **/ 207 UINTN 208 EdbPrintRegister2 ( 209 IN UINT8 Operands 210 ); 211 212 /** 213 214 Print dedicated register 1 in operands. 215 216 @param Operands - instruction operands 217 218 @return Instruction content offset 219 220 **/ 221 UINTN 222 EdbPrintDedicatedRegister1 ( 223 IN UINT8 Operands 224 ); 225 226 /** 227 228 Print dedicated register 2 in operands. 229 230 @param Operands - instruction operands 231 232 @return Instruction content offset 233 234 **/ 235 UINTN 236 EdbPrintDedicatedRegister2 ( 237 IN UINT8 Operands 238 ); 239 240 /** 241 242 Print the hexical UINTN index data to instruction content. 243 244 @param Sign - Signed bit of UINTN data 245 @param NaturalUnits - natural units of UINTN data 246 @param ConstantUnits - natural units of UINTN data 247 248 @return Instruction content offset 249 250 **/ 251 UINTN 252 EdbPrintIndexData ( 253 IN BOOLEAN Sign, 254 IN UINTN NaturalUnits, 255 IN UINTN ConstantUnits 256 ); 257 258 /** 259 260 Print the hexical QWORD index data to instruction content. 261 262 @param Sign - Signed bit of QWORD data 263 @param NaturalUnits - natural units of QWORD data 264 @param ConstantUnits - natural units of QWORD data 265 266 @return Instruction content offset 267 268 **/ 269 UINTN 270 EdbPrintIndexData64 ( 271 IN BOOLEAN Sign, 272 IN UINT64 NaturalUnits, 273 IN UINT64 ConstantUnits 274 ); 275 276 /** 277 278 Print the hexical BYTE immediate data to instruction content. 279 280 @param Data - BYTE data 281 282 @return Instruction content offset 283 284 **/ 285 UINTN 286 EdbPrintImmData8 ( 287 IN UINT8 Data 288 ); 289 290 /** 291 292 Print the hexical WORD immediate data to instruction content. 293 294 @param Data - WORD data 295 296 @return Instruction content offset 297 298 **/ 299 UINTN 300 EdbPrintImmData16 ( 301 IN UINT16 Data 302 ); 303 304 /** 305 306 Print the hexical DWORD immediate data to instruction content. 307 308 @param Data - DWORD data 309 310 @return Instruction content offset 311 312 **/ 313 UINTN 314 EdbPrintImmData32 ( 315 IN UINT32 Data 316 ); 317 318 /** 319 320 Print the hexical QWORD immediate data to instruction content. 321 322 @param Data - QWORD data 323 324 @return Instruction content offset 325 326 **/ 327 UINTN 328 EdbPrintImmData64 ( 329 IN UINT64 Data 330 ); 331 332 /** 333 334 Print the decimal UINTN immediate data to instruction content. 335 336 @param Data - UINTN data 337 338 @return Instruction content offset 339 340 **/ 341 UINTN 342 EdbPrintImmDatan ( 343 IN UINTN Data 344 ); 345 346 /** 347 348 Print the decimal QWORD immediate data to instruction content. 349 350 @param Data64 - QWORD data 351 352 @return Instruction content offset 353 354 **/ 355 UINTN 356 EdbPrintImmData64n ( 357 IN UINT64 Data64 358 ); 359 360 /** 361 362 Print the hexical BYTE to instruction content. 363 364 @param Data8 - BYTE data 365 366 @return Instruction content offset 367 368 **/ 369 UINTN 370 EdbPrintData8 ( 371 IN UINT8 Data8 372 ); 373 374 /** 375 376 Print the hexical WORD to instruction content. 377 378 @param Data16 - WORD data 379 380 @return Instruction content offset 381 382 **/ 383 UINTN 384 EdbPrintData16 ( 385 IN UINT16 Data16 386 ); 387 388 /** 389 390 Print the hexical DWORD to instruction content. 391 392 @param Data32 - DWORD data 393 394 @return Instruction content offset 395 396 **/ 397 UINTN 398 EdbPrintData32 ( 399 IN UINT32 Data32 400 ); 401 402 /** 403 404 Print the hexical QWORD to instruction content. 405 406 @param Data64 - QWORD data 407 408 @return Instruction content offset 409 410 **/ 411 UINTN 412 EdbPrintData64 ( 413 IN UINT64 Data64 414 ); 415 416 /** 417 418 Print the decimal unsigned UINTN to instruction content. 419 420 @param Data - unsigned UINTN data 421 422 @return Instruction content offset 423 424 **/ 425 UINTN 426 EdbPrintDatan ( 427 IN UINTN Data 428 ); 429 430 /** 431 432 Print the decimal unsigned QWORD to instruction content. 433 434 @param Data64 - unsigned QWORD data 435 436 @return Instruction content offset 437 438 **/ 439 UINTN 440 EdbPrintData64n ( 441 IN UINT64 Data64 442 ); 443 444 /** 445 446 Print the decimal signed BYTE to instruction content. 447 448 @param Data8 - signed BYTE data 449 450 @return Instruction content offset 451 452 **/ 453 UINTN 454 EdbPrintData8s ( 455 IN UINT8 Data8 456 ); 457 458 /** 459 460 Print the decimal signed WORD to instruction content. 461 462 @param Data16 - signed WORD data 463 464 @return Instruction content offset 465 466 **/ 467 UINTN 468 EdbPrintData16s ( 469 IN UINT16 Data16 470 ); 471 472 /** 473 474 Print the decimal signed DWORD to instruction content. 475 476 @param Data32 - signed DWORD data 477 478 @return Instruction content offset 479 480 **/ 481 UINTN 482 EdbPrintData32s ( 483 IN UINT32 Data32 484 ); 485 486 /** 487 488 Print the decimal signed QWORD to instruction content. 489 490 @param Data64 - signed QWORD data 491 492 @return Instruction content offset 493 494 **/ 495 UINTN 496 EdbPrintData64s ( 497 IN UINT64 Data64 498 ); 499 500 /** 501 502 Print the comma to instruction content. 503 504 @return Instruction content offset 505 506 **/ 507 UINTN 508 EdbPrintComma ( 509 VOID 510 ); 511 512 /** 513 514 Find the symbol string according to address, then print it. 515 516 @param Address - instruction address 517 518 @retval 1 - symbol string is found and printed 519 @retval 0 - symbol string not found 520 521 **/ 522 UINTN 523 EdbFindAndPrintSymbol ( 524 IN UINTN Address 525 ); 526 527 /** 528 529 Print the EBC byte code. 530 531 @param InstructionAddress - instruction address 532 @param InstructionNumber - instruction number 533 534 **/ 535 VOID 536 EdbPrintRaw ( 537 IN EFI_PHYSICAL_ADDRESS InstructionAddress, 538 IN UINTN InstructionNumber 539 ); 540 541 /** 542 543 Print the EBC asm code. 544 545 @param DebuggerPrivate - EBC Debugger private data structure 546 @param SystemContext - EBC system context. 547 548 @retval EFI_SUCCESS - show disasm successfully 549 550 **/ 551 EFI_STATUS 552 EdbShowDisasm ( 553 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, 554 IN EFI_SYSTEM_CONTEXT SystemContext 555 ); 556 557 /** 558 559 Get register value accroding to the system context, and register index. 560 561 @param SystemContext - EBC system context. 562 @param Index - EBC register index 563 564 @return register value 565 566 **/ 567 UINT64 568 GetRegisterValue ( 569 IN EFI_SYSTEM_CONTEXT SystemContext, 570 IN UINT8 Index 571 ); 572 573 #endif 574