Austin Schuh | dace2a6 | 2020-08-18 10:56:48 -0700 | [diff] [blame] | 1 | dnl ARM32 calling conventions checking. |
| 2 | |
| 3 | dnl Copyright 2000, 2003, 2004, 2006, 2007, 2010, 2013, 2016 Free Software |
| 4 | dnl Foundation, Inc. |
| 5 | |
| 6 | dnl This file is part of the GNU MP Library test suite. |
| 7 | |
| 8 | dnl The GNU MP Library test suite is free software; you can redistribute it |
| 9 | dnl and/or modify it under the terms of the GNU General Public License as |
| 10 | dnl published by the Free Software Foundation; either version 3 of the |
| 11 | dnl License, or (at your option) any later version. |
| 12 | |
| 13 | dnl The GNU MP Library test suite is distributed in the hope that it will be |
| 14 | dnl useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 16 | dnl Public License for more details. |
| 17 | |
| 18 | dnl You should have received a copy of the GNU General Public License along |
| 19 | dnl with the GNU MP Library test suite. If not, see |
| 20 | dnl https://www.gnu.org/licenses/. |
| 21 | |
| 22 | |
| 23 | dnl The current version of the code attempts to keep the call/return |
| 24 | dnl prediction stack valid, but matching calls and returns. |
| 25 | |
| 26 | include(`../config.m4') |
| 27 | |
| 28 | |
| 29 | C int calling_conventions (...); |
| 30 | C |
| 31 | C The global variable "calling_conventions_function" is the function to |
| 32 | C call, with the arguments as passed here. |
| 33 | |
| 34 | define(`WANT_CALLEE_SAVES', eval(4*0)) |
| 35 | define(`SAVE_CALLEE_SAVES', eval(4*8)) |
| 36 | define(`RETADDR', eval(4*16)) |
| 37 | define(`GOT_CALLEE_SAVES', eval(4*17)) |
| 38 | define(`JUNK_PARAMS', eval(4*25)) |
| 39 | |
| 40 | TEXT |
| 41 | ALIGN(32) |
| 42 | PROLOGUE(calling_conventions) |
| 43 | LEA( r12, calling_conventions_values) |
| 44 | |
| 45 | C Preserve callee-saves registers, including the link register r14 |
| 46 | add r12, r12, #SAVE_CALLEE_SAVES |
| 47 | stm r12, {r4-r11,r14} |
| 48 | sub r12, r12, #SAVE_CALLEE_SAVES |
| 49 | |
| 50 | C Put chosen junk into callee-saves registers |
| 51 | add r12, r12, #WANT_CALLEE_SAVES |
| 52 | ldm r12, {r4-r11} |
| 53 | sub r12, r12, #WANT_CALLEE_SAVES |
| 54 | |
| 55 | C No callee-saves registers on arm except r12 and parameter registers |
| 56 | C |
| 57 | |
| 58 | C Make the actual call |
| 59 | LEA( r12, calling_conventions_function) |
| 60 | ldr r12, [r12] |
| 61 | mov r14, pc |
| 62 | return r12 |
| 63 | |
| 64 | LEA( r12, calling_conventions_values) |
| 65 | |
| 66 | C Save callee-saves registers after call |
| 67 | add r12, r12, #GOT_CALLEE_SAVES |
| 68 | stm r12, {r4-r11} |
| 69 | sub r12, r12, #GOT_CALLEE_SAVES |
| 70 | |
| 71 | C Restore callee-saves registers, including the link register r14 |
| 72 | add r12, r12, #SAVE_CALLEE_SAVES |
| 73 | ldm r12, {r4-r11,r14} |
| 74 | sub r12, r12, #SAVE_CALLEE_SAVES |
| 75 | |
| 76 | C Overwrite parameter registers. Note that we overwrite r1, which |
| 77 | C could hold one half of a 64-bit return value, since we don't use that |
| 78 | C in GMP. |
| 79 | add r12, r12, #JUNK_PARAMS |
| 80 | ldm r12, {r1-r3} |
| 81 | |
| 82 | return r14 |
| 83 | EPILOGUE() |