Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M16C #pragma 32bit register support #7358

Open
RyanHope opened this issue Jan 9, 2025 · 4 comments
Open

M16C #pragma 32bit register support #7358

RyanHope opened this issue Jan 9, 2025 · 4 comments

Comments

@RyanHope
Copy link

RyanHope commented Jan 9, 2025

The M16C compiler supports a #pragma macro that allows the programmer to specify which registers are used for arguments getting passed to a function. The current M16C processor support does not detect these or even seem to support manually editing the function signature to support this. Below is a description of this #pragma macro:

image

Here is an example of this being used in a binary I am working on.

          0c9a68 0b 12 0e        MOV.B:S    DAT_000e12,R0L
          0c9a6b eb 5f 0d 00     MOVA       0xd,A1
          0c9a6f eb 4f b2 00     MOVA       0xb2,A0
          0c9a73 72 f2 3d 0e     MOV.B:G    DAT_000e3d,R1L
          0c9a77 c3 18           MOV.B:S    #0x18,R0H
          0c9a79 f5 5e 34        JSR.W      FUN_0cced8
          0c9a7c 72 2f 3d 0e     MOV.B:G    R1L,DAT_000e3d
          0c9a80 73 0f 2b 0e     MOV.W:G    R0,DAT_000e2b
                             **************************************************************
                             *                          FUNCTION                          *
                             **************************************************************
                             void FUN_0cced8(void)
             void              <VOID>         <RETURN>
                             FUN_0cced8                                      XREF[4]:     0c9a79(c), 0c9a95(c), 0c9ace(c), 
                                                                                          0c9b07(c)  
          0cced8 8b 02           SUB.B:S    #0x2,R0H
          0cceda c0 21           CMP.B:G    R1L,R0H
          0ccedc 68 03           JGEU       LAB_0ccee0
          0ccede 72 12           MOV.B:G    R0H,R1L
                             LAB_0ccee0                                      XREF[1]:     0ccedc(j)  
          0ccee0 d8 03           MOV.B:Q    #0x0,R1H
          0ccee2 73 12           MOV.W:G    R1,R2
          0ccee4 6a 16           JEQ        LAB_0ccefb
          0ccee6 a1 24           ADD.W:G    R2,A0
          0ccee8 77 e5           ADCF.W     A1
                             LAB_0cceea                                      XREF[1]:     0ccef8(j)  
          0cceea 74 a3           LDE.B      [A1A0],R1H
          0cceec c0 30           CMP.B:G    R1H,R0L
          0cceee 68 15           JGEU       LAB_0ccf04
          0ccef0 77 54 01 00     SUB.W:G    #0x1,A0
          0ccef4 77 75 00 00     SBB.W      #0x0,A1
          0ccef8 f8 f2 f0        ADJNZ.B    #-0x1,R1L

If I try to edit the function signature and with custom storage checked, I can't add A1A0 as a parameter.

How do I fix this?

@RyanHope
Copy link
Author

RyanHope commented Jan 9, 2025

This is what the function editor looks like when I try and add A1A0 as the register source for an argument...
image

@RyanHope
Copy link
Author

RyanHope commented Jan 9, 2025

If I modify the .cspec and add this prototype:

  <prototype name="__pragmacall" extrapop="0" stackshift="0">
    <input>
        <pentry maxsize="4" minsize="1" align="1">
          <register name="A1A0" />
        </pentry>
        <pentry maxsize="4" minsize="1" align="1">
          <register name="R3R1" />
        </pentry>
        <pentry maxsize="4" minsize="1" align="1">
          <register name="R2R0" />
        </pentry>
    </input>
    <output>
        <pentry maxsize="1" minsize="1">
          <register name="R1L"/>
        </pentry>
    </output>
    <unaffected>
      <register name="SP" />
      <register name="INTB" />
      <register name="FB" />
      <register name="SB" />
      <register name="FLG" />
    </unaffected>
  </prototype>

Then I can modify the signature to look like this. However, as can be seen none of the storage sizes are larger than 1 so there are these filler "register" params that should not actually exist if the storage sizes were correct.
image

I am stuck here.

@RyanHope
Copy link
Author

RyanHope commented Jan 9, 2025

Hmm, for some reason if I replace this __pragama call with with the default __stdcall, everything seems to be working as better.

image

@RyanHope
Copy link
Author

RyanHope commented Jan 9, 2025

If I try and edit the datatype for the pointer however things break again because pointers are set to only be 3 bytes.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant