1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                             S I G T R A M P                              *
6  *                                                                          *
7  *                         Asm Implementation File                          *
8  *                                                                          *
9  *         Copyright (C) 2011-2015, Free Software Foundation, Inc.          *
10  *                                                                          *
11  * GNAT is free software;  you can  redistribute it  and/or modify it under *
12  * terms of the  GNU General Public License as published  by the Free Soft- *
13  * ware  Foundation;  either version 3,  or (at your option) any later ver- *
14  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16  * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
17  *                                                                          *
18  * As a special exception under Section 7 of GPL version 3, you are granted *
19  * additional permissions described in the GCC Runtime Library Exception,   *
20  * version 3.1, as published by the Free Software Foundation.               *
21  *                                                                          *
22  * In particular,  you can freely  distribute your programs  built with the *
23  * GNAT Pro compiler, including any required library run-time units,  using *
24  * any licensing terms  of your choosing.  See the AdaCore Software License *
25  * for full details.                                                        *
26  *                                                                          *
27  * GNAT was originally developed  by the GNAT team at  New York University. *
28  * Extensive contributions were provided by Ada Core Technologies Inc.      *
29  *                                                                          *
30  ****************************************************************************/
31 
32 /**************************************************
33  * VxWorks version of the __gnat_sigtramp service *
34  **************************************************/
35 
36 #include "sigtramp.h"
37 /* See sigtramp.h for a general explanation of functionality.  */
38 
39 #include <vxWorks.h>
40 #include <arch/../regs.h>
41 #ifndef __RTP__
42 #include <sigLib.h>
43 #else
44 #include <signal.h>
45 #include <regs.h>
46 
47 typedef struct mcontext
48   {
49     REG_SET     regs;
50   } mcontext_t;
51 
52 typedef struct ucontext
53   {
54     mcontext_t          uc_mcontext;    /* register set */
55     struct ucontext *   uc_link;        /* not used */
56     sigset_t            uc_sigmask;     /* set of signals blocked */
57     stack_t             uc_stack;       /* stack of context signaled */
58   } ucontext_t;
59 #endif
60 
61 /* ----------------------
62    -- General comments --
63    ----------------------
64 
65    Stubs are generated from toplevel asms and .cfi directives, much simpler
66    to use and check for correctness than manual encodings of CFI byte
67    sequences.  The general idea is to establish CFA as sigcontext->sc_pregs
68    (for DKM) and mcontext (for RTP) and state where to find the registers as
69    offsets from there.
70 
71    As of today, we support a stub providing CFI info for common
72    registers (GPRs, LR, ...). We might need variants with support for floating
73    point or altivec registers as well at some point.
74 
75    Checking which variant should apply and getting at sc_pregs / mcontext
76    is simpler to express in C (we can't use offsetof in toplevel asms and
77    hardcoding constants is not workable with the flurry of VxWorks variants),
78    so this is the choice for our toplevel interface.
79 
80    Note that the registers we "restore" here are those to which we have
81    direct access through the system sigcontext structure, which includes
82    only a partial set of the non-volatiles ABI-wise.  */
83 
84 /* -------------------------------------------
85    -- Prototypes for our internal asm stubs --
86    -------------------------------------------
87 
88    Eventhough our symbols will remain local, the prototype claims "extern"
89    and not "static" to prevent compiler complaints about a symbol used but
90    never defined.  */
91 
92 /* sigtramp stub providing CFI info for common registers.  */
93 
94 extern void __gnat_sigtramp_common
95 (int signo, void *siginfo, void *sigcontext,
96  __sigtramphandler_t * handler, void * sc_pregs);
97 
98 
99 /* -------------------------------------
100    -- Common interface implementation --
101    -------------------------------------
102 
103    We enforce optimization to minimize the overhead of the extra layer.  */
104 
105 void __gnat_sigtramp (int signo, void *si, void *sc,
106 		      __sigtramphandler_t * handler)
107      __attribute__((optimize(2)));
108 
__gnat_sigtramp(int signo,void * si,void * sc,__sigtramphandler_t * handler)109 void __gnat_sigtramp (int signo, void *si, void *sc,
110 		      __sigtramphandler_t * handler)
111 {
112 #ifdef __RTP__
113   mcontext_t *mcontext = &((ucontext_t *) sc)->uc_mcontext;
114 
115   /* Pass MCONTEXT in the fifth position so that the assembly code can find
116      it at the same stack location or in the same register as SC_PREGS.  */
117   __gnat_sigtramp_common (signo, si, mcontext, handler, mcontext);
118 #else
119   struct sigcontext * sctx = (struct sigcontext *) sc;
120 
121   __gnat_sigtramp_common (signo, si, sctx, handler, sctx->sc_pregs);
122 #endif
123 }
124 
125 /* Include the target specific bits.  */
126 #include "sigtramp-vxworks-target.inc"
127 
128 /* sigtramp stub for common registers.  */
129 
130 #define TRAMP_COMMON __gnat_sigtramp_common
131 
132 asm (SIGTRAMP_START(TRAMP_COMMON));
133 asm (CFI_DEF_CFA);
134 asm (CFI_COMMON_REGS);
135 asm (SIGTRAMP_BODY);
136 asm (SIGTRAMP_END(TRAMP_COMMON));
137 
138 
139