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