Semihosting broken with latest GCC arm-eabi update

Sysprogs forums Forums VisualGDB Semihosting broken with latest GCC arm-eabi update

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #885
    zarthcode
    Participant

    Just the other day, VisualGDB invited me to update to the latest arm-eabi release. I did it, not knowing that it would break semihosting.

    Now, when calling initialise_monitor_handles(), a SVC call is performed (it made a SIGTRAP and “just worked”, before) – something I’m not sure that I understand – but am digging into.

    Target is a STM32F427 – What changed?

    #3331
    support
    Keymaster

    Hi,

    The previous version did not include the initialise_monitor_handles() method at all. In the current version it is used by the weak implementations of syscalls that can be overridden. Are you calling it initialise_monitor_handles() explicitly, or is it called by some syscall you are invoking?

    #3332
    zarthcode
    Participant

    That’s the problem. I don’t know. I don’t have the previous version/build. VisualGDB prompted me to update SysGCC, and that’s when the change occurred. It was always GCC 4.8.2, initialise_monitor_handles() was absolutely present, as it worked as expected. I have nothing overridden.

    I’ve since switched to launchpad GCC 4.9, it’s initialise_monitor_handles() implementation works exactly as expected, without making a SVC request.

    #3335
    support
    Keymaster

    Hi,

    We’ve released an updated toolchain based on gcc 4.9.1 that resolves some issues and includes a newer newlib. Does your problem still happen with that version?

    #3333
    zarthcode
    Participant

    Only a slight change. There is no wonky SVC call now, which is no longer a show-stopper. However, printf is still no longer redirected as a result of initialise_monitor_handles(); – All calls to printf appear to (silently) go nowhere apparent. (No issues w/launchpad.)

    #3334
    support
    Keymaster

    Hi,

    This can be related to the implementation of initialize_monitor_handles() in newlib 2.1.0:

    void
    initialise_monitor_handles (void)
    {
    int i;
    
    #ifdef ARM_RDI_MONITOR
    int volatile block[3];
    
    block[0] = (int) ":tt";
    block[2] = 3;     /* length of filename */
    block[1] = 0;     /* mode "r" */
    monitor_stdin = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
    
    block[0] = (int) ":tt";
    block[2] = 3;     /* length of filename */
    block[1] = 4;     /* mode "w" */
    monitor_stdout = monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
    #else
    int fh;
    const char * name;
    
    name = ":tt";
    asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
    : "=r"(fh)
    : "i" (SWI_Open),"r"(name)
    : "r0","r1");
    monitor_stdin = fh;
    
    name = ":tt";
    asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
    : "=r"(fh)
    : "i" (SWI_Open),"r"(name)
    : "r0","r1");
    monitor_stdout = monitor_stderr = fh;
    #endif
    
    for (i = 0; i < MAX_OPEN_FILES; i ++)
    openfiles.handle = -1;

    openfiles[0].handle = monitor_stdin;
    openfiles[0].pos = 0;
    openfiles[1].handle = monitor_stdout;
    openfiles[1].pos = 0;
    }

    Our toolchain includes a patch that declares this function as __attribute__((weak)), so you can simply get the newlib source code and add this one file to your project, setting ARM_RDI_MONITOR if you need it and modifying anything else you need. You won’t need to rebuild the libc or anything else, the functions from your manually added file will simply replace the default ones.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.