Menu

#497 mcs51 usim: pass return value of simulated main function to host

None
closed-accepted
None
5
2 days ago
4 days ago
Oleg Endo
No

When running a program in the mcs51 simulator the return value of that program is lost (hardcoded to 0). This makes it difficult to use for running tests on the host and catching EXIT_SUCCESS/ EXIT_FAILURE

The attached patch allows the return value to be passed through.

1 Attachments

Discussion

  • Daniel Drotos

    Daniel Drotos - 4 days ago
    • status: open --> closed-accepted
    • assigned_to: Daniel Drotos
    • Group: -->
     
  • Daniel Drotos

    Daniel Drotos - 4 days ago
     

    Related

    Commit: [r16441]

  • Daniel Drotos

    Daniel Drotos - 4 days ago

    I've applied uCsim part only! Code generator is not touched.

    I think that selfjump after the main is not a good solution, as selfjump detection is not used in mcs51 regtests, becouse it is valid in normal code.

     
  • Oleg Endo

    Oleg Endo - 3 days ago

    Thanks for looking into it.

    I've been trying to update my SDCC from 4.2 to 4.5 and had this patch has been sitting in my tree. Apparently using selfjump was the old way of doing it. In fact, it's even still described in the 4.5 manual:

    (main.asm)
        .area GSFINAL (CODE)
        ljmp __sdcc_program_startup
    ;--------------------------------------------------------
    ; Home
    ;--------------------------------------------------------
        .area HOME (CODE)
        .area CSEG (CODE)
    __sdcc_program_startup:
        lcall _main
    ; return from main will lock up
        sjmp .
    

    It's just that the documentation doesn't match the actual implementation.

    I've also tried using simif 's' command and the execution path is different of course and the return value not forward. So I'm attaching another patch to fix this. It's adding a new function cl_uc::sim_stop_result. Please have a look again.

    By trying very hard, it seems the main function can be tricked into returning to a controlled exit function by overriding __sdcc_external_startupand re-implementing the static initialization.

    But perhaps it's better to add a way to allow users to implement/override their own exit function.

     
  • Daniel Drotos

    Daniel Drotos - 3 days ago

    What about using a label on the seljump which is after main?

    __sdcc_program_startup:
        lcall _main
    ; return from main will lock up
    __magic_point_after_main_to_stop_on:
        sjmp .
    

    uCsim can get address of the label from the cdb (or map) file and automatically break at that address and pass out return value produced by sim_stop_result().

     
  • Daniel Drotos

    Daniel Drotos - 3 days ago
     

    Related

    Commit: [r16444]

    • Oleg Endo

      Oleg Endo - 3 days ago

      Thanks!

       
  • Oleg Endo

    Oleg Endo - 3 days ago

    What about using a label on the seljump which is after main?
    uCsim can get address of the label from the cdb (or map) file and automatically break at that address and pass out return value produced by sim_stop_result().

    Yes, that sounds good!

     

Log in to post a comment.

MongoDB Logo MongoDB