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

Support MIPS for OpenWRT #21

Closed
winlinvip opened this issue Sep 30, 2021 · 1 comment
Closed

Support MIPS for OpenWRT #21

winlinvip opened this issue Sep 30, 2021 · 1 comment
Assignees
Labels

Comments

@winlinvip
Copy link
Member

winlinvip commented Sep 30, 2021

Calling conventions

MIPS has had several calling conventions, especially on the 32-bit platform.

image

从上图可以看出,需要保存的寄存器如下:

  • $gp global pointer
  • $fp frame pointer
  • $sp stack pointer
  • $s0–$s7 saved temporaries

调试下setjmp函数,发现还会保存下面两个寄存器:

  • $ra return address,函数返回地址,其实就是跳转的PC了,参考The jal Instruction
  • $fp, $s8, 保存的是这个寄存器,应该是s8用作fp了。

Jmpbuf

jmpbuf的布局如下:

    #define JB_SP  0    /* Stack pointer */
    #define JB_RA  11   /* Return address */
    #define JB_GP  1    /* Global pointer */
    #define JB_S0  3    /* S0-S7, Saved temporaries */
    #define JB_S1  4    /* S0-S7, Saved temporaries */
    #define JB_S2  5    /* S0-S7, Saved temporaries */
    #define JB_S3  6    /* S0-S7, Saved temporaries */
    #define JB_S4  7    /* S0-S7, Saved temporaries */
    #define JB_S5  8    /* S0-S7, Saved temporaries */
    #define JB_S6  9    /* S0-S7, Saved temporaries */
    #define JB_S7  10   /* S0-S7, Saved temporaries */
    #define JB_FP  2    /* FP/S8 Frame pointer */

选择将SP放在第一个位置,是为了方便更换:

        #elif defined(__mips__)
            /* https://github.com/ossrs/state-threads/issues/21 */
            #define MD_USE_BUILTIN_SETJMP
            #define MD_GET_SP(_t) *((long *)&((_t)->context[0].__jb[0]))

Return value

写两个函数返回0和1,可以发现返回值是寄存器$v0

由于$ra是函数的返回地址,所以返回都是跳转到$ra

        li $v0, 1       /* Set return value to 1 */
        jr $ra          /* Return to the saved return address */
@winlinvip
Copy link
Member Author

支持MIPS 64,参考 a03a3c8

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

No branches or pull requests

1 participant