[ABANDONED] Risc-V core hart selection?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [ABANDONED] Risc-V core hart selection?

    I'm trying to use my jlink to debug Starfive JH7110, which has a 1+4 harts version of U74-MC. I could successfully connect to chip, but I don't know which hart is selected and how to choose specific hart. Anyone could help?
  • I'm trying to set dmcontrol register to select hart, but commander always report using hart0. Is this a bug?
    Script:

    C Source Code

    1. int InitTarget(void)
    2. {
    3. //
    4. // TDI -> TAP_#1 -> TAP_#0 -> TDO
    5. //
    6. // TAP_#0 info:
    7. // Maybe E24?
    8. // IRLen: 5
    9. //
    10. // TAP_#1 info:
    11. // U74-MC here
    12. // IRLen: 5
    13. //
    14. //
    15. // Code to connect to TAP_#1
    16. //
    17. JLINK_JTAG_DRPre = 1;
    18. JLINK_JTAG_DRPost = 0;
    19. JLINK_JTAG_IRPre = 5;
    20. JLINK_JTAG_IRPost = 0;
    21. JLINK_JTAG_IRLen = 5;
    22. JLINK_SetDevice("U74-MC");
    23. return 0;
    24. }
    25. // Select needed hart
    26. // Seems Jlink could not handle multi-core debugging at the same time through script file?
    27. // Or there exists some APIs not written in official wiki that could handle this?
    28. int SetupTarget(void)
    29. {
    30. int ret;
    31. U32 dmcontrol_addr;
    32. U32 hasel_mask;
    33. U32 hartsello_mask;
    34. U32 hartselhi_mask;
    35. U32 dmcontrol_value;
    36. U32 hart_id;
    37. U32 hart_id_target;
    38. // Set wanted hart id here(0 is S7 core, 1~4 is U74 core)
    39. hart_id = 3;
    40. ret = 0;
    41. dmcontrol_addr = 0x10;
    42. hasel_mask = 0x04000000;
    43. hartsello_mask = 0x03FF0000;
    44. hartselhi_mask = 0x0000FFC0;
    45. // Core selection through writing DMI registers
    46. // First, do automatic configure
    47. // Needed or connection would fail
    48. ret = JLINK_RISCV_DMI_AutodetectDMISettings();
    49. if(ret < 0)
    50. {
    51. return ret;
    52. }
    53. // Second, read dmcontrol to get current hart;
    54. ret = JLINK_RISCV_DMI_ReadReg(dmcontrol_addr, &dmcontrol_value);
    55. if(ret < 0)
    56. {
    57. return ret;
    58. }
    59. hart_id_target = ((dmcontrol_value & hartsello_mask) >> 16) | ((dmcontrol_value & hartselhi_mask) << 4);
    60. JLINK_SYS_Report("********************************");
    61. JLINK_SYS_Report("Pre-selection info");
    62. JLINK_SYS_Report1("dmcontrol value is: ", dmcontrol_value);
    63. JLINK_SYS_Report1("Current hart id is: ", hart_id_target);
    64. JLINK_SYS_Report("********************************");
    65. // Third, modify dmcontrol value to select wanted hart.
    66. dmcontrol_value = dmcontrol_value | ((hart_id & (hartsello_mask >> 16)) << 16) | ((hart_id & (hartselhi_mask << 4)) >> 4);
    67. ret = JLINK_RISCV_DMI_WriteReg(dmcontrol_addr, dmcontrol_value);
    68. if(ret < 0)
    69. {
    70. return ret;
    71. }
    72. // Fourth, check if configure is successful
    73. ret = JLINK_RISCV_DMI_ReadReg(dmcontrol_addr, &dmcontrol_value);
    74. hart_id_target = ((dmcontrol_value & hartsello_mask) >> 16) | ((dmcontrol_value & hartselhi_mask) << 4);
    75. JLINK_SYS_Report("********************************");
    76. JLINK_SYS_Report("Post-selection info");
    77. JLINK_SYS_Report1("dmcontrol value is: ", dmcontrol_value);
    78. JLINK_SYS_Report1("Current hart id is: ", hart_id_target);
    79. JLINK_SYS_Report("********************************");
    80. return ret;
    81. }
    Display All

    And here's JLink Commander output:

    Source Code

    1. SEGGER J-Link Commander V7.86h (Compiled Apr 12 2023 16:11:59)
    2. DLL version V7.86h, compiled Apr 12 2023 16:10:23
    3. Connecting to J-Link via USB...O.K.
    4. Firmware: J-Link V11 compiled Mar 28 2023 16:59:55
    5. Hardware version: V11.00
    6. J-Link uptime (since boot): 0d 00h 06m 32s
    7. S/N: 261011862
    8. License(s): FlashBP, GDB
    9. OEM: SEGGER-EDU
    10. USB speed mode: High speed (480 MBit/s)
    11. VTref=3.300V (fixed)
    12. Type "connect" to establish a target connection, '?' for help
    13. J-Link>connect
    14. Please specify device / core. <Default>: U74-MC
    15. Type '?' for selection dialog
    16. Device>
    17. Please specify target interface:
    18. J) JTAG (Default)
    19. S) SWD
    20. T) cJTAG
    21. TIF>
    22. Device position in JTAG chain (IRPre,DRPre) <Default>: -1,-1 => Auto-detect
    23. JTAGConf>
    24. Specify target interface speed [kHz]. <Default>: 4000 kHz
    25. Speed>15000
    26. Device "U74-MC" selected.
    27. Connecting to target via JTAG
    28. ConfigTargetSettings() start
    29. ConfigTargetSettings() end - Took 6us
    30. InitTarget() start
    31. Device "U74-MC" selected.
    32. InitTarget() end - Took 1.15ms
    33. TotalIRLen = 10, IRPrint = 0x0021
    34. JTAG chain detection found 2 devices:
    35. #0 Id: 0x07110CFD, IRLen: 05, Unknown device
    36. #1 Id: 0x07110CFD, IRLen: 05, Unknown device
    37. Debug architecture:
    38. RISC-V debug: 0.13
    39. AddrBits: 7
    40. DataBits: 32
    41. IdleClks: 5
    42. Memory access:
    43. Via system bus: Yes (8/16/32/64-bit accesses are supported)
    44. Via ProgBuf: Yes (16 ProgBuf entries)
    45. Via abstract command (AAM): May be tried as last resort
    46. DataBuf: 2 entries
    47. autoexec[0] implemented: Yes
    48. Detected: RV64 core
    49. Temp. halting CPU for for feature detection...
    50. HW instruction/data BPs: 8
    51. Support set/clr BPs while running: No
    52. HW data BPs trigger before execution of inst
    53. CSR access via abs. commands: No
    54. Feature detection done. Restarting core...
    55. BG memory access support: Via SBA
    56. SetupTarget() start
    57. ********************************
    58. Pre-selection info
    59. dmcontrol value is: 0x00000001
    60. Current hart id is: 0x00000000
    61. ********************************
    62. ********************************
    63. Post-selection info
    64. dmcontrol value is: 0x00030001
    65. Current hart id is: 0x00000003
    66. ********************************
    67. SetupTarget() end - Took 3.56ms
    68. Memory zones:
    69. Zone: "Default" Description: Default access mode
    70. RISC-V identified.
    71. J-Link>halt
    72. pc = 000000004000AB9A sp = 0000000040060F00 ra = 000000004000ABA0
    73. gp = 0000000000000000 tp = 0000000040061000 fp = 0000000040060F30
    74. t0 = 0000000000000022 t1 = 0000000000000000 t2 = 0000000000000000
    75. t3 = 0000000000000000 t4 = 0000000000000000 t5 = 0000000000000000 t6 = 0000000000000000
    76. a0 = 0000000000000001 a1 = 0000000000000000 a2 = 0000000000000000 a3 = 0000000000090006
    77. a4 = 0000000002000000 a5 = 0000000000000808 a6 = 0000000000000000 a7 = 0000000000000000
    78. s1 = 0000000040061068 s2 = 0000000000000002 s3 = 0000000000000000 s4 = 0000000040042000
    79. s5 = 0000000040042020 s6 = 0000000000000000 s7 = 0000000000000018 s8 = 0000000000002000
    80. s9 = 000000004004EAB8 s10 = 0000000000000000 s11 = 0000000000000000
    81. J-Link>readcsr 0xF11
    82. CSR 0x0F11: 0x00000489
    83. J-Link>readcsr 0xF12
    84. CSR 0x0F12: 0x8000000000000007
    85. J-Link>readcsr 0xF13
    86. CSR 0x0F13: 0x04210427
    87. J-Link>readcsr 0xF14
    88. CSR 0x0F14: 0x00000000
    89. J-Link>readcsr 0x301
    90. CSR 0x0301: 0x8000000000901107
    Display All

    CSR 0x301(misa) also implies this is a S7 core(at hart 0) rather than a U74 core.