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__FBSDID("$FreeBSD$"); 265d031e33SJustin Hibbits 275d031e33SJustin Hibbits.text 285d031e33SJustin Hibbits 295d031e33SJustin Hibbits/* 305d031e33SJustin Hibbits * The PowerPC ABI spec requires the following save/restore functions to be 315d031e33SJustin Hibbits * provided: 325d031e33SJustin Hibbits * 335d031e33SJustin Hibbits * _savefpr_N 345d031e33SJustin Hibbits * _restfpr_N 355d031e33SJustin Hibbits * _restfpr_N_x 365d031e33SJustin Hibbits * _savegpr_N 375d031e33SJustin Hibbits * _restgpr_N 385d031e33SJustin Hibbits * _restgpr_N_x 395d031e33SJustin Hibbits * 405d031e33SJustin Hibbits * With N ranging from 14 to 31, to save the nonvolatile registers. 415d031e33SJustin Hibbits */ 425d031e33SJustin Hibbits 435d031e33SJustin Hibbits#define _CRTENTRY(name) \ 445d031e33SJustin Hibbits .text; \ 455d031e33SJustin Hibbits .globl name; \ 465d031e33SJustin Hibbits .type name,@function; \ 475d031e33SJustin Hibbits name: 485d031e33SJustin Hibbits 495d031e33SJustin Hibbits#define SAVEFPR(r) _CRTENTRY(__CONCAT(_savefpr_,r)) \ 505d031e33SJustin Hibbits stfd r,(-256 + r * 8)(11) 515d031e33SJustin Hibbits 525d031e33SJustin HibbitsSAVEFPR(14) 535d031e33SJustin HibbitsSAVEFPR(15) 545d031e33SJustin HibbitsSAVEFPR(16) 555d031e33SJustin HibbitsSAVEFPR(17) 565d031e33SJustin HibbitsSAVEFPR(18) 575d031e33SJustin HibbitsSAVEFPR(19) 585d031e33SJustin HibbitsSAVEFPR(20) 595d031e33SJustin HibbitsSAVEFPR(21) 605d031e33SJustin HibbitsSAVEFPR(22) 615d031e33SJustin HibbitsSAVEFPR(23) 625d031e33SJustin HibbitsSAVEFPR(24) 635d031e33SJustin HibbitsSAVEFPR(25) 645d031e33SJustin HibbitsSAVEFPR(26) 655d031e33SJustin HibbitsSAVEFPR(27) 665d031e33SJustin HibbitsSAVEFPR(28) 675d031e33SJustin HibbitsSAVEFPR(29) 685d031e33SJustin HibbitsSAVEFPR(30) 695d031e33SJustin HibbitsSAVEFPR(31) 705d031e33SJustin Hibbits blr 715d031e33SJustin Hibbits 725d031e33SJustin Hibbits#define RESTFPR(r) _CRTENTRY(__CONCAT(_restfpr_,r)) \ 735d031e33SJustin Hibbits lfd r,(-256 + r * 8)(11) 745d031e33SJustin Hibbits 755d031e33SJustin HibbitsRESTFPR(14) 765d031e33SJustin HibbitsRESTFPR(15) 775d031e33SJustin HibbitsRESTFPR(16) 785d031e33SJustin HibbitsRESTFPR(17) 795d031e33SJustin HibbitsRESTFPR(18) 805d031e33SJustin HibbitsRESTFPR(19) 815d031e33SJustin HibbitsRESTFPR(20) 825d031e33SJustin HibbitsRESTFPR(21) 835d031e33SJustin HibbitsRESTFPR(22) 845d031e33SJustin HibbitsRESTFPR(23) 855d031e33SJustin HibbitsRESTFPR(24) 865d031e33SJustin HibbitsRESTFPR(25) 875d031e33SJustin HibbitsRESTFPR(26) 885d031e33SJustin HibbitsRESTFPR(27) 895d031e33SJustin HibbitsRESTFPR(28) 905d031e33SJustin HibbitsRESTFPR(29) 915d031e33SJustin HibbitsRESTFPR(30) 925d031e33SJustin HibbitsRESTFPR(31) 935d031e33SJustin Hibbits blr 945d031e33SJustin Hibbits 955d031e33SJustin Hibbits#define SAVEGPR(r) _CRTENTRY(__CONCAT(_savegpr_,r)) \ 96*3dbb9df3SBrandon Bergren stw r,(-128 + r * 4)(11) 975d031e33SJustin Hibbits 985d031e33SJustin HibbitsSAVEGPR(14) 995d031e33SJustin HibbitsSAVEGPR(15) 1005d031e33SJustin HibbitsSAVEGPR(16) 1015d031e33SJustin HibbitsSAVEGPR(17) 1025d031e33SJustin HibbitsSAVEGPR(18) 1035d031e33SJustin HibbitsSAVEGPR(19) 1045d031e33SJustin HibbitsSAVEGPR(20) 1055d031e33SJustin HibbitsSAVEGPR(21) 1065d031e33SJustin HibbitsSAVEGPR(22) 1075d031e33SJustin HibbitsSAVEGPR(23) 1085d031e33SJustin HibbitsSAVEGPR(24) 1095d031e33SJustin HibbitsSAVEGPR(25) 1105d031e33SJustin HibbitsSAVEGPR(26) 1115d031e33SJustin HibbitsSAVEGPR(27) 1125d031e33SJustin HibbitsSAVEGPR(28) 1135d031e33SJustin HibbitsSAVEGPR(29) 1145d031e33SJustin HibbitsSAVEGPR(30) 1155d031e33SJustin HibbitsSAVEGPR(31) 1165d031e33SJustin Hibbits blr 1175d031e33SJustin Hibbits 1185d031e33SJustin Hibbits#define RESTGPR(r) _CRTENTRY(__CONCAT(_restgpr_,r)) \ 1195d031e33SJustin Hibbits lwz r,(-128 + r*4)(11) 1205d031e33SJustin Hibbits 1215d031e33SJustin HibbitsRESTGPR(14) 1225d031e33SJustin HibbitsRESTGPR(15) 1235d031e33SJustin HibbitsRESTGPR(16) 1245d031e33SJustin HibbitsRESTGPR(17) 1255d031e33SJustin HibbitsRESTGPR(18) 1265d031e33SJustin HibbitsRESTGPR(19) 1275d031e33SJustin HibbitsRESTGPR(20) 1285d031e33SJustin HibbitsRESTGPR(21) 1295d031e33SJustin HibbitsRESTGPR(22) 1305d031e33SJustin HibbitsRESTGPR(23) 1315d031e33SJustin HibbitsRESTGPR(24) 1325d031e33SJustin HibbitsRESTGPR(25) 1335d031e33SJustin HibbitsRESTGPR(26) 1345d031e33SJustin HibbitsRESTGPR(27) 1355d031e33SJustin HibbitsRESTGPR(28) 1365d031e33SJustin HibbitsRESTGPR(29) 1375d031e33SJustin HibbitsRESTGPR(30) 1385d031e33SJustin HibbitsRESTGPR(31) 1395d031e33SJustin Hibbits blr 1405d031e33SJustin Hibbits 1415d031e33SJustin Hibbits#define RESTFPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restfpr_,r),_x)) \ 1425d031e33SJustin Hibbits lfd r,(-256 + r * 8)(11) 1435d031e33SJustin Hibbits 1445d031e33SJustin HibbitsRESTFPR_X(14) 1455d031e33SJustin HibbitsRESTFPR_X(15) 1465d031e33SJustin HibbitsRESTFPR_X(16) 1475d031e33SJustin HibbitsRESTFPR_X(17) 1485d031e33SJustin HibbitsRESTFPR_X(18) 1495d031e33SJustin HibbitsRESTFPR_X(19) 1505d031e33SJustin HibbitsRESTFPR_X(20) 1515d031e33SJustin HibbitsRESTFPR_X(21) 1525d031e33SJustin HibbitsRESTFPR_X(22) 1535d031e33SJustin HibbitsRESTFPR_X(23) 1545d031e33SJustin HibbitsRESTFPR_X(24) 1555d031e33SJustin HibbitsRESTFPR_X(25) 1565d031e33SJustin HibbitsRESTFPR_X(26) 1575d031e33SJustin HibbitsRESTFPR_X(27) 1585d031e33SJustin HibbitsRESTFPR_X(28) 1595d031e33SJustin HibbitsRESTFPR_X(29) 1605d031e33SJustin HibbitsRESTFPR_X(30) 1615d031e33SJustin HibbitsRESTFPR_X(31) 1625d031e33SJustin Hibbits lwz 0,4(11) 1635d031e33SJustin Hibbits mtlr 0 1645d031e33SJustin Hibbits mr 1,11 1655d031e33SJustin Hibbits blr 1665d031e33SJustin Hibbits 1675d031e33SJustin Hibbits#define RESTGPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restgpr_,r),_x)) \ 1685d031e33SJustin Hibbits lwz r,(-128 + r * 4)(11) 1695d031e33SJustin Hibbits 1705d031e33SJustin HibbitsRESTGPR_X(14) 1715d031e33SJustin HibbitsRESTGPR_X(15) 1725d031e33SJustin HibbitsRESTGPR_X(16) 1735d031e33SJustin HibbitsRESTGPR_X(17) 1745d031e33SJustin HibbitsRESTGPR_X(18) 1755d031e33SJustin HibbitsRESTGPR_X(19) 1765d031e33SJustin HibbitsRESTGPR_X(20) 1775d031e33SJustin HibbitsRESTGPR_X(21) 1785d031e33SJustin HibbitsRESTGPR_X(22) 1795d031e33SJustin HibbitsRESTGPR_X(23) 1805d031e33SJustin HibbitsRESTGPR_X(24) 1815d031e33SJustin HibbitsRESTGPR_X(25) 1825d031e33SJustin HibbitsRESTGPR_X(26) 1835d031e33SJustin HibbitsRESTGPR_X(27) 1845d031e33SJustin HibbitsRESTGPR_X(28) 1855d031e33SJustin HibbitsRESTGPR_X(29) 1865d031e33SJustin HibbitsRESTGPR_X(30) 1875d031e33SJustin HibbitsRESTGPR_X(31) 1885d031e33SJustin Hibbits lwz 0,4(11) 1895d031e33SJustin Hibbits mtlr 0 1905d031e33SJustin Hibbits mr 1,11 1915d031e33SJustin Hibbits blr 192