1/* $OpenBSD: _setjmp.S,v 1.3 2021/05/14 00:57:03 drahn Exp $ */ 2/* 3 * Copyright (c) 2020 Dale Rahn <drahn@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 19#include "DEFS.h" 20#include <machine/setjmp.h> 21 22ENTRY(_setjmp) 23 RETGUARD_SETUP(_setjmp, t6) 24 25 sd sp, (1 * 8)(a0) 26 /* Store the general purpose registers and ra */ 27 sd s0, (2 * 8)(a0) 28 sd s1, (3 * 8)(a0) 29 sd s2, (4 * 8)(a0) 30 sd s3, (5 * 8)(a0) 31 sd s4, (6 * 8)(a0) 32 sd s5, (7 * 8)(a0) 33 sd s6, (8 * 8)(a0) 34 sd s7, (9 * 8)(a0) 35 sd s8, (10 * 8)(a0) 36 sd s9, (11 * 8)(a0) 37 sd s10, (12 * 8)(a0) 38 sd s11, (13 * 8)(a0) 39 sd ra, (14 * 8)(a0) 40 41#ifndef _STANDALONE 42 /* Store the fp registers */ 43 fsd fs0, (15 * 8)(a0) 44 fsd fs1, (16 * 8)(a0) 45 fsd fs2, (17 * 8)(a0) 46 fsd fs3, (18 * 8)(a0) 47 fsd fs4, (19 * 8)(a0) 48 fsd fs5, (20 * 8)(a0) 49 fsd fs6, (21 * 8)(a0) 50 fsd fs7, (22 * 8)(a0) 51 fsd fs8, (23 * 8)(a0) 52 fsd fs9, (24 * 8)(a0) 53 fsd fs10, (25 * 8)(a0) 54 fsd fs11, (26 * 8)(a0) 55 frcsr t0 56 sd t0, (27 * 8)(a0) 57#endif 58 59 /* Return value */ 60 mv a0, x0 61 RETGUARD_CHECK(_setjmp, t6) 62 ret 63END_STRONG(_setjmp) 64 65ENTRY(_longjmp) 66 RETGUARD_SYMBOL(_longjmp) 67 RETGUARD_LOAD_RANDOM(_longjmp, t6) 68 69 /* Restore the stack pointer */ 70 ld t0, (1 * 8)(a0) 71 mv sp, t0 72 73 /* Store the general purpose registers and ra */ 74 ld s0, (2 * 8)(a0) 75 ld s1, (3 * 8)(a0) 76 ld s2, (4 * 8)(a0) 77 ld s3, (5 * 8)(a0) 78 ld s4, (6 * 8)(a0) 79 ld s5, (7 * 8)(a0) 80 ld s6, (8 * 8)(a0) 81 ld s7, (9 * 8)(a0) 82 ld s8, (10 * 8)(a0) 83 ld s9, (11 * 8)(a0) 84 ld s10, (12 * 8)(a0) 85 ld s11, (13 * 8)(a0) 86 ld ra, (14 * 8)(a0) 87 88#ifndef _STANDALONE 89 /* Store the fp registers */ 90 fld fs0, (15 * 8)(a0) 91 fld fs1, (16 * 8)(a0) 92 fld fs2, (17 * 8)(a0) 93 fld fs3, (18 * 8)(a0) 94 fld fs4, (19 * 8)(a0) 95 fld fs5, (20 * 8)(a0) 96 fld fs6, (21 * 8)(a0) 97 fld fs7, (22 * 8)(a0) 98 fld fs8, (23 * 8)(a0) 99 fld fs9, (24 * 8)(a0) 100 fld fs10, (25 * 8)(a0) 101 fld fs11, (26 * 8)(a0) 102 ld t0, (27 * 8)(a0) 103 fscsr t0 104#endif 105 106 /* Load the return value */ 107 li a0, 1 108 beqz a1, 1f 109 mv a0, a1 1101: 111 RETGUARD_CHECK(_longjmp, t6) 112 ret 113 114END_STRONG(_longjmp) 115