Copy comments from gdbarch.sh to gdbarch.h. Fix a number of K&R params.
[deliverable/binutils-gdb.git] / gdb / ser-ocd.c
1 /* Remote serial interface for Macraigor Systems implementation of
2 On-Chip Debugging using serial target box or serial wiggler
3
4 Copyright 1994, 1997, 1999, 2000 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "serial.h"
25
26 #ifdef _WIN32
27 #include <windows.h>
28 #endif
29
30 #ifdef _WIN32
31 /* On Windows, this function pointer is initialized to a function in
32 the wiggler DLL. */
33 static int (*dll_do_command) (const char *, char *);
34 #endif
35
36 static int
37 ocd_open (serial_t scb, const char *name)
38 {
39 #ifdef _WIN32
40 /* Find the wiggler DLL which talks to the board. */
41 if (dll_do_command == NULL)
42 {
43 HINSTANCE handle;
44
45 /* FIXME: Should the user be able to configure this? */
46 handle = LoadLibrary ("Wigglers.dll");
47 if (handle == NULL)
48 error ("Can't load Wigglers.dll");
49
50 dll_do_command = ((int (*) (const char *, char *))
51 GetProcAddress (handle, "do_command"));
52 if (dll_do_command == NULL)
53 error ("Can't find do_command function in Wigglers.dll");
54 }
55 #else
56 /* No wiggler DLLs on Unix yet, fail. */
57 error ("Wiggler library not available for this type of host.");
58 #endif /* _WIN32 */
59 return 0;
60 }
61
62 static int
63 ocd_noop (serial_t scb)
64 {
65 return 0;
66 }
67
68 static void
69 ocd_raw (serial_t scb)
70 {
71 /* Always in raw mode */
72 }
73
74 /* We need a buffer to store responses from the Wigglers.dll */
75 #define WIGGLER_BUFF_SIZE 512
76 unsigned char from_wiggler_buffer[WIGGLER_BUFF_SIZE];
77 unsigned char *wiggler_buffer_ptr; /* curr spot in buffer */
78
79 static int
80 ocd_readchar (serial_t scb, int timeout)
81 {
82 /* Catch attempts at reading past the end of the buffer */
83 if (wiggler_buffer_ptr >
84 (from_wiggler_buffer + (sizeof (char *) * WIGGLER_BUFF_SIZE)))
85 error ("ocd_readchar asked to read past the end of the buffer!");
86
87 return (int) *wiggler_buffer_ptr++; /* return curr char and increment ptr */
88 }
89
90 struct ocd_ttystate
91 {
92 int dummy;
93 };
94
95 /* ocd_{get set}_tty_state() are both dummys to fill out the function
96 vector. Someday, they may do something real... */
97
98 static serial_ttystate
99 ocd_get_tty_state (serial_t scb)
100 {
101 struct ocd_ttystate *state;
102
103 state = (struct ocd_ttystate *) xmalloc (sizeof *state);
104
105 return (serial_ttystate) state;
106 }
107
108 static int
109 ocd_set_tty_state (serial_t scb, serial_ttystate ttystate)
110 {
111 return 0;
112 }
113
114 static int
115 ocd_noflush_set_tty_state (serial_t scb, serial_ttystate new_ttystate,
116 serial_ttystate old_ttystate)
117 {
118 return 0;
119 }
120
121 static void
122 ocd_print_tty_state (serial_t scb,
123 serial_ttystate ttystate,
124 struct ui_file *stream)
125 {
126 /* Nothing to print. */
127 return;
128 }
129
130 static int
131 ocd_setbaudrate (serial_t scb, int rate)
132 {
133 return 0;
134 }
135
136 static int
137 ocd_write (serial_t scb, const char *str, int len)
138 {
139 #ifdef _WIN32
140 /* send packet to Wigglers.dll and store response so we can give it to
141 remote-wiggler.c when get_packet is run */
142 dll_do_command (str, from_wiggler_buffer);
143 wiggler_buffer_ptr = from_wiggler_buffer;
144 #endif
145
146 return 0;
147 }
148
149 static void
150 ocd_close (serial_t scb)
151 {
152 }
153
154 static struct serial_ops ocd_ops =
155 {
156 "ocd",
157 0,
158 ocd_open,
159 ocd_close,
160 ocd_readchar,
161 ocd_write,
162 ocd_noop, /* flush output */
163 ocd_noop, /* flush input */
164 ocd_noop, /* send break -- currently used only for nindy */
165 ocd_raw,
166 ocd_get_tty_state,
167 ocd_set_tty_state,
168 ocd_print_tty_state,
169 ocd_noflush_set_tty_state,
170 ocd_setbaudrate,
171 ocd_noop, /* wait for output to drain */
172 };
173
174 void
175 _initialize_ser_ocd_bdm (void)
176 {
177 serial_add_interface (&ocd_ops);
178 }
This page took 0.031965 seconds and 4 git commands to generate.