* alpha-tdep.h (gdbarch_tdep): Add jb_pc and jb_elt_size members.
[external/binutils.git] / gdb / alpha-linux-tdep.c
1 /* Target-dependent code for GNU/Linux on Alpha.
2    Copyright 2002 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include "gdbcore.h"
23 #include "value.h"
24
25 #include "alpha-tdep.h"
26
27 /* Under GNU/Linux, signal handler invocations can be identified by the
28    designated code sequence that is used to return from a signal
29    handler.  In particular, the return address of a signal handler
30    points to the following sequence (the first instruction is quadword
31    aligned):
32   
33    bis $30,$30,$16
34    addq $31,0x67,$0
35    call_pal callsys 
36       
37    Each instruction has a unique encoding, so we simply attempt to
38    match the instruction the pc is pointing to with any of the above
39    instructions.  If there is a hit, we know the offset to the start
40    of the designated sequence and can then check whether we really are
41    executing in a designated sequence.  If not, -1 is returned,
42    otherwise the offset from the start of the desingated sequence is
43    returned.
44    
45    There is a slight chance of false hits: code could jump into the
46    middle of the designated sequence, in which case there is no
47    guarantee that we are in the middle of a sigreturn syscall.  Don't
48    think this will be a problem in praxis, though.  */
49 LONGEST
50 alpha_linux_sigtramp_offset (CORE_ADDR pc)
51 {
52   unsigned int i[3], w;
53   long off;
54
55   if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
56     return -1;
57
58   off = -1;
59   switch (w)
60     {
61     case 0x47de0410:
62       off = 0;
63       break;                    /* bis $30,$30,$16 */
64     case 0x43ecf400:
65       off = 4;
66       break;                    /* addq $31,0x67,$0 */
67     case 0x00000083:
68       off = 8;
69       break;                    /* call_pal callsys */
70     default:
71       return -1;
72     }
73   pc -= off;
74   if (pc & 0x7)
75     {
76       /* designated sequence is not quadword aligned */
77       return -1;
78     }
79   if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
80     return -1;
81
82   if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
83     return off;
84
85   return -1;
86 }
87
88 static int
89 alpha_linux_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
90 {
91   return (alpha_linux_sigtramp_offset (pc) >= 0);
92 }
93
94 static void
95 alpha_linux_init_abi (struct gdbarch_info info,
96                       struct gdbarch *gdbarch)
97 {
98   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
99
100   set_gdbarch_pc_in_sigtramp (gdbarch, alpha_linux_pc_in_sigtramp);
101
102   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
103
104   tdep->jb_pc = 2;
105   tdep->jb_elt_size = 8;
106 }
107
108 void
109 _initialize_alpha_linux_tdep (void)
110 {
111   alpha_gdbarch_register_os_abi (ALPHA_ABI_LINUX, alpha_linux_init_abi);
112 }