X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fser-ocd.c;h=08239bba3a4e6f66970c5c9ccd264bc560c427d9;hb=326ca4ee5776a676c6b6a7913321107e2a3c73e2;hp=1b1213ede0f4c17dd99174f021b2146ceeac58c1;hpb=706eff3f9df3cb29608b7ba465b15b3dbbe0b964;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/ser-ocd.c b/gdb/ser-ocd.c index 1b1213ede0..08239bba3a 100644 --- a/gdb/ser-ocd.c +++ b/gdb/ser-ocd.c @@ -22,6 +22,10 @@ #include "defs.h" #include "serial.h" +#ifdef _WIN32 +#include +#endif + static int ser_ocd_open PARAMS ((serial_t scb, const char *name)); static void ser_ocd_raw PARAMS ((serial_t scb)); static int ser_ocd_readchar PARAMS ((serial_t scb, int timeout)); @@ -31,11 +35,35 @@ static void ser_ocd_close PARAMS ((serial_t scb)); static serial_ttystate ser_ocd_get_tty_state PARAMS ((serial_t scb)); static int ser_ocd_set_tty_state PARAMS ((serial_t scb, serial_ttystate state)); +#ifdef _WIN32 +/* On Windows, this function pointer is initialized to a function in + the wiggler DLL. */ +static int (*dll_do_command) PARAMS ((const char *, char *)); +#endif + static int ocd_open (scb, name) serial_t scb; const char *name; { +#ifdef _WIN32 + /* Find the wiggler DLL which talks to the board. */ + if (dll_do_command == NULL) + { + HINSTANCE handle; + + /* FIXME: Should the user be able to configure this? */ + handle = LoadLibrary ("Wigglers.dll"); + if (handle == NULL) + error ("Can't load Wigglers.dll"); + + dll_do_command = ((int (*) PARAMS ((const char *, char *))) + GetProcAddress (handle, "do_command")); + if (dll_do_command == NULL) + error ("Can't find do_command function in Wigglers.dll"); + } +#endif + return 0; } @@ -53,21 +81,27 @@ ocd_raw (scb) /* Always in raw mode */ } -/* We need a buffer to store responses from the Wigglers.dll */ -char * from_wigglers_buffer; -char * bptr; /* curr spot in buffer */ - static void ocd_readremote () { } +/* We need a buffer to store responses from the Wigglers.dll */ +#define WIGGLER_BUFF_SIZE 512 +unsigned char from_wiggler_buffer[WIGGLER_BUFF_SIZE]; +unsigned char * wiggler_buffer_ptr; /* curr spot in buffer */ + static int ocd_readchar (scb, timeout) serial_t scb; int timeout; { + /* Catch attempts at reading past the end of the buffer */ + if (wiggler_buffer_ptr > + (from_wiggler_buffer + (sizeof (char *) * WIGGLER_BUFF_SIZE))) + error ("ocd_readchar asked to read past the end of the buffer!"); + return (int) *wiggler_buffer_ptr++; /* return curr char and increment ptr */ } struct ocd_ttystate { @@ -130,12 +164,11 @@ ocd_write (scb, str, len) { char c; - ocd_readremote(); - -#ifdef __CYGWIN32__ +#ifdef _WIN32 /* send packet to Wigglers.dll and store response so we can give it to remote-wiggler.c when get_packet is run */ - do_command (str, from_wigglers_buffer); + dll_do_command (str, from_wiggler_buffer); + wiggler_buffer_ptr = from_wiggler_buffer; #endif return 0; @@ -145,7 +178,6 @@ static void ocd_close (scb) serial_t scb; { - ocd_close (0); } static struct serial_ops ocd_ops =