1/*.$NetBSD: setjmp.S,v 1.4 2021/10/07 06:44:18 skrll Exp $.*/ 2 3/*- 4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <machine/asm.h> 33#include "assym.h" 34 35/* 36 * C library -- setjmp, longjmp 37 * 38 * longjmp(a,v) 39 * will generate a "return(v)" from the last call to 40 * setjmp(a) 41 * by restoring registers from the stack. 42 * The previous signal state is restored. 43 */ 44 45 .section .rodata.cst8,"aM",@progbits,8 46 .align 3 47.L_MAGIC: 48 .xword _JB_MAGIC_AARCH64_SETJMP 49 50ENTRY(__setjmp14) 51 adrp x7, .L_MAGIC 52 ldr x7, [x7, #:lo12:.L_MAGIC] 53 54 mov x3, sp 55 stp x7, x3, [x0, #_JB_MAGIC] 56 57 stp x19, x20, [x0, #_JB_X19] 58 stp x21, x22, [x0, #_JB_X21] 59 stp x23, x24, [x0, #_JB_X23] 60 stp x25, x26, [x0, #_JB_X25] 61 stp x27, x28, [x0, #_JB_X27] 62 stp x29, x30, [x0, #_JB_X29] 63 64 stp d8, d9, [x0, #_JB_D8] 65 stp d10, d11, [x0, #_JB_D10] 66 stp d12, d13, [x0, #_JB_D12] 67 stp d14, d15, [x0, #_JB_D14] 68 69 /* Get the signal mask. */ 70 add x2, x0, #_JB_SIGMASK 71 mov x1, #0 72 mov x0, #0 73 74 stp x29, x30, [sp, #-16]! 75 mov x29, sp 76 bl _C_LABEL(__sigprocmask14) 77 ldp x29, x30, [sp], #16 78 79 mov x0, xzr 80 ret 81END(__setjmp14) 82 83ENTRY(__longjmp14) 84 adrp x7, .L_MAGIC 85 ldr x7, [x7, #:lo12:.L_MAGIC] 86 ldp x2, x3, [x0, #_JB_MAGIC] 87 cmp x2, x7 88 b.ne .Lbotch 89 90 ldp x4, x5, [x0, #_JB_X29] 91 cbz x3, .Lbotch 92 cbz x5, .Lbotch 93 94 ldp x19, x20, [x0, #_JB_X19] 95 ldp x21, x22, [x0, #_JB_X21] 96 ldp x23, x24, [x0, #_JB_X23] 97 ldp x25, x26, [x0, #_JB_X25] 98 ldp x27, x28, [x0, #_JB_X27] 99 100 ldp d8, d9, [x0, #_JB_D8] 101 ldp d10, d11, [x0, #_JB_D10] 102 ldp d12, d13, [x0, #_JB_D12] 103 ldp d14, d15, [x0, #_JB_D14] 104 105 sub sp, x3, #32 106 107 stp x4, x5, [sp, #16] 108 str x1, [sp, #8] 109 add x29, sp, #16 110 111 mov x2, #0 112 add x1, x0, #_JB_SIGMASK 113 mov x0, #3 /* SIG_SETMASK */ 114 bl _C_LABEL(__sigprocmask14) 115 116 ldp x29, x30, [sp, #16] 117 ldr x1, [sp, #8] 118 add sp, sp, #32 119 120 cmp x1, #0 121 csinc x0, x1, xzr, ne 122 ret 123 124 /* validation failed, die die die. */ 125.Lbotch: 126 bl _C_LABEL(longjmperror) 127 bl _C_LABEL(abort) 1281: b 1b /* Cannot get here */ 129END(__longjmp14) 130