[SOLVED] J-Link script compiler or interpreter errors

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

  • [SOLVED] J-Link script compiler or interpreter errors

    Hello,

    for trying to get the FCR4 scripts working with J-Link software V632c, i found that the code is compiled or interpreted wrong.
    It can observed that when using function results directly, garbage is returned. Workaround seem to be using temporary variables for the results.

    C Source Code

    1. int TestFunc(void)
    2. {
    3. int result;
    4. result = 0;
    5. //Report1(" TestFunc: ", result);
    6. return result;
    7. }
    8. void CallEvalFunc1(void)
    9. {
    10. int temp;
    11. Report(" CallEvalFunc1: entry");
    12. temp = TestFunc();
    13. if (temp != 0)
    14. {
    15. Report1(" ***if (temp != 0)***", temp);
    16. SYS_Sleep(750);
    17. }
    18. else
    19. {
    20. Report(" else.1");
    21. }
    22. Report(" CallEvalFunc1: exit");
    23. }
    24. void CallEvalFunc2(void)
    25. {
    26. Report(" CallEvalFunc2: entry");
    27. if (TestFunc() != 0)
    28. {
    29. Report(" ***if (TestFunc() != 0)***");
    30. SYS_Sleep(750);
    31. }
    32. else
    33. {
    34. Report(" else.2");
    35. }
    36. Report(" CallEvalFunc2: exit");
    37. }
    38. void CallEvalFunc3(void)
    39. {
    40. Report(" CallEvalFunc3: entry");
    41. if (0 != TestFunc())
    42. {
    43. Report(" ***if (0 != TestFunc())***");
    44. SYS_Sleep(750);
    45. }
    46. else
    47. {
    48. Report(" else.3");
    49. }
    50. Report(" CallEvalFunc3: exit");
    51. }
    52. void CallEvalFunc4(void)
    53. {
    54. int temp;
    55. Report(" CallEvalFunc4: entry");
    56. temp = TestFunc();
    57. Report1(" a) TestFunc() temp: ", temp);
    58. Report1(" b) TestFunc() direct: ", TestFunc());
    59. temp = TestFunc();
    60. Report1(" a) TestFunc() temp: ", temp);
    61. Report1(" b) TestFunc() direct: ", TestFunc());
    62. Report(" CallEvalFunc4: exit");
    63. }
    64. void ResetTarget(void)
    65. {
    66. Report("ResetTarget() from JLinkScript is executed");
    67. }
    68. void InitTarget(void)
    69. {
    70. Report("InitTarget: extry");
    71. CallEvalFunc1();
    72. CallEvalFunc2();
    73. CallEvalFunc3();
    74. CallEvalFunc4();
    75. Report("InitTarget: exit");
    76. }
    Display All


    output on V612i is:

    Source Code

    1. InitTarget: extry
    2. CallEvalFunc1: entry
    3. else.1
    4. CallEvalFunc1: exit
    5. CallEvalFunc2: entry
    6. else.2
    7. CallEvalFunc2: exit
    8. CallEvalFunc3: entry
    9. else.3
    10. CallEvalFunc3: exit
    11. CallEvalFunc4: entry
    12. a) TestFunc() temp: 0x00000000
    13. b) TestFunc() direct: 0x00000000
    14. a) TestFunc() temp: 0x00000000
    15. b) TestFunc() direct: 0x00000000
    16. CallEvalFunc4: exit
    17. InitTarget: exit
    Display All


    output on V632c is:

    Source Code

    1. InitTarget: extry
    2. CallEvalFunc1: entry
    3. else.1
    4. CallEvalFunc1: exit
    5. CallEvalFunc2: entry
    6. ***if (TestFunc() != 0)***
    7. CallEvalFunc2: exit
    8. CallEvalFunc3: entry
    9. else.3
    10. CallEvalFunc3: exit
    11. CallEvalFunc4: entry
    12. a) TestFunc() temp: 0x00000000
    13. b) TestFunc() direct: 0x00000139
    14. a) TestFunc() temp: 0x00000000
    15. b) TestFunc() direct: 0x00000139
    16. CallEvalFunc4: exit
    17. InitTarget: exit
    Display All

    The post was edited 2 times, last by Veit_Kannegieser ().

  • It seem to be a compiler problem in JLinkARM.dll,
    i have looked with a debugger, and found that for the
    indirect function result usage it generates:

    Source Code

    1. // temp = TestFunc();
    2. push R0 // Save registers in use
    3. call TestFunc
    4. mov R1, R0 // Save return value
    5. pop R0 // Restore registers
    6. str R1, [SP] // temp
    7. // Report1(" a) TestFunc() temp: ", temp);
    8. mov R11, _StrLit13
    9. ldr R12, [SP] // temp
    10. push R11-R12
    11. apicall 48, 2 // Report1
    Display All

    so the result travels R0 -> R1 -> [SP] -> R12 -> push.


    however for direct case:

    Source Code

    1. // Report1(" b) TestFunc() direct: ", TestFunc());
    2. mov R11, _StrLit14
    3. call TestFunc
    4. mov R12, R11
    5. push R11-R12
    6. apicall 48, 2 // Report1


    the function result in R0 gets ignored and the string address gets pushed in both R11 and R12.
  • Hello,

    Thank you for this detailed analysis.
    We will see if we can reproduce the reported issue and fix it accordingly.
    Sorry for any inconveniences caused.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Nino,

    i should have added, that the issue is visible for different targets,
    i tried the MB9DF125, but using the script on a Corex-A9 gives same results.

    Currently a lot of J-Links devices here seem to have developed wings,
    i currently only have access to a J-Link Ultra+ V1.2 for my daily work.
  • Hello,

    Veit_Kannegieser wrote:

    i should have added, that the issue is visible for different targets,
    Yes we figured. We will investigate which targets might be affected by broken third party Scriptfiles and try to add them natively so we
    have support control about these devices and we no longer rely on MCU vendors that get bought up every once in a while.

    Veit_Kannegieser wrote:

    Currently a lot of J-Links devices here seem to have developed wings,
    i currently only have access to a J-Link Ultra+ V1.2 for my daily work.
    If you are looking for a new J-Link device our trade in program might be interesting to you: segger.com/purchase/trade-in-program/

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.