Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Print NS 32000 instructions for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1991, 1992, 1994, 1995 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "defs.h" | |
22 | ||
23 | void | |
24 | _initialize_ns32k_tdep () | |
25 | { | |
26 | tm_print_insn = print_insn_ns32k; | |
27 | } | |
b83266a0 SS |
28 | |
29 | /* Advance PC across any function entry prologue instructions | |
30 | to reach some "real" code. */ | |
31 | ||
32 | CORE_ADDR | |
33 | merlin_skip_prologue (pc) | |
34 | CORE_ADDR pc; | |
35 | { | |
36 | register int op = read_memory_integer (pc, 1); | |
37 | if (op == 0x82) | |
38 | { | |
39 | op = read_memory_integer (pc+2,1); | |
40 | if ((op & 0x80) == 0) | |
41 | pc += 3; | |
42 | else if ((op & 0xc0) == 0x80) | |
43 | pc += 4; | |
44 | else pc += 6; | |
45 | } | |
46 | return pc; | |
47 | } | |
48 | ||
49 | CORE_ADDR | |
50 | umax_skip_prologue (pc) | |
51 | CORE_ADDR pc; | |
52 | { | |
53 | register unsigned char op = read_memory_integer (pc, 1); | |
54 | if (op == 0x82) | |
55 | { | |
56 | op = read_memory_integer (pc+2,1); | |
57 | if ((op & 0x80) == 0) | |
58 | pc += 3; | |
59 | else if ((op & 0xc0) == 0x80) | |
60 | pc += 4; | |
61 | else | |
62 | pc += 6; | |
63 | } | |
64 | return pc; | |
65 | } | |
66 | ||
67 | ||
c906108c SS |
68 | |
69 | sign_extend (value, bits) | |
70 | { | |
71 | value = value & ((1 << bits) - 1); | |
72 | return (value & (1 << (bits-1)) | |
73 | ? value | (~((1 << bits) - 1)) | |
74 | : value); | |
75 | } | |
76 | ||
77 | void | |
78 | flip_bytes (ptr, count) | |
79 | char *ptr; | |
80 | int count; | |
81 | { | |
82 | char tmp; | |
83 | ||
84 | while (count > 0) | |
85 | { | |
86 | tmp = *ptr; | |
87 | ptr[0] = ptr[count-1]; | |
88 | ptr[count-1] = tmp; | |
89 | ptr++; | |
90 | count -= 2; | |
91 | } | |
92 | } | |
93 | ||
94 | /* Return the number of locals in the current frame given a pc | |
95 | pointing to the enter instruction. This is used in the macro | |
96 | FRAME_FIND_SAVED_REGS. */ | |
97 | ||
98 | int | |
99 | ns32k_localcount (enter_pc) | |
100 | CORE_ADDR enter_pc; | |
101 | { | |
102 | unsigned char localtype; | |
103 | int localcount; | |
104 | ||
105 | localtype = read_memory_integer (enter_pc+2, 1); | |
106 | if ((localtype & 0x80) == 0) | |
107 | localcount = localtype; | |
108 | else if ((localtype & 0xc0) == 0x80) | |
109 | localcount = (((localtype & 0x3f) << 8) | |
110 | | (read_memory_integer (enter_pc+3, 1) & 0xff)); | |
111 | else | |
112 | localcount = (((localtype & 0x3f) << 24) | |
113 | | ((read_memory_integer (enter_pc+3, 1) & 0xff) << 16) | |
114 | | ((read_memory_integer (enter_pc+4, 1) & 0xff) << 8 ) | |
115 | | (read_memory_integer (enter_pc+5, 1) & 0xff)); | |
116 | return localcount; | |
117 | } | |
118 | ||
119 | ||
120 | /* Nonzero if instruction at PC is a return instruction. */ | |
121 | ||
122 | static int | |
123 | ns32k_about_to_return (pc) | |
124 | CORE_ADDR pc; | |
125 | { | |
126 | return (read_memory_integer (pc, 1) == 0x12); | |
127 | } | |
128 | ||
129 | ||
130 | /* | |
131 | * Get the address of the enter opcode for the function | |
132 | * containing PC, if there is an enter for the function, | |
133 | * and if the pc is between the enter and exit. | |
134 | * Returns positive address if pc is between enter/exit, | |
135 | * 1 if pc before enter or after exit, 0 otherwise. | |
136 | */ | |
137 | ||
138 | CORE_ADDR | |
139 | ns32k_get_enter_addr (pc) | |
140 | CORE_ADDR pc; | |
141 | { | |
142 | CORE_ADDR enter_addr; | |
143 | unsigned char op; | |
144 | ||
145 | if (pc == 0) | |
146 | return 0; | |
147 | ||
148 | if (ns32k_about_to_return (pc)) | |
149 | return 1; /* after exit */ | |
150 | ||
151 | enter_addr = get_pc_function_start (pc); | |
152 | ||
153 | if (pc == enter_addr) | |
154 | return 1; /* before enter */ | |
155 | ||
156 | op = read_memory_integer (enter_addr, 1); | |
157 | ||
158 | if (op != 0x82) | |
159 | return 0; /* function has no enter/exit */ | |
160 | ||
161 | return enter_addr; /* pc is between enter and exit */ | |
162 | } |