15d031e33SJustin Hibbits/*- 25d031e33SJustin Hibbits * SPDX-License-Identifier: BSD-1-Clause 35d031e33SJustin Hibbits * 45d031e33SJustin Hibbits * Copyright 2019 Justin Hibbits 55d031e33SJustin Hibbits * 65d031e33SJustin Hibbits * Redistribution and use in source and binary forms, with or without 75d031e33SJustin Hibbits * modification, are permitted provided that the following conditions 85d031e33SJustin Hibbits * are met: 95d031e33SJustin Hibbits * 1. Redistributions of source code must retain the above copyright 105d031e33SJustin Hibbits * notice, this list of conditions and the following disclaimer. 115d031e33SJustin Hibbits * 125d031e33SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 135d031e33SJustin Hibbits * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 145d031e33SJustin Hibbits * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 155d031e33SJustin Hibbits * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 165d031e33SJustin Hibbits * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 175d031e33SJustin Hibbits * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 185d031e33SJustin Hibbits * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 195d031e33SJustin Hibbits * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 205d031e33SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 215d031e33SJustin Hibbits * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 225d031e33SJustin Hibbits */ 235d031e33SJustin Hibbits 245d031e33SJustin Hibbits#include <machine/asm.h> 255d031e33SJustin Hibbits.text 265d031e33SJustin Hibbits 275d031e33SJustin Hibbits/* 285d031e33SJustin Hibbits * The PowerPC ABI spec requires the following save/restore functions to be 295d031e33SJustin Hibbits * provided: 305d031e33SJustin Hibbits * 315d031e33SJustin Hibbits * _savefpr_N 325d031e33SJustin Hibbits * _restfpr_N 335d031e33SJustin Hibbits * _restfpr_N_x 345d031e33SJustin Hibbits * _savegpr_N 355d031e33SJustin Hibbits * _restgpr_N 365d031e33SJustin Hibbits * _restgpr_N_x 375d031e33SJustin Hibbits * 385d031e33SJustin Hibbits * With N ranging from 14 to 31, to save the nonvolatile registers. 395d031e33SJustin Hibbits */ 405d031e33SJustin Hibbits 415d031e33SJustin Hibbits#define _CRTENTRY(name) \ 425d031e33SJustin Hibbits .text; \ 435d031e33SJustin Hibbits .globl name; \ 445d031e33SJustin Hibbits .type name,@function; \ 455d031e33SJustin Hibbits name: 465d031e33SJustin Hibbits 475d031e33SJustin Hibbits#define SAVEFPR(r) _CRTENTRY(__CONCAT(_savefpr_,r)) \ 485d031e33SJustin Hibbits stfd r,(-256 + r * 8)(11) 495d031e33SJustin Hibbits 505d031e33SJustin HibbitsSAVEFPR(14) 515d031e33SJustin HibbitsSAVEFPR(15) 525d031e33SJustin HibbitsSAVEFPR(16) 535d031e33SJustin HibbitsSAVEFPR(17) 545d031e33SJustin HibbitsSAVEFPR(18) 555d031e33SJustin HibbitsSAVEFPR(19) 565d031e33SJustin HibbitsSAVEFPR(20) 575d031e33SJustin HibbitsSAVEFPR(21) 585d031e33SJustin HibbitsSAVEFPR(22) 595d031e33SJustin HibbitsSAVEFPR(23) 605d031e33SJustin HibbitsSAVEFPR(24) 615d031e33SJustin HibbitsSAVEFPR(25) 625d031e33SJustin HibbitsSAVEFPR(26) 635d031e33SJustin HibbitsSAVEFPR(27) 645d031e33SJustin HibbitsSAVEFPR(28) 655d031e33SJustin HibbitsSAVEFPR(29) 665d031e33SJustin HibbitsSAVEFPR(30) 675d031e33SJustin HibbitsSAVEFPR(31) 685d031e33SJustin Hibbits blr 695d031e33SJustin Hibbits 705d031e33SJustin Hibbits#define RESTFPR(r) _CRTENTRY(__CONCAT(_restfpr_,r)) \ 715d031e33SJustin Hibbits lfd r,(-256 + r * 8)(11) 725d031e33SJustin Hibbits 735d031e33SJustin HibbitsRESTFPR(14) 745d031e33SJustin HibbitsRESTFPR(15) 755d031e33SJustin HibbitsRESTFPR(16) 765d031e33SJustin HibbitsRESTFPR(17) 775d031e33SJustin HibbitsRESTFPR(18) 785d031e33SJustin HibbitsRESTFPR(19) 795d031e33SJustin HibbitsRESTFPR(20) 805d031e33SJustin HibbitsRESTFPR(21) 815d031e33SJustin HibbitsRESTFPR(22) 825d031e33SJustin HibbitsRESTFPR(23) 835d031e33SJustin HibbitsRESTFPR(24) 845d031e33SJustin HibbitsRESTFPR(25) 855d031e33SJustin HibbitsRESTFPR(26) 865d031e33SJustin HibbitsRESTFPR(27) 875d031e33SJustin HibbitsRESTFPR(28) 885d031e33SJustin HibbitsRESTFPR(29) 895d031e33SJustin HibbitsRESTFPR(30) 905d031e33SJustin HibbitsRESTFPR(31) 915d031e33SJustin Hibbits blr 925d031e33SJustin Hibbits 935d031e33SJustin Hibbits#define SAVEGPR(r) _CRTENTRY(__CONCAT(_savegpr_,r)) \ 94*3dbb9df3SBrandon Bergren stw r,(-128 + r * 4)(11) 955d031e33SJustin Hibbits 965d031e33SJustin HibbitsSAVEGPR(14) 975d031e33SJustin HibbitsSAVEGPR(15) 985d031e33SJustin HibbitsSAVEGPR(16) 995d031e33SJustin HibbitsSAVEGPR(17) 1005d031e33SJustin HibbitsSAVEGPR(18) 1015d031e33SJustin HibbitsSAVEGPR(19) 1025d031e33SJustin HibbitsSAVEGPR(20) 1035d031e33SJustin HibbitsSAVEGPR(21) 1045d031e33SJustin HibbitsSAVEGPR(22) 1055d031e33SJustin HibbitsSAVEGPR(23) 1065d031e33SJustin HibbitsSAVEGPR(24) 1075d031e33SJustin HibbitsSAVEGPR(25) 1085d031e33SJustin HibbitsSAVEGPR(26) 1095d031e33SJustin HibbitsSAVEGPR(27) 1105d031e33SJustin HibbitsSAVEGPR(28) 1115d031e33SJustin HibbitsSAVEGPR(29) 1125d031e33SJustin HibbitsSAVEGPR(30) 1135d031e33SJustin HibbitsSAVEGPR(31) 1145d031e33SJustin Hibbits blr 1155d031e33SJustin Hibbits 1165d031e33SJustin Hibbits#define RESTGPR(r) _CRTENTRY(__CONCAT(_restgpr_,r)) \ 1175d031e33SJustin Hibbits lwz r,(-128 + r*4)(11) 1185d031e33SJustin Hibbits 1195d031e33SJustin HibbitsRESTGPR(14) 1205d031e33SJustin HibbitsRESTGPR(15) 1215d031e33SJustin HibbitsRESTGPR(16) 1225d031e33SJustin HibbitsRESTGPR(17) 1235d031e33SJustin HibbitsRESTGPR(18) 1245d031e33SJustin HibbitsRESTGPR(19) 1255d031e33SJustin HibbitsRESTGPR(20) 1265d031e33SJustin HibbitsRESTGPR(21) 1275d031e33SJustin HibbitsRESTGPR(22) 1285d031e33SJustin HibbitsRESTGPR(23) 1295d031e33SJustin HibbitsRESTGPR(24) 1305d031e33SJustin HibbitsRESTGPR(25) 1315d031e33SJustin HibbitsRESTGPR(26) 1325d031e33SJustin HibbitsRESTGPR(27) 1335d031e33SJustin HibbitsRESTGPR(28) 1345d031e33SJustin HibbitsRESTGPR(29) 1355d031e33SJustin HibbitsRESTGPR(30) 1365d031e33SJustin HibbitsRESTGPR(31) 1375d031e33SJustin Hibbits blr 1385d031e33SJustin Hibbits 1395d031e33SJustin Hibbits#define RESTFPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restfpr_,r),_x)) \ 1405d031e33SJustin Hibbits lfd r,(-256 + r * 8)(11) 1415d031e33SJustin Hibbits 1425d031e33SJustin HibbitsRESTFPR_X(14) 1435d031e33SJustin HibbitsRESTFPR_X(15) 1445d031e33SJustin HibbitsRESTFPR_X(16) 1455d031e33SJustin HibbitsRESTFPR_X(17) 1465d031e33SJustin HibbitsRESTFPR_X(18) 1475d031e33SJustin HibbitsRESTFPR_X(19) 1485d031e33SJustin HibbitsRESTFPR_X(20) 1495d031e33SJustin HibbitsRESTFPR_X(21) 1505d031e33SJustin HibbitsRESTFPR_X(22) 1515d031e33SJustin HibbitsRESTFPR_X(23) 1525d031e33SJustin HibbitsRESTFPR_X(24) 1535d031e33SJustin HibbitsRESTFPR_X(25) 1545d031e33SJustin HibbitsRESTFPR_X(26) 1555d031e33SJustin HibbitsRESTFPR_X(27) 1565d031e33SJustin HibbitsRESTFPR_X(28) 1575d031e33SJustin HibbitsRESTFPR_X(29) 1585d031e33SJustin HibbitsRESTFPR_X(30) 1595d031e33SJustin HibbitsRESTFPR_X(31) 1605d031e33SJustin Hibbits lwz 0,4(11) 1615d031e33SJustin Hibbits mtlr 0 1625d031e33SJustin Hibbits mr 1,11 1635d031e33SJustin Hibbits blr 1645d031e33SJustin Hibbits 1655d031e33SJustin Hibbits#define RESTGPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restgpr_,r),_x)) \ 1665d031e33SJustin Hibbits lwz r,(-128 + r * 4)(11) 1675d031e33SJustin Hibbits 1685d031e33SJustin HibbitsRESTGPR_X(14) 1695d031e33SJustin HibbitsRESTGPR_X(15) 1705d031e33SJustin HibbitsRESTGPR_X(16) 1715d031e33SJustin HibbitsRESTGPR_X(17) 1725d031e33SJustin HibbitsRESTGPR_X(18) 1735d031e33SJustin HibbitsRESTGPR_X(19) 1745d031e33SJustin HibbitsRESTGPR_X(20) 1755d031e33SJustin HibbitsRESTGPR_X(21) 1765d031e33SJustin HibbitsRESTGPR_X(22) 1775d031e33SJustin HibbitsRESTGPR_X(23) 1785d031e33SJustin HibbitsRESTGPR_X(24) 1795d031e33SJustin HibbitsRESTGPR_X(25) 1805d031e33SJustin HibbitsRESTGPR_X(26) 1815d031e33SJustin HibbitsRESTGPR_X(27) 1825d031e33SJustin HibbitsRESTGPR_X(28) 1835d031e33SJustin HibbitsRESTGPR_X(29) 1845d031e33SJustin HibbitsRESTGPR_X(30) 1855d031e33SJustin HibbitsRESTGPR_X(31) 1865d031e33SJustin Hibbits lwz 0,4(11) 1875d031e33SJustin Hibbits mtlr 0 1885d031e33SJustin Hibbits mr 1,11 1895d031e33SJustin Hibbits blr 190