ultra3 split
[binutils-gdb.git] / gdb / ultra3-xdep.c
1 /* Host-dependent code for GDB, for NYU Ultra3 running Sym1 OS.
2 Copyright (C) 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by David Wood (wood@nyu.edu) at New York University.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #define DEBUG
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "symtab.h"
26 #include "value.h"
27
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <signal.h>
31 #include <sys/ioctl.h>
32 #include <fcntl.h>
33
34 #include "gdbcore.h"
35
36 #include <sys/file.h>
37 #include <sys/stat.h>
38
39 /* Assumes support for AMD's Binary Compatibility Standard
40 for ptrace(). If you define ULTRA3, the ultra3 extensions to
41 ptrace() are used allowing the reading of more than one register
42 at a time.
43
44 This file assumes KERNEL_DEBUGGING is turned off. This means
45 that if the user/gdb tries to read gr64-gr95 or any of the
46 protected special registers we silently return -1 (see the
47 CANNOT_STORE/FETCH_REGISTER macros). */
48 #define ULTRA3
49
50 #if !defined (offsetof)
51 # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
52 #endif
53
54 extern int errno;
55 struct ptrace_user pt_struct;
56
57 /*
58 * Takes a register number as defined in tm.h via REGISTER_NAMES, and maps
59 * it to an offset in a struct ptrace_user defined by AMD's BCS.
60 * That is, it defines the mapping between gdb register numbers and items in
61 * a struct ptrace_user.
62 * A register protection scheme is set up here. If a register not
63 * available to the user is specified in 'regno', then an address that
64 * will cause ptrace() to fail is returned.
65 */
66 unsigned int
67 register_addr (regno,blockend)
68 unsigned int regno;
69 char *blockend;
70 {
71 if ((regno >= LR0_REGNUM) && (regno < LR0_REGNUM + 128)) {
72 return(offsetof(struct ptrace_user,pt_lr[regno-LR0_REGNUM]));
73 } else if ((regno >= GR96_REGNUM) && (regno < GR96_REGNUM + 32)) {
74 return(offsetof(struct ptrace_user,pt_gr[regno-GR96_REGNUM]));
75 } else {
76 switch (regno) {
77 case GR1_REGNUM: return(offsetof(struct ptrace_user,pt_gr1));
78 case CPS_REGNUM: return(offsetof(struct ptrace_user,pt_psr));
79 case NPC_REGNUM: return(offsetof(struct ptrace_user,pt_pc0));
80 case PC_REGNUM: return(offsetof(struct ptrace_user,pt_pc1));
81 case PC2_REGNUM: return(offsetof(struct ptrace_user,pt_pc2));
82 case IPC_REGNUM: return(offsetof(struct ptrace_user,pt_ipc));
83 case IPA_REGNUM: return(offsetof(struct ptrace_user,pt_ipa));
84 case IPB_REGNUM: return(offsetof(struct ptrace_user,pt_ipb));
85 case Q_REGNUM: return(offsetof(struct ptrace_user,pt_q));
86 case BP_REGNUM: return(offsetof(struct ptrace_user,pt_bp));
87 case FC_REGNUM: return(offsetof(struct ptrace_user,pt_fc));
88 default:
89 fprintf_filtered(stderr,"register_addr():Bad register %s (%d)\n",
90 reg_names[regno],regno);
91 return(0xffffffff); /* Should make ptrace() fail */
92 }
93 }
94 }
95
96
97 /* Assorted operating system circumventions */
98
99 #ifdef SYM1
100
101 /* FIXME: Kludge this for now. It really should be system call. */
102 int
103 getpagesize()
104 { return(8192); }
105
106 /* FIXME: Fake out the fcntl() call, which we don't have. */
107 fcntl(fd, cmd, arg)
108 int fd, cmd, arg;
109 {
110
111 switch (cmd) {
112 case F_GETFL: return(O_RDONLY); break;
113 default:
114 printf("Ultra3's fcntl() failing, cmd = %d.\n",cmd);
115 return(-1);
116 }
117 }
118
119
120 /*
121 * 4.2 Signal support, requires linking with libjobs.
122 */
123 static int _SigMask;
124 #define sigbit(s) (1L << ((s)-1))
125
126 init_SigMask()
127 {
128 /* Taken from the sym1 kernel in machdep.c:startup() */
129 _SigMask = sigbit (SIGTSTP) | sigbit (SIGTTOU) | sigbit (SIGTTIN) |
130 sigbit (SIGCHLD) | sigbit (SIGTINT);
131 }
132
133 sigmask(signo)
134 int signo;
135 {
136 return (1 << (signo-1));
137 }
138
139 sigsetmask(sigmask)
140 unsigned int sigmask;
141 {
142 int i, mask = 1;
143 int lastmask = _SigMask;
144
145 for (i=0 ; i<NSIG ; i++) {
146 if (sigmask & mask) {
147 if (!(_SigMask & mask)) {
148 sighold(i+1);
149 _SigMask |= mask;
150 }
151 } else if (_SigMask & mask) {
152 sigrelse(i+1);
153 _SigMask &= ~mask;
154 }
155 mask <<= 1;
156 }
157 return (lastmask);
158 }
159
160 sigblock(sigmask)
161 unsigned int sigmask;
162 {
163 int i, mask = 1;
164 int lastmask = _SigMask;
165
166 for (i=0 ; i<NSIG ; i++) {
167 if ((sigmask & mask) && !(_SigMask & mask)) {
168 sighold(i+1);
169 _SigMask |= mask;
170 }
171 mask <<= 1;
172 }
173 return (lastmask);
174 }
175 #endif /* SYM1 */
176
177
178 /* Initialization code for this module. */
179
180 _initialize_ultra3 ()
181 {
182 #ifdef SYM1
183 init_SigMask();
184 #endif
185 }