1/*        $NetBSD: __setjmp14.S,v 1.10 2024/04/20 14:09:40 skrll Exp $          */
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matthew Fredette.
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 "assym.h"
33
34#include <machine/asm.h>
35#include <machine/frame.h>
36#include <machine/psl.h>
37
38#if defined(LIBC_SCCS) && !defined(lint)
39          RCSID("$NetBSD: __setjmp14.S,v 1.10 2024/04/20 14:09:40 skrll Exp $")
40#endif /* LIBC_SCCS and not lint */
41
42/*
43 * C library -- setjmp, longjmp
44 *
45 *        longjmp(a,v)
46 * will generate a "return(v)" from
47 * the last call to
48 *        setjmp(a)
49 * by restoring registers from the stack,
50 * and a struct sigcontext, see <signal.h>
51 */
52
53ENTRY(__setjmp14,0)
54          /* Finish our stack frame. */
55          stw       %rp, HPPA_FRAME_CRP(%sp)
56          stw       %arg0, HPPA_FRAME_ARG(0)(%sp)
57
58          /* A sigcontext is at the beginning of our jmp_buf. */
59          stw       %r0, _SC_MASK13(%arg0)                  ; unused word (old style signal mask)
60          stw       %sp, _SC_REGS_SP(%arg0)                 ; sc.sc_sp = %sp
61          stw       %r0, _SC_REGS_AP(%arg0)                 ; sc.sc_ap = NULL
62          mfsp      %sr0, %r1
63          stw       %r1, _SC_REGS_PCSQH(%arg0)    ; sc.sc_pcsqh = %sr0
64          stw       %rp, _SC_REGS_PCOQH(%arg0)    ; sc.sc_pcoqh = %rp
65          stw       %r1, _SC_REGS_PCSQT(%arg0)    ; sc.sc_pcsqt = %sr0
66          ldo       4(%rp), %r1
67          stw       %r1, _SC_REGS_PCOQT(%arg0)    ; sc.sc_pcoqt = %rp + 4
68          ldil      L%PSW_MBS, %r1
69          ldo       R%PSW_MBS(%r1), %r1
70          stw       %r1, _SC_REGS_PS(%arg0)                 ; set sc.sc_ps
71
72          /* We store all callee-saved registers after the sigcontext. */
73          ldo       SIZEOF_SIGCONTEXT(%arg0), %r1
74          stwm      %r3, 4(%r1)
75          stwm      %r4, 4(%r1)
76          stwm      %r5, 4(%r1)
77          stwm      %r6, 4(%r1)
78          stwm      %r7, 4(%r1)
79          stwm      %r8, 4(%r1)
80          stwm      %r9, 4(%r1)
81          stwm      %r10, 4(%r1)
82          stwm      %r11, 4(%r1)
83          stwm      %r12, 4(%r1)
84          stwm      %r13, 4(%r1)
85          stwm      %r14, 4(%r1)
86          stwm      %r15, 4(%r1)
87          stwm      %r16, 4(%r1)
88          stwm      %r17, 4(%r1)
89          stwm      %r18, 4(%r1)
90
91          /*
92           * Start the stack frame for the calls we will make.
93           * The minimum frame is 48 bytes, but the stack must
94           * always be 64-byte aligned; we use the top 4 bytes
95           * to save our caller's %r3, and the following 12 bytes
96           * as the stack_t for our sigaltstack call.
97           * XXX - this assumes that sizeof(stack_t) <= 12
98           */
99          copy      %r3, %r1
100          copy      %sp, %r3
101          stwm      %r1, HPPA_FRAME_SIZE(%sp)
102
103          /* Get signal stack info. */
104          ldo       4(%r3), %arg1                 ; set up oss
105          bl        __sigaltstack14, %rp
106           copy     %r0, %arg0                    ; set up ss
107
108          /* Recover our jmp_buf and extract SS_ONSTACK */
109          ldw       HPPA_FRAME_ARG(0)(%r3), %arg0
110          ldw       12(%r3), %r1                  ; get ss_flags
111          ldi       1, %r20                       ; SS_ONSTACK
112          and       %r1, %r20, %r1
113          stw       %r1, 0(%arg0)                 ; sc.sc_onstack
114
115          /* Get the signal mask. */
116          ldo       _SC_MASK(%arg0), %arg2        ; oset = &sc.sc_mask
117          copy      %r0, %arg1                    ; set = NULL
118          bl        __sigprocmask14, %rp
119           copy     %r0, %arg0                    ; action = 0 <ignored>
120
121          /* Return 0. */
122          ldo       HPPA_FRAME_SIZE(%r3),%sp
123          ldwm      -HPPA_FRAME_SIZE(%sp),%r3
124          ldw       HPPA_FRAME_CRP(%sp), %rp
125          bv        %r0(%rp)
126           copy     %r0, %ret0
127EXIT(__setjmp14)
128
129          .end
130