1 /* 2 * Copyright (c) 2021 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <xtensa_asm2_context.h> 9 #include <zephyr/debug/gdbstub.h> 10 #include <zephyr/offsets.h> 11 12 /* 13 * Address Mappings From ESP32 Technical Reference Manual Version 4.5 14 * https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf 15 */ 16 const struct gdb_mem_region gdb_mem_region_array[] = { 17 { 18 /* External Memory (Data Bus) */ 19 .start = 0x3F400000, 20 .end = 0x3FBFFFFF, 21 .attributes = GDB_MEM_REGION_RW, 22 .alignment = 4, 23 }, 24 { 25 /* Peripheral (Data Bus) */ 26 .start = 0x3FF00000, 27 .end = 0x3FF7FFFF, 28 .attributes = GDB_MEM_REGION_RW, 29 .alignment = 4, 30 }, 31 { 32 /* RTC FAST Memory (Data Bus) */ 33 .start = 0x3FF80000, 34 .end = 0x3FF81FFF, 35 .attributes = GDB_MEM_REGION_RW, 36 .alignment = 4, 37 }, 38 { 39 /* Internal ROM 1 (Data Bus) */ 40 .start = 0x3FF90000, 41 .end = 0x3FF9FFFF, 42 .attributes = GDB_MEM_REGION_RO, 43 .alignment = 4, 44 }, 45 { 46 /* Internal SRAM 1 and 2 (Data Bus) */ 47 .start = 0x3FFAE000, 48 .end = 0x3FFFFFFF, 49 .attributes = GDB_MEM_REGION_RW, 50 .alignment = 4, 51 }, 52 { 53 /* Internal ROM 0 (Instruction Bus) */ 54 .start = 0x40000000, 55 .end = 0x4005FFFF, 56 .attributes = GDB_MEM_REGION_RO, 57 .alignment = 4, 58 }, 59 { 60 /* Internal SRAM 0 and 1 (Instruction Bus) */ 61 .start = 0x40070000, 62 .end = 0x400BFFFF, 63 .attributes = GDB_MEM_REGION_RW, 64 .alignment = 4, 65 }, 66 { 67 /* RTC FAST Memory (Instruction Bus) */ 68 .start = 0x400C0000, 69 .end = 0x400C1FFF, 70 .attributes = GDB_MEM_REGION_RW, 71 .alignment = 4, 72 }, 73 { 74 /* External Memory (Instruction Bus) */ 75 .start = 0x400C2000, 76 .end = 0x400CFFFF, 77 .attributes = GDB_MEM_REGION_RW, 78 .alignment = 4, 79 }, 80 { 81 /* 82 * Flash memory obtained via GDB memory map 83 * with ESP32's OpenOCD 84 */ 85 .start = 0x400D0000, 86 .end = 0x400D5FFF, 87 .attributes = GDB_MEM_REGION_RO, 88 .alignment = 4, 89 }, 90 { 91 /* External Memory (Instruction Bus) */ 92 .start = 0x400D6000, 93 .end = 0x40BFFFFF, 94 .attributes = GDB_MEM_REGION_RW, 95 .alignment = 4, 96 }, 97 { 98 /* RTC SLOW Memory (Data/Instruction Bus) */ 99 .start = 0x50000000, 100 .end = 0x50001FFF, 101 .attributes = GDB_MEM_REGION_RW, 102 .alignment = 4, 103 }, 104 }; 105 106 const size_t gdb_mem_num_regions = ARRAY_SIZE(gdb_mem_region_array); 107 108 static struct xtensa_register gdb_reg_list[] = { 109 { 110 /* PC */ 111 .idx = 0, 112 .regno = 0x0020, 113 .byte_size = 4, 114 .gpkt_offset = 0, 115 .stack_offset = ___xtensa_irq_bsa_t_pc_OFFSET, 116 }, 117 { 118 /* AR0 */ 119 .idx = 1, 120 .regno = 0x100, 121 .byte_size = 4, 122 .gpkt_offset = 4, 123 }, 124 { 125 /* AR1 */ 126 .idx = 2, 127 .regno = 0x101, 128 .byte_size = 4, 129 .gpkt_offset = 8, 130 }, 131 { 132 /* AR2 */ 133 .idx = 3, 134 .regno = 0x102, 135 .byte_size = 4, 136 .gpkt_offset = 12, 137 }, 138 { 139 /* AR3 */ 140 .idx = 4, 141 .regno = 0x103, 142 .byte_size = 4, 143 .gpkt_offset = 16, 144 }, 145 { 146 /* AR4 */ 147 .idx = 5, 148 .regno = 0x104, 149 .byte_size = 4, 150 .gpkt_offset = 20, 151 }, 152 { 153 /* AR5 */ 154 .idx = 6, 155 .regno = 0x105, 156 .byte_size = 4, 157 .gpkt_offset = 24, 158 }, 159 { 160 /* AR6 */ 161 .idx = 7, 162 .regno = 0x106, 163 .byte_size = 4, 164 .gpkt_offset = 28, 165 }, 166 { 167 /* AR7 */ 168 .idx = 8, 169 .regno = 0x107, 170 .byte_size = 4, 171 .gpkt_offset = 32, 172 }, 173 { 174 /* AR8 */ 175 .idx = 9, 176 .regno = 0x108, 177 .byte_size = 4, 178 .gpkt_offset = 36, 179 }, 180 { 181 /* AR9 */ 182 .idx = 10, 183 .regno = 0x109, 184 .byte_size = 4, 185 .gpkt_offset = 40, 186 }, 187 { 188 /* AR10 */ 189 .idx = 11, 190 .regno = 0x10a, 191 .byte_size = 4, 192 .gpkt_offset = 44, 193 }, 194 { 195 /* AR11 */ 196 .idx = 12, 197 .regno = 0x10b, 198 .byte_size = 4, 199 .gpkt_offset = 48, 200 }, 201 { 202 /* AR12 */ 203 .idx = 13, 204 .regno = 0x10c, 205 .byte_size = 4, 206 .gpkt_offset = 52, 207 }, 208 { 209 /* AR13 */ 210 .idx = 14, 211 .regno = 0x10d, 212 .byte_size = 4, 213 .gpkt_offset = 56, 214 }, 215 { 216 /* AR14 */ 217 .idx = 15, 218 .regno = 0x10e, 219 .byte_size = 4, 220 .gpkt_offset = 60, 221 }, 222 { 223 /* AR15 */ 224 .idx = 16, 225 .regno = 0x10f, 226 .byte_size = 4, 227 .gpkt_offset = 64, 228 }, 229 { 230 /* AR16 */ 231 .idx = 17, 232 .regno = 0x110, 233 .byte_size = 4, 234 .gpkt_offset = 68, 235 }, 236 { 237 /* AR17 */ 238 .idx = 18, 239 .regno = 0x111, 240 .byte_size = 4, 241 .gpkt_offset = 72, 242 }, 243 { 244 /* AR18 */ 245 .idx = 19, 246 .regno = 0x112, 247 .byte_size = 4, 248 .gpkt_offset = 76, 249 }, 250 { 251 /* AR19 */ 252 .idx = 20, 253 .regno = 0x113, 254 .byte_size = 4, 255 .gpkt_offset = 80, 256 }, 257 { 258 /* AR20 */ 259 .idx = 21, 260 .regno = 0x114, 261 .byte_size = 4, 262 .gpkt_offset = 84, 263 }, 264 { 265 /* AR21 */ 266 .idx = 22, 267 .regno = 0x115, 268 .byte_size = 4, 269 .gpkt_offset = 88, 270 }, 271 { 272 /* AR22 */ 273 .idx = 23, 274 .regno = 0x116, 275 .byte_size = 4, 276 .gpkt_offset = 92, 277 }, 278 { 279 /* AR23 */ 280 .idx = 24, 281 .regno = 0x117, 282 .byte_size = 4, 283 .gpkt_offset = 96, 284 }, 285 { 286 /* AR24 */ 287 .idx = 25, 288 .regno = 0x118, 289 .byte_size = 4, 290 .gpkt_offset = 100, 291 }, 292 { 293 /* AR25 */ 294 .idx = 26, 295 .regno = 0x119, 296 .byte_size = 4, 297 .gpkt_offset = 104, 298 }, 299 { 300 /* AR26 */ 301 .idx = 27, 302 .regno = 0x11a, 303 .byte_size = 4, 304 .gpkt_offset = 108, 305 }, 306 { 307 /* AR27 */ 308 .idx = 28, 309 .regno = 0x11b, 310 .byte_size = 4, 311 .gpkt_offset = 112, 312 }, 313 { 314 /* AR28 */ 315 .idx = 29, 316 .regno = 0x11c, 317 .byte_size = 4, 318 .gpkt_offset = 116, 319 }, 320 { 321 /* AR29 */ 322 .idx = 30, 323 .regno = 0x11d, 324 .byte_size = 4, 325 .gpkt_offset = 120, 326 }, 327 { 328 /* AR30 */ 329 .idx = 31, 330 .regno = 0x11e, 331 .byte_size = 4, 332 .gpkt_offset = 124, 333 }, 334 { 335 /* AR31 */ 336 .idx = 32, 337 .regno = 0x11f, 338 .byte_size = 4, 339 .gpkt_offset = 128, 340 }, 341 { 342 /* AR32 */ 343 .idx = 33, 344 .regno = 0x120, 345 .byte_size = 4, 346 .gpkt_offset = 132, 347 }, 348 { 349 /* AR33 */ 350 .idx = 34, 351 .regno = 0x121, 352 .byte_size = 4, 353 .gpkt_offset = 136, 354 }, 355 { 356 /* AR34 */ 357 .idx = 35, 358 .regno = 0x122, 359 .byte_size = 4, 360 .gpkt_offset = 140, 361 }, 362 { 363 /* AR35 */ 364 .idx = 36, 365 .regno = 0x123, 366 .byte_size = 4, 367 .gpkt_offset = 144, 368 }, 369 { 370 /* AR36 */ 371 .idx = 37, 372 .regno = 0x124, 373 .byte_size = 4, 374 .gpkt_offset = 148, 375 }, 376 { 377 /* AR37 */ 378 .idx = 38, 379 .regno = 0x125, 380 .byte_size = 4, 381 .gpkt_offset = 152, 382 }, 383 { 384 /* AR38 */ 385 .idx = 39, 386 .regno = 0x126, 387 .byte_size = 4, 388 .gpkt_offset = 156, 389 }, 390 { 391 /* AR39 */ 392 .idx = 40, 393 .regno = 0x127, 394 .byte_size = 4, 395 .gpkt_offset = 160, 396 }, 397 { 398 /* AR40 */ 399 .idx = 41, 400 .regno = 0x128, 401 .byte_size = 4, 402 .gpkt_offset = 164, 403 }, 404 { 405 /* AR41 */ 406 .idx = 42, 407 .regno = 0x129, 408 .byte_size = 4, 409 .gpkt_offset = 168, 410 }, 411 { 412 /* AR42 */ 413 .idx = 43, 414 .regno = 0x12a, 415 .byte_size = 4, 416 .gpkt_offset = 172, 417 }, 418 { 419 /* AR43 */ 420 .idx = 44, 421 .regno = 0x12b, 422 .byte_size = 4, 423 .gpkt_offset = 176, 424 }, 425 { 426 /* AR44 */ 427 .idx = 45, 428 .regno = 0x12c, 429 .byte_size = 4, 430 .gpkt_offset = 180, 431 }, 432 { 433 /* AR45 */ 434 .idx = 46, 435 .regno = 0x12d, 436 .byte_size = 4, 437 .gpkt_offset = 184, 438 }, 439 { 440 /* AR46 */ 441 .idx = 47, 442 .regno = 0x12e, 443 .byte_size = 4, 444 .gpkt_offset = 188, 445 }, 446 { 447 /* AR47 */ 448 .idx = 48, 449 .regno = 0x12f, 450 .byte_size = 4, 451 .gpkt_offset = 192, 452 }, 453 { 454 /* AR48 */ 455 .idx = 49, 456 .regno = 0x130, 457 .byte_size = 4, 458 .gpkt_offset = 196, 459 }, 460 { 461 /* AR49 */ 462 .idx = 50, 463 .regno = 0x131, 464 .byte_size = 4, 465 .gpkt_offset = 200, 466 }, 467 { 468 /* AR50 */ 469 .idx = 51, 470 .regno = 0x132, 471 .byte_size = 4, 472 .gpkt_offset = 204, 473 }, 474 { 475 /* AR51 */ 476 .idx = 52, 477 .regno = 0x133, 478 .byte_size = 4, 479 .gpkt_offset = 208, 480 }, 481 { 482 /* AR52 */ 483 .idx = 53, 484 .regno = 0x134, 485 .byte_size = 4, 486 .gpkt_offset = 212, 487 }, 488 { 489 /* AR53 */ 490 .idx = 54, 491 .regno = 0x135, 492 .byte_size = 4, 493 .gpkt_offset = 216, 494 }, 495 { 496 /* AR54 */ 497 .idx = 55, 498 .regno = 0x136, 499 .byte_size = 4, 500 .gpkt_offset = 220, 501 }, 502 { 503 /* AR55 */ 504 .idx = 56, 505 .regno = 0x137, 506 .byte_size = 4, 507 .gpkt_offset = 224, 508 }, 509 { 510 /* AR56 */ 511 .idx = 57, 512 .regno = 0x138, 513 .byte_size = 4, 514 .gpkt_offset = 228, 515 }, 516 { 517 /* AR57 */ 518 .idx = 58, 519 .regno = 0x139, 520 .byte_size = 4, 521 .gpkt_offset = 232, 522 }, 523 { 524 /* AR58 */ 525 .idx = 59, 526 .regno = 0x13a, 527 .byte_size = 4, 528 .gpkt_offset = 236, 529 }, 530 { 531 /* AR59 */ 532 .idx = 60, 533 .regno = 0x13b, 534 .byte_size = 4, 535 .gpkt_offset = 240, 536 }, 537 { 538 /* AR60 */ 539 .idx = 61, 540 .regno = 0x13c, 541 .byte_size = 4, 542 .gpkt_offset = 244, 543 }, 544 { 545 /* AR61 */ 546 .idx = 62, 547 .regno = 0x13d, 548 .byte_size = 4, 549 .gpkt_offset = 248, 550 }, 551 { 552 /* AR62 */ 553 .idx = 63, 554 .regno = 0x13e, 555 .byte_size = 4, 556 .gpkt_offset = 252, 557 }, 558 { 559 /* AR63 */ 560 .idx = 64, 561 .regno = 0x13f, 562 .byte_size = 4, 563 .gpkt_offset = 256, 564 }, 565 { 566 /* LBEG */ 567 .idx = 65, 568 .regno = 0x0200, 569 .byte_size = 4, 570 .gpkt_offset = 260, 571 .stack_offset = ___xtensa_irq_bsa_t_lbeg_OFFSET, 572 }, 573 { 574 /* LEND */ 575 .idx = 66, 576 .regno = 0x0201, 577 .byte_size = 4, 578 .gpkt_offset = 264, 579 .stack_offset = ___xtensa_irq_bsa_t_lend_OFFSET, 580 }, 581 { 582 /* LCOUNT */ 583 .idx = 67, 584 .regno = 0x0202, 585 .byte_size = 4, 586 .gpkt_offset = 268, 587 .stack_offset = ___xtensa_irq_bsa_t_lcount_OFFSET, 588 }, 589 { 590 /* SAR */ 591 .idx = 68, 592 .regno = 0x0203, 593 .byte_size = 4, 594 .gpkt_offset = 272, 595 .stack_offset = ___xtensa_irq_bsa_t_sar_OFFSET, 596 }, 597 { 598 /* WINDOWBASE */ 599 .idx = 69, 600 .regno = 0x0248, 601 .byte_size = 4, 602 .gpkt_offset = 276, 603 .is_read_only = 1, 604 }, 605 { 606 /* WINDOWSTART */ 607 .idx = 70, 608 .regno = 0x0249, 609 .byte_size = 4, 610 .gpkt_offset = 280, 611 .is_read_only = 1, 612 }, 613 { 614 /* PS */ 615 .idx = 73, 616 .regno = 0x02E6, 617 .byte_size = 4, 618 .gpkt_offset = 292, 619 .stack_offset = ___xtensa_irq_bsa_t_ps_OFFSET, 620 }, 621 { 622 /* THREADPTR */ 623 .idx = 74, 624 .regno = 0x02E7, 625 .byte_size = 4, 626 .gpkt_offset = 296, 627 #ifdef CONFIG_THREAD_LOCAL_STORAGE 628 /* Only saved in stack if TLS is enabled */ 629 .stack_offset = ___xtensa_irq_bsa_t_threadptr_OFFSET, 630 #endif 631 }, 632 { 633 /* SCOMPARE1 */ 634 .idx = 76, 635 .regno = 0x020C, 636 .byte_size = 4, 637 .gpkt_offset = 304, 638 .stack_offset = ___xtensa_irq_bsa_t_scompare1_OFFSET, 639 }, 640 { 641 /* EXCCAUSE */ 642 .idx = 143, 643 .regno = 0x02E8, 644 .byte_size = 4, 645 .gpkt_offset = 572, 646 .stack_offset = ___xtensa_irq_bsa_t_exccause_OFFSET, 647 }, 648 { 649 /* DEBUGCAUSE */ 650 .idx = 144, 651 .regno = 0x02E9, 652 .byte_size = 4, 653 .gpkt_offset = 576, 654 }, 655 { 656 /* EXCVADDR */ 657 .idx = 149, 658 .regno = 0x02EE, 659 .byte_size = 4, 660 .gpkt_offset = 596, 661 }, 662 { 663 /* A0 */ 664 .idx = 157, 665 .regno = 0x0000, 666 .byte_size = 4, 667 .gpkt_offset = 628, 668 .stack_offset = ___xtensa_irq_bsa_t_a0_OFFSET, 669 }, 670 { 671 /* A1 */ 672 .idx = 158, 673 .regno = 0x0001, 674 .byte_size = 4, 675 .gpkt_offset = 632, 676 }, 677 { 678 /* A2 */ 679 .idx = 159, 680 .regno = 0x0002, 681 .byte_size = 4, 682 .gpkt_offset = 636, 683 .stack_offset = ___xtensa_irq_bsa_t_a2_OFFSET, 684 }, 685 { 686 /* A3 */ 687 .idx = 160, 688 .regno = 0x0003, 689 .byte_size = 4, 690 .gpkt_offset = 640, 691 .stack_offset = ___xtensa_irq_bsa_t_a3_OFFSET, 692 }, 693 { 694 /* A4 */ 695 .idx = 161, 696 .regno = 0x0004, 697 .byte_size = 4, 698 .gpkt_offset = 644, 699 .stack_offset = -16, 700 }, 701 { 702 /* A5 */ 703 .idx = 162, 704 .regno = 0x0005, 705 .byte_size = 4, 706 .gpkt_offset = 648, 707 .stack_offset = -12, 708 }, 709 { 710 /* A6 */ 711 .idx = 163, 712 .regno = 0x0006, 713 .byte_size = 4, 714 .gpkt_offset = 652, 715 .stack_offset = -8, 716 }, 717 { 718 /* A7 */ 719 .idx = 164, 720 .regno = 0x0007, 721 .byte_size = 4, 722 .gpkt_offset = 656, 723 .stack_offset = -4, 724 }, 725 { 726 /* A8 */ 727 .idx = 165, 728 .regno = 0x0008, 729 .byte_size = 4, 730 .gpkt_offset = 660, 731 .stack_offset = -32, 732 }, 733 { 734 /* A9 */ 735 .idx = 166, 736 .regno = 0x0009, 737 .byte_size = 4, 738 .gpkt_offset = 664, 739 .stack_offset = -28, 740 }, 741 { 742 /* A10 */ 743 .idx = 167, 744 .regno = 0x000A, 745 .byte_size = 4, 746 .gpkt_offset = 668, 747 .stack_offset = -24, 748 }, 749 { 750 /* A11 */ 751 .idx = 168, 752 .regno = 0x000B, 753 .byte_size = 4, 754 .gpkt_offset = 672, 755 .stack_offset = -20, 756 }, 757 { 758 /* A12 */ 759 .idx = 169, 760 .regno = 0x000C, 761 .byte_size = 4, 762 .gpkt_offset = 676, 763 .stack_offset = -48, 764 }, 765 { 766 /* A13 */ 767 .idx = 170, 768 .regno = 0x000D, 769 .byte_size = 4, 770 .gpkt_offset = 680, 771 .stack_offset = -44, 772 }, 773 { 774 /* A14 */ 775 .idx = 171, 776 .regno = 0x000E, 777 .byte_size = 4, 778 .gpkt_offset = 684, 779 .stack_offset = -40, 780 }, 781 { 782 /* A15 */ 783 .idx = 172, 784 .regno = 0x000F, 785 .byte_size = 4, 786 .gpkt_offset = 688, 787 .stack_offset = -36, 788 }, 789 }; 790 791 struct gdb_ctx xtensa_gdb_ctx = { 792 .regs = gdb_reg_list, 793 .num_regs = ARRAY_SIZE(gdb_reg_list), 794 }; 795