* nlm/alpha.c (strtol): Removed, it is provided by NetWare C library.
[binutils-gdb.git] / gdb / nlm / alpha.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <time.h>
5 #include <errno.h>
6
7 #include <nwtypes.h>
8 #include <nwdfs.h>
9 #include <nwconio.h>
10 #include <nwadv.h>
11 #include <nwdbgapi.h>
12 #include <nwthread.h>
13 #include <aio.h>
14
15 #include "alpha.h"
16
17 extern char *mem2hex (void *mem, char *buf, int count, int may_fault);
18 extern char *hex2mem (char *buf, void *mem, int count, int may_fault);
19 extern int computeSignal (int exceptionVector);
20
21 /* Get the registers out of the frame information. */
22
23 void
24 frame_to_registers (frame, regs)
25 struct StackFrame *frame;
26 char *regs;
27 {
28 mem2hex (&frame->ExceptionPC, &regs[PC_REGNUM * 8 * 2], 8 * 1, 0);
29
30 mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET], &regs[V0_REGNUM * 8 * 2], 8 * 64, 0);
31 }
32
33 /* Put the registers back into the frame information. */
34
35 void
36 registers_to_frame (regs, frame)
37 char *regs;
38 struct StackFrame *frame;
39 {
40 hex2mem (&regs[PC_REGNUM * 8 * 2], &frame->ExceptionPC, 8 * 1, 0);
41
42 hex2mem (&regs[V0_REGNUM * 8 * 2], &frame->ExceptionRegs[SF_IREG_OFFSET], 8 * 64, 0);
43 }
44
45 union inst
46 {
47 LONG l;
48
49 struct
50 {
51 union
52 {
53 struct
54 {
55 unsigned hint : 16;
56 unsigned rb : 5;
57 unsigned ra : 5;
58 unsigned opcode : 6;
59 } jump;
60 struct
61 {
62 signed disp : 21;
63 unsigned ra : 5;
64 unsigned opcode : 6;
65 } branch;
66 } variant;
67 } inst;
68 };
69
70 static LONG saved_inst;
71 static LONG *saved_inst_pc = 0;
72 static LONG saved_target_inst;
73 static LONG *saved_target_inst_pc = 0;
74
75 void
76 set_step_traps (frame)
77 struct StackFrame *frame;
78 {
79 union inst inst;
80 LONG *target;
81 int opcode;
82 int ra, rb;
83 LONG *pc = (LONG *)frame->ExceptionPC;
84
85 inst.l = *pc++;
86
87 opcode = inst.inst.variant.branch.opcode;
88
89 if ((opcode & 0x30) == 0x30) /* A branch of some sort */
90 target = inst.inst.variant.branch.disp + pc;
91 else if (opcode == 0x1a) /* jmp, ret, etc... */
92 target = (LONG *)(frame->ExceptionRegs[SF_IREG_OFFSET
93 + inst.inst.variant.jump.rb].lo
94 & ~3);
95 else
96 target = pc;
97
98 saved_inst = *pc;
99 *pc = 0x80; /* call_pal bpt */
100 saved_inst_pc = pc;
101
102 if (target != pc)
103 {
104 saved_target_inst = *target;
105 *target = 0x80; /* call_pal bpt */
106 saved_target_inst_pc = target;
107 }
108 }
109
110 /* Remove step breakpoints. Returns non-zero if pc was at a step breakpoint,
111 zero otherwise. This routine works even if there were no step breakpoints
112 set. */
113
114 int
115 clear_step_traps (frame)
116 struct StackFrame *frame;
117 {
118 int retcode;
119 LONG *pc = (LONG *)frame->ExceptionPC;
120
121 if (saved_inst_pc == pc || saved_target_inst_pc == pc)
122 retcode = 1;
123 else
124 retcode = 0;
125
126 if (saved_inst_pc)
127 {
128 *saved_inst_pc = saved_inst;
129 saved_inst_pc = 0;
130 }
131
132 if (saved_target_inst_pc)
133 {
134 *saved_target_inst_pc = saved_target_inst;
135 saved_target_inst_pc = 0;
136 }
137
138 return retcode;
139 }
140
141 void
142 do_status (ptr, frame)
143 char *ptr;
144 struct StackFrame *frame;
145 {
146 int sigval;
147
148 sigval = computeSignal (frame->ExceptionNumber);
149
150 sprintf (ptr, "T%02x", sigval);
151 ptr += 3;
152
153 sprintf (ptr, "%02x:", PC_REGNUM);
154 ptr = mem2hex (&frame->ExceptionPC, ptr + 3, 8, 0);
155 *ptr++ = ';';
156
157 sprintf (ptr, "%02x:", SP_REGNUM);
158 ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + SP_REGNUM], ptr + 3, 8, 0);
159 *ptr++ = ';';
160
161 sprintf (ptr, "%02x:", RA_REGNUM);
162 ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + RA_REGNUM], ptr + 3, 8, 0);
163 *ptr++ = ';';
164
165 sprintf (ptr, "%02x:", FP_REGNUM);
166 ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + FP_REGNUM], ptr + 3, 8, 0);
167 *ptr++ = ';';
168
169 *ptr = '\000';
170 }
171
172 /* This section provides stubs and equivalent interfaces for all functions that
173 the debugger stub needs, but aren't yet implemented (such as the AIO nlm). */
174
175 #include <nwtypes.h>
176 #include <errno.h>
177 #include <stdio.h>
178 #include <aio.h>
179
180 #define CONST const
181
182 #define com1Rbr 0x3f8 /* Receiver Buffer - Read */
183 #define com1Thr 0x3f8 /* Transmitter Holding - Write */
184 #define com1Ier 0x3f9 /* Interrupt Enable */
185 #define com1Iir 0x3fa /* Interrupt Identification */
186 #define com1Lcr 0x3fb /* Line Control */
187 #define com1Mcr 0x3fc /* Modem Control */
188 #define com1Lsr 0x3fd /* Line Status */
189 #define com1Msr 0x3fe /* Modem Status */
190 #define com1Scr 0x3ff /* Scratch */
191 #define com1Dll 0x3f8 /* Divisor Latch - lsb */
192 #define com1Dlm 0x3f9 /* Divisor Latch - msb */
193
194 #define com2Rbr 0x2f8 /* Receiver Buffer - Read */
195 #define com2Thr 0x2f8 /* Transmitter Holding - Write */
196 #define com2Ier 0x2f9 /* Interrupt Enable */
197 #define com2Iir 0x2fa /* Interrupt Identification */
198 #define com2Lcr 0x2fb /* Line Control */
199 #define com2Mcr 0x2fc /* Modem Control */
200 #define com2Lsr 0x2fd /* Line Status */
201 #define com2Msr 0x2fe /* Modem Status */
202 #define com2Scr 0x2ff /* Scratch */
203 #define com2Dll 0x2f8 /* Divisor Latch - lsb */
204 #define com2Dlm 0x2f9 /* Divisor Latch - msb */
205
206 #define COM1 0x8000
207 #define COM2 0x9000
208
209 static ULONG
210 uart_getchar (void)
211 {
212 while ((inVti(com1Lsr) & 1) == 0);
213
214 return inVti (com1Rbr);
215 }
216
217 static void
218 uart_putchar (char c)
219 {
220 while ((inVti(com1Lsr) & 0x20) == 0);
221
222 outVti (com1Thr,c);
223 }
224
225 static int
226 uart_init (int baud)
227 {
228 int i;
229 int baudconst;
230
231 baudconst = 115200 / baud;
232
233 outVti (com1Lcr, 0x87);
234 outVti (com1Dlm, 0);
235 outVti (com1Dll, baudconst);
236 outVti (com1Lcr, 0x07);
237 outVti (com1Mcr, 0x0F);
238 outVti (com1Ier, 0x0);
239 }
240
241 int
242 AIOReadData (int portHandle, char *buffer, LONG length, LONG *numberBytesRead)
243 {
244 ULONG c;
245
246 while (1)
247 {
248 c = uart_getchar ();
249 if ((c & ~0377) == COM1)
250 break;
251 }
252
253 *buffer = c;
254 *numberBytesRead = 1;
255
256 return AIO_SUCCESS;
257 }
258
259 int
260 AIOWriteData (int portHandle, char *buffer, LONG length,
261 LONG *numberBytesWritten)
262
263 {
264 *numberBytesWritten = length;
265
266 while (length-- > 0)
267 uart_putchar (*buffer++);
268
269 return AIO_SUCCESS;
270 }
271
272 int
273 AIOAcquirePort (int *hardwareType, int *boardNumber, int *portNumber,
274 int *portHandle)
275 {
276 return AIO_SUCCESS;
277 }
278
279 int
280 AIOConfigurePort (int portHandle, BYTE bitRate, BYTE dataBits, BYTE stopBits,
281 BYTE parityMode, BYTE flowCtrlMode)
282 {
283 uart_init (9600);
284
285 return AIO_SUCCESS;
286 }
287
288 int
289 AIOGetPortConfiguration (int portHandle, AIOPORTCONFIG *pPortConfig,
290 AIODVRCONFIG *pDvrConfig)
291 {
292 fprintf (stderr, "AIOGetPortConfiguration stubbed out\n");
293 exit (1);
294 }
295
296 int
297 AIOReleasePort (int portHandle)
298 {
299 return AIO_SUCCESS;
300 }
301
302 int
303 AIOSetExternalControl (int portHandle, int requestType, int requestValue)
304 {
305 return AIO_SUCCESS;
306 }
307
308 int
309 AIOGetExternalStatus (int portHandle, LONG *extStatus, LONG *chgdExtStatus)
310 {
311 fprintf (stderr, "AIOGetExternalStatus stubbed out\n");
312 exit (1);
313 }
314
315 void
316 StopBell ()
317 {
318 }
319
320 int
321 Breakpoint (int __arg)
322 {
323 fprintf (stderr, "Breakpoint() stubbed out\n");
324 exit (1);
325 }