#39 make semi hosting not one time decision at project creation

Next Release
closed-fixed
None
5
2014-07-14
2014-02-20
diabolo38
No

It's at project creation that user decide to use or not and what type of semi hosting is needed . it would be nice if semi_hosting could be enable or type change at any time of the project life.

I'm girth now trying to do it from stm32f4 std perif start sample project as a configuration. It's should only be matter of changing a few linker option and also exclude/include some file in the build. It's not yet working but i think i'm nearly done
I can provide support and detail description of what to do when over
but implementing it in java for eclipse is like black magic to me ;)

These request is linked to the fact that semi-hosted program do not run on stm32f4 discovery if not debug from st-link (non semi hosted app do)? maybe it's just a board or probe issue ? or maybe just the way it is meant to be ?
I'm investigating why and how to enhance that but i've been unlucky so far
Removing rdimon and disabling most of the cmis startup hosting code did not help
Id id not find where syscall is and feel like it is the faulty .... any idea is welcome

Discussion

1 2 > >> (Page 1 of 2)
  • Liviu Ionescu (ilg)

    • status: open --> open-accepted
    • assigned_to: Liviu Ionescu (ilg)
     
  • Liviu Ionescu (ilg)

    semi_hosting could be enable or type change at any time of the project life.

    using semihosting is toolchain dependent

    a few linker option and also exclude/include some file in the build.

    this is application specific, I doubt there is a magic solution for this

    semi-hosted program do not run on stm32f4 discovery if not debug from st-link

    I successfully use semihosting with stm32f4discovery both with jlink and openocd.

    any idea is welcome

    I'm currently working on a set of libraries to improve newlib and to replace librdimon, but they are not ready.

     
    Last edit: Liviu Ionescu (ilg) 2014-02-20
    • diabolo38

      diabolo38 - 2014-02-20

      semi-hosted program do not run on stm32f4 discovery if not debug from st-link

      I successfully use semihosting with stm32f4discovery both with jlink and openocd.

      Yes i can also run them with opencd via onboard st-link
      but it run only when started from the gui.
      After usb disconected and reconected program do not run (the example flashing led is not blinking)

      I'm currently working on a set of libraries to improve newlib and to replace librdimon, but they are not ready.

      good to here

       
      • Liviu Ionescu (ilg)

        After usb disconected and reconected program do not run (the example flashing led is not blinking)

        reading manuals may sometimes be useful :-)

        semihosting works via the debugger connection; stop the debugger and the target hangs with exception.

         
  • diabolo38

    diabolo38 - 2014-02-20

    For project started from new stm32f4 std perif it's finally straight forward, i have it working now. I can provide the project and setting if you requires.

    But I Agree base on application and project no automatic switch is easy and possible
    But at that level where you handle your own ld lib start-up etc.. user is maybe expert enough to make it's own configuration adaption and deal with hosting.
    I'm not yet there with gnu-arm-embedded ;)

    Anyway end of the day what is most annoying me is why the semi hosted program require the host side TO RUN ? Could not the target side just make all semi hosted call fail (return -1) but yet run until host attached ? (ok no debug printf but who care nobody is listening?)

    That strategy is what i was what find in most cpu/toolchain i've used so far.
    It is fairly easy for the host debugger to modify or intercept a no_dbg_sts symbol (bkp)
    and set pc/jmp to over known symbol ie with_dbg_sts.
    It's somehow how i tweaked the no semi hosting configuration modifying the
    do_AngelSWI to return -1 and not linking the startup + rdimon lib .

     
  • Liviu Ionescu (ilg)

    It is fairly easy for the host debugger to modify or intercept a no_dbg_sts symbol (bkp)
    and set pc/jmp to over known symbol ie with_dbg_sts.

    that's a good observation.

    if I remember right, on cortex-m the instruction is 'bkpt 0xA8'.

    could you experiment with an exception handling routine to ignore only this specific code and continue execution? if so, I'll add this routine to the template code.

     
  • diabolo38

    diabolo38 - 2014-02-21

    hum ... is the exception to handle DebugMon_Handler i can see in vectors_stm32f4xx.c ?
    it's also the code for the semi hosting that do_AngelSWI translate on the
    do_AngelSWI:
    ....
    0800057f: bkpt 0x00ab

    Where is the bkpt handler ? is it one of the "reserved" vector ?
    I'm still readind about bkpt monitor etc ... but not yet found much

     
    • Liviu Ionescu (ilg)

      I don't have time to search for these details now, you have to discover them alone.

      I suggest you do the following: insert another bkpt, for example 0x77, run it, and see what handler it reaches. normally the debugger should not catch it, but I do not know, eventually try different values, maybe you can catch one of them.

      then read very thoroughly the ARM reference manuals, and the STM manuals, to understand how exceptions work, and if there is any chance to skip the break and continue from the next instruction. (I did not try this, but it might be possible)

       
  • diabolo38

    diabolo38 - 2014-02-21

    I'm reading the arm ref but the doc it's not so helpful so far
    An exception is triggered but witch one ? svc , hardfault etc ... also hwo are stasu reg affected ?
    he R4 doc says bkpt generate the hard fault execption but m4 doc doesn't say anything such, anyway. "swi" beeing used i'll bet on SVC_handler .

    Semi hosting beeing active the bkpt must be managed but first quick inspection of the vector table is not showing it ? i've more to investigate ...

    Note that a soft control is much simpler,a test for a ram variable (.bss 0 init) set by debugger to non 0 would do the trick...
    custom .gdbinit on debug configuration can be used to do that almost automatically at load time.

     
  • diabolo38

    diabolo38 - 2014-02-22

    rdimon lib or startup is causing an hard fault when debugger is not connected
    What cannot be observed with debugger attached :(
    The reason is a bkpt instruction when debugger is not on cause an hard fault fault.
    A soft bkpt in code casue same failure without rdimon linked and debugger off.

    Some peace of inforamtion i found that may be helpfull
    test presence of debuger => ( CoreDebug->DHCSR & 1)
    What i already added to bypass bkpt usage in do_AngelSWI

    Now need try to see and fix rdimon failure
    what gonna be tricky to rebuild under window :(

     
    Last edit: diabolo38 2014-02-22
  • Liviu Ionescu (ilg)

    test presence of debugger

    that's useful, as I told you I'm working on a replacement to librdimon, so we can use this to simply avoid issuing the bkpt.

    but it would also be useful to extend the fault handler to return from it, probably with R0=-1 to inform the caller that an error occurred, in case someone uses other libraries.

     
  • diabolo38

    diabolo38 - 2014-02-22

    Done it in a mix asm/c as stack frame depend on the c locals it's not very clean.

    if ( !(CoreDebug->DHCSR &1) && (SCB->HFSR&SCB_HFSR_DEBUGEVT_Msk) ){
    // togle red led every 1 green every 8k
    asm volatile ("mov r0, #-1; str r0, [sp, #16];"); // make r0=-1 return
    // imm #16 is for #8 for 2xlocal (scb and i) + 2 push to save r7 and lr>
    return
    }

    The debug exception keep on cumming at very high rate i suspect continuously
    so whatever is doing rdimon it keep on doing it
    or maybe pc need to be advance to skip the faulty bkp or whatever rdi execute

    So i've not over choice to wait for your new monitor or fix rdimon source

     
    • Liviu Ionescu (ilg)

      I'm not sure I understand it. what exception routine is this?

      as functionality, you should check if the breakpoint code is 0xAB, and if so, advance to the next instruction and return -1.

      if not BKPT 0xAB, probably remain in a loop, since it is a different exception.

      So i've not over choice to wait for your new monitor or fix rdimon source

      your code should work with librdimon; a patch in my future library will simply avoid throwing this exception and you'll have no way to test it.

       
  • diabolo38

    diabolo38 - 2014-02-23

    arm/st doc is light on the subject but from what i read and personal trial the conclusion
    is there's no "debug/bkpt exception".
    When not debuged cpu here throw an hard_fault on bkpt instructcion ,
    when debuged it goes in debug state and debugger must put it back to run.
    (i do not see hard_fautl invoked when debuiging a test bkpt)

    So that's debug fault is what i catch in in hardfault exception handler by lookign at SCB->HFSR&SCB_HFSR_DEBUGEVT_Msk. "Debug Event"

    Modifying return pc is not easy it depend on the instruction size itself thumb arm...
    Also it is hard to make the difference from what is the bkpt purpose?
    Is it a monitor init or user one ? i'll be assuming user bkpt never show.

    in "rdimon" crt0.S ther's two bkp "angel call" one is to get heap size and second program command line ( see gcc-arm-none-eabi-4_8-2013q4-20131204\src\newlib\newlib\libc\sys\arm\crt0.S)
    that damned crt0 is not checking any error code in r0 instead it used value setup by monitor in [r1].
    what i'll try to patch.
    I'm done with that just need to test it no time today ;).

    Adding a modifiied crt0.s in the project could be done but it depend on too many external define :(

     

    Related

    Commit: [r1]

  • Liviu Ionescu (ilg)

    arm/st doc is light on the subject but from what i read and personal trial the
    conclusion is there's no "debug/bkpt exception".

    that's correct

    when debuged it goes in debug state and debugger must put it back to run.
    (i do not see hard_fautl invoked when debuiging a test bkpt)

    for test purposes, I already suggested you to use a bkpt with another number; the debugger should not catch it, so you should be able to step by step your hard fault handler.

    Modifying return pc is not easy it depend on the instruction size itself thumb arm...

    we are addressing Cortex-M devices only, so no arm instructions

    Also it is hard to make the difference from what is the bkpt purpose?

    if you know the PC where the fault occured, you can read the instruction from flash and compare the corresponding byte with 0xAB.

    Is it a monitor init or user one ? i'll be assuming user bkpt never show.

    ?

    that damned crt0 is not checking any error code in r0 instead it
    used value setup by monitor in [r1].

    unfortunately librdimon quality is pretty low. that's the reason I'm considering a rewrite.

     

    Related

    Commit: [r1]

  • diabolo38

    diabolo38 - 2014-02-23

    rdimon even if low quality is fine (i patched it even before it get involved in syscall.c) it is the crt0.s (with rdi) that is not quite correct up to me.
    Say if you use debugger it work but if you run program non-attached it crash.

    I have now patched the return address (pc+2) and have it working standalone "oura" ,
    code is perfectible like you say we can analyze op-code or just check the fault address if < main then patch r0/r1 else just bypass bkp.

    I can only agree there's room to improve semi hosting monitor , I've used over cpu with far better support where no code at all was added only a few data for file descriptor+ cmd line. It is IMO the best option to go.

    Actual semi-host crt0 want debugger from boot what i cant' understand even if we fix the few initial bkp if debugger is not attached at boot we will not ever get any std file (stdin,stdout,stderr) if debugger connect at later time. All debug print will fail cos all fd=-1 .
    Setting the fd from debugger is easy as we have or can make sure we'll have the symbol where to store them.
    If we set that from debugger eclipse-plugin or gdb init script at attach time all i/o will work as soon as we plug and it will not requires any f/w code for it .

    if you need help or a beta tester for that new monitor just let me know, just be aware than i'm more confident with asm/c/c++ than java :D .

    Discussion is far from the initial topic , dynamic switch to/from semi host no semi-host that it's actually easy for standard example project. I did it easily.

     
    • Liviu Ionescu (ilg)

      I have now patched the return address (pc+2) and have it working standalone "oura"

      ok

      I can only agree there's room to improve semi hosting monitor

      what monitor are you referring to?


      since I'm not sure the initial idea was clear, I restate it: we need a fault handler to be added to the template code, so that projects created with the retargeted and semihosting templates will no longer crash after disconnecting from the debugger. the sequence to test is simple, program flash, disconnect the debugger, press hardware reset; if the led will blink, we're done.

      when you have a final handler routine, that ignores only bkpt 0xAB and stops for all other faults, please sent it for testing.

       
  • diabolo38

    diabolo38 - 2014-02-23

    ok i'll clean up the code and provide it.

     
  • diabolo38

    diabolo38 - 2014-02-24

    Had some hard time understating crt0.s and what "Angel" as to do for it
    some optimization trick to sort-out also but i'm done :D

    Tested at O0,O1,O3 blink OK , many malloc loop so heap setup look great as well.
    How do i sent you the code ? any svn/git ?
    You need also to modify syscall.c.

     
    • Liviu Ionescu (ilg)

      How do i sent you the code ? any svn/git ?
      You need also to modify syscall.c.

      if you need patches to syscalls.c, add comments to each one explaining the reason for the patch.

      then create a new ticket in the feature requests, explaining exactly what this is all about.

      add the archive containing your patches/source files.

      SourceForge has some problems, I can not access the web interface past the first page of each ticket.

      Liviu

       
  • Liviu Ionescu (ilg)

    the new beta version should allow to change the project between semihosting/retargetting/freestanding after project creation, by changing some preprocessor definitions.

    could you test if this is functional?

     
  • diabolo38

    diabolo38 - 2014-03-27

    sure,
    beta is available on update-test i guess ?

     
    • Liviu Ionescu (ilg)

      this is correct.

      there is a new page with more details about contributing.

      the new tracker is called "Beta versions", it is the last in the SourceForge list.

       
  • Liviu Ionescu (ilg)

    fixed in 2.2.1-201404120702

     
1 2 > >> (Page 1 of 2)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks