]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ser-ocd.c
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / ser-ocd.c
CommitLineData
c906108c 1/* Remote serial interface for Macraigor Systems implementation of
c5aa993b 2 On-Chip Debugging using serial target box or serial wiggler
c906108c
SS
3
4 Copyright 1994, 1997 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
c5aa993b
JM
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "serial.h"
25
26#ifdef _WIN32
27#include <windows.h>
28#endif
29
30static int ser_ocd_open PARAMS ((serial_t scb, const char *name));
31static void ser_ocd_raw PARAMS ((serial_t scb));
32static int ser_ocd_readchar PARAMS ((serial_t scb, int timeout));
33static int ser_ocd_setbaudrate PARAMS ((serial_t scb, int rate));
34static int ser_ocd_write PARAMS ((serial_t scb, const char *str, int len));
35static void ser_ocd_close PARAMS ((serial_t scb));
36static serial_ttystate ser_ocd_get_tty_state PARAMS ((serial_t scb));
37static int ser_ocd_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
38
39#ifdef _WIN32
40/* On Windows, this function pointer is initialized to a function in
41 the wiggler DLL. */
42static int (*dll_do_command) PARAMS ((const char *, char *));
43#endif
44
45static int
46ocd_open (scb, name)
47 serial_t scb;
48 const char *name;
49{
50#ifdef _WIN32
51 /* Find the wiggler DLL which talks to the board. */
52 if (dll_do_command == NULL)
53 {
54 HINSTANCE handle;
55
56 /* FIXME: Should the user be able to configure this? */
57 handle = LoadLibrary ("Wigglers.dll");
58 if (handle == NULL)
59 error ("Can't load Wigglers.dll");
60
c5aa993b 61 dll_do_command = ((int (*)PARAMS ((const char *, char *)))
c906108c
SS
62 GetProcAddress (handle, "do_command"));
63 if (dll_do_command == NULL)
64 error ("Can't find do_command function in Wigglers.dll");
65 }
66#else
67 /* No wiggler DLLs on Unix yet, fail. */
68 error ("Wiggler library not available for this type of host.");
69#endif /* _WIN32 */
70 return 0;
71}
72
73static int
74ocd_noop (scb)
75 serial_t scb;
76{
77 return 0;
78}
79
80static void
81ocd_raw (scb)
82 serial_t scb;
83{
84 /* Always in raw mode */
85}
86
87static void
88ocd_readremote ()
89{
90}
91
92/* We need a buffer to store responses from the Wigglers.dll */
93#define WIGGLER_BUFF_SIZE 512
94unsigned char from_wiggler_buffer[WIGGLER_BUFF_SIZE];
c5aa993b 95unsigned char *wiggler_buffer_ptr; /* curr spot in buffer */
c906108c
SS
96
97static int
98ocd_readchar (scb, timeout)
99 serial_t scb;
100 int timeout;
101{
102 /* Catch attempts at reading past the end of the buffer */
103 if (wiggler_buffer_ptr >
c5aa993b
JM
104 (from_wiggler_buffer + (sizeof (char *) * WIGGLER_BUFF_SIZE)))
105 error ("ocd_readchar asked to read past the end of the buffer!");
c906108c 106
c5aa993b 107 return (int) *wiggler_buffer_ptr++; /* return curr char and increment ptr */
c906108c
SS
108}
109
c5aa993b
JM
110struct ocd_ttystate
111{
c906108c
SS
112 int dummy;
113};
114
115/* ocd_{get set}_tty_state() are both dummys to fill out the function
116 vector. Someday, they may do something real... */
117
118static serial_ttystate
119ocd_get_tty_state (scb)
120 serial_t scb;
121{
122 struct ocd_ttystate *state;
123
124 state = (struct ocd_ttystate *) xmalloc (sizeof *state);
125
126 return (serial_ttystate) state;
127}
128
129static int
130ocd_set_tty_state (scb, ttystate)
131 serial_t scb;
132 serial_ttystate ttystate;
133{
134 return 0;
135}
136
137static int
138ocd_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
139 serial_t scb;
140 serial_ttystate new_ttystate;
141 serial_ttystate old_ttystate;
142{
143 return 0;
144}
145
146static void
147ocd_print_tty_state (scb, ttystate)
148 serial_t scb;
149 serial_ttystate ttystate;
150{
151 /* Nothing to print. */
152 return;
153}
154
155static int
156ocd_setbaudrate (scb, rate)
157 serial_t scb;
158 int rate;
159{
160 return 0;
161}
162
163static int
164ocd_write (scb, str, len)
165 serial_t scb;
166 const char *str;
167 int len;
168{
169 char c;
170
c5aa993b 171#ifdef _WIN32
c906108c 172 /* send packet to Wigglers.dll and store response so we can give it to
c5aa993b 173 remote-wiggler.c when get_packet is run */
c906108c
SS
174 dll_do_command (str, from_wiggler_buffer);
175 wiggler_buffer_ptr = from_wiggler_buffer;
176#endif
177
178 return 0;
179}
180
181static void
182ocd_close (scb)
183 serial_t scb;
184{
185}
186
187static struct serial_ops ocd_ops =
188{
189 "ocd",
190 0,
191 ocd_open,
192 ocd_close,
193 ocd_readchar,
194 ocd_write,
c5aa993b
JM
195 ocd_noop, /* flush output */
196 ocd_noop, /* flush input */
197 ocd_noop, /* send break -- currently used only for nindy */
c906108c
SS
198 ocd_raw,
199 ocd_get_tty_state,
200 ocd_set_tty_state,
201 ocd_print_tty_state,
202 ocd_noflush_set_tty_state,
203 ocd_setbaudrate,
c5aa993b 204 ocd_noop, /* wait for output to drain */
c906108c
SS
205};
206
207void
208_initialize_ser_ocd_bdm ()
209{
210 serial_add_interface (&ocd_ops);
211}