]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ns32k-tdep.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / ns32k-tdep.c
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 }
28
29 sign_extend (value, bits)
30 {
31 value = value & ((1 << bits) - 1);
32 return (value & (1 << (bits-1))
33 ? value | (~((1 << bits) - 1))
34 : value);
35 }
36
37 void
38 flip_bytes (ptr, count)
39 char *ptr;
40 int count;
41 {
42 char tmp;
43
44 while (count > 0)
45 {
46 tmp = *ptr;
47 ptr[0] = ptr[count-1];
48 ptr[count-1] = tmp;
49 ptr++;
50 count -= 2;
51 }
52 }
53
54 /* Return the number of locals in the current frame given a pc
55 pointing to the enter instruction. This is used in the macro
56 FRAME_FIND_SAVED_REGS. */
57
58 int
59 ns32k_localcount (enter_pc)
60 CORE_ADDR enter_pc;
61 {
62 unsigned char localtype;
63 int localcount;
64
65 localtype = read_memory_integer (enter_pc+2, 1);
66 if ((localtype & 0x80) == 0)
67 localcount = localtype;
68 else if ((localtype & 0xc0) == 0x80)
69 localcount = (((localtype & 0x3f) << 8)
70 | (read_memory_integer (enter_pc+3, 1) & 0xff));
71 else
72 localcount = (((localtype & 0x3f) << 24)
73 | ((read_memory_integer (enter_pc+3, 1) & 0xff) << 16)
74 | ((read_memory_integer (enter_pc+4, 1) & 0xff) << 8 )
75 | (read_memory_integer (enter_pc+5, 1) & 0xff));
76 return localcount;
77 }
78
79
80 /* Nonzero if instruction at PC is a return instruction. */
81
82 static int
83 ns32k_about_to_return (pc)
84 CORE_ADDR pc;
85 {
86 return (read_memory_integer (pc, 1) == 0x12);
87 }
88
89
90 /*
91 * Get the address of the enter opcode for the function
92 * containing PC, if there is an enter for the function,
93 * and if the pc is between the enter and exit.
94 * Returns positive address if pc is between enter/exit,
95 * 1 if pc before enter or after exit, 0 otherwise.
96 */
97
98 CORE_ADDR
99 ns32k_get_enter_addr (pc)
100 CORE_ADDR pc;
101 {
102 CORE_ADDR enter_addr;
103 unsigned char op;
104
105 if (pc == 0)
106 return 0;
107
108 if (ns32k_about_to_return (pc))
109 return 1; /* after exit */
110
111 enter_addr = get_pc_function_start (pc);
112
113 if (pc == enter_addr)
114 return 1; /* before enter */
115
116 op = read_memory_integer (enter_addr, 1);
117
118 if (op != 0x82)
119 return 0; /* function has no enter/exit */
120
121 return enter_addr; /* pc is between enter and exit */
122 }