hoglet67 / PiTubeDirect

Bare-metal Raspberry Pi project that attaches to the Acorn TUBE interface and emulates many BBC Micro Co Processors
GNU General Public License v3.0
188 stars 23 forks source link

Workspace pointer not passed to Escape Handler in Native ARM copro #112

Closed markdryan closed 3 years ago

markdryan commented 3 years ago

At least I don't think it is. I'm not quite sure how to debug this with my setup but looking at the code it doesn't seem to be passed. The escape handler wrapper seems to initialise R11, which is good, but not R12.

https://github.com/hoglet67/PiTubeDirect/blob/697b4c038fa5cb79ea98398e7da871f286642db0/src/copro-armnativeasm.S#L217-L230

The workspace pointer is however passed to the exit handler.

https://github.com/hoglet67/PiTubeDirect/blob/697b4c038fa5cb79ea98398e7da871f286642db0/src/copro-armnativeasm.S#L233-L243

https://github.com/hoglet67/PiTubeDirect/blob/697b4c038fa5cb79ea98398e7da871f286642db0/src/tube-swi.c#L809-L814

Here's my handler and registration code

        MOV R0, #9
        ADD R1, R15, #16
        MOV R2, R12                                         ; Pass the workspace pointer to SWI &40.  I expect to see this value in R12 in the handler.
        SWI &40
        STR R1, [R12, -#8]
        STR R2, [R12, -#12]
        B label_14
.label_45                                                       ; handler starts here
        TST R11, #64
        MOVEQ R15, R14
        MOV R11, #1
        STR R11, [R12, -#4]                              ; R12 is expected to be initialised to the workspace passed to R2 during the call to SWI &40
        MOV R15, R14

When I press the escape button weird things happen. I think this is because R12 points to some random value, which the handler then writes to. I can't be absolutely sure as I can't quite figure out how to debug but looking at the PiTube direct code, the workspace pointer doesn't seem to be passed to the escape handler.

markdryan commented 3 years ago

Here's the RiscOS documentation for the escape handler.

https://www.riscosopen.org/wiki/documentation/show/Escape%20Handler

hoglet67 commented 3 years ago

I've pushed a fix for this to the gecko-dev branch.

Would you be able to test it for me?

(if you need me to upload a PiTubeDirect build for testing, then I can do that)

markdryan commented 3 years ago

The fix looks good to me.

Would you be able to test it for me?

I can indeed. It would be great if you could upload a test build.

hoglet67 commented 3 years ago

PiTubeDirect_20201224_1828_dmb.zip

This includes the fixed version of OS_ReadPoint

markdryan commented 3 years ago

My escape handler still isn't working but looking at the code I think it's getting passed the EXIT handler's R12.

POINT(-1,-1) works fine however.

Also, escape still works in general on the *prompt and also in BASIC.

markdryan commented 3 years ago

So

unsigned int r12 = env->handler[EXIT_HANDLER].r12;

should be

unsigned int r12 = env->handler[ESCAPE_HANDLER].r12;

in the two places it's used.

hoglet67 commented 3 years ago

Sorry, that was a stupid cut/paste error

Here's another build: PiTubeDirect_20201224_2041_dmb.zip

markdryan commented 3 years ago

Here's another build:

Excellent. It works! I can now escape out of my binaries without any issues. I briefly tested escape on the * prompt and in ARMBASIC and everything seems to be working. Thanks for the quick fix!

hoglet67 commented 3 years ago

Thanks for testing this.