OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [ser-mac.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* Remote serial interface for local (hardwired) serial ports for Macintosh.
/* Remote serial interface for local (hardwired) serial ports for Macintosh.
   Copyright 1994, 2000 Free Software Foundation, Inc.
   Copyright 1994, 2000 Free Software Foundation, Inc.
   Contributed by Cygnus Support.  Written by Stan Shebs.
   Contributed by Cygnus Support.  Written by Stan Shebs.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "serial.h"
#include "serial.h"
 
 
#include <Types.h>
#include <Types.h>
#include <Devices.h>
#include <Devices.h>
/* This is the regular Mac Serial.h, but copied to a different name
/* This is the regular Mac Serial.h, but copied to a different name
   so as not to get confused with the GDB serial.h above.  */
   so as not to get confused with the GDB serial.h above.  */
#include "MacSerial.h"
#include "MacSerial.h"
 
 
/* This is unused for now.  We just return a placeholder. */
/* This is unused for now.  We just return a placeholder. */
 
 
struct mac_ttystate
struct mac_ttystate
  {
  {
    int bogus;
    int bogus;
  };
  };
 
 
static int mac_open PARAMS ((serial_t scb, const char *name));
static int mac_open PARAMS ((serial_t scb, const char *name));
static void mac_raw PARAMS ((serial_t scb));
static void mac_raw PARAMS ((serial_t scb));
static int mac_readchar PARAMS ((serial_t scb, int timeout));
static int mac_readchar PARAMS ((serial_t scb, int timeout));
static int mac_setbaudrate PARAMS ((serial_t scb, int rate));
static int mac_setbaudrate PARAMS ((serial_t scb, int rate));
static int mac_write PARAMS ((serial_t scb, const char *str, int len));
static int mac_write PARAMS ((serial_t scb, const char *str, int len));
static void mac_close PARAMS ((serial_t scb));
static void mac_close PARAMS ((serial_t scb));
static serial_ttystate mac_get_tty_state PARAMS ((serial_t scb));
static serial_ttystate mac_get_tty_state PARAMS ((serial_t scb));
static int mac_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
static int mac_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
static char *aptr PARAMS ((short p));
static char *aptr PARAMS ((short p));
 
 
short input_refnum;
short input_refnum;
short output_refnum;
short output_refnum;
 
 
char *mac_input_buffer;
char *mac_input_buffer;
char *mac_output_buffer;
char *mac_output_buffer;
 
 
static int
static int
mac_open (scb, name)
mac_open (scb, name)
     serial_t scb;
     serial_t scb;
     const char *name;
     const char *name;
{
{
  OSErr err;
  OSErr err;
 
 
  /* Alloc buffer space first - that way any allocation failures are
  /* Alloc buffer space first - that way any allocation failures are
     intercepted before the serial driver gets involved. */
     intercepted before the serial driver gets involved. */
  if (mac_input_buffer == NULL)
  if (mac_input_buffer == NULL)
    mac_input_buffer = (char *) xmalloc (4096);
    mac_input_buffer = (char *) xmalloc (4096);
  /* Match on a name and open a port. */
  /* Match on a name and open a port. */
  if (strcmp (name, "modem") == 0)
  if (strcmp (name, "modem") == 0)
    {
    {
      err = OpenDriver ("\p.AIn", &input_refnum);
      err = OpenDriver ("\p.AIn", &input_refnum);
      if (err != 0)
      if (err != 0)
        {
        {
          return (-1);
          return (-1);
        }
        }
      err = OpenDriver ("\p.AOut", &output_refnum);
      err = OpenDriver ("\p.AOut", &output_refnum);
      if (err != 0)
      if (err != 0)
        {
        {
          CloseDriver (input_refnum);
          CloseDriver (input_refnum);
          return (-1);
          return (-1);
        }
        }
    }
    }
  else if (strcmp (name, "printer") == 0)
  else if (strcmp (name, "printer") == 0)
    {
    {
      err = OpenDriver ("\p.BIn", &input_refnum);
      err = OpenDriver ("\p.BIn", &input_refnum);
      if (err != 0)
      if (err != 0)
        {
        {
          return (-1);
          return (-1);
        }
        }
      err = OpenDriver ("\p.BOut", &output_refnum);
      err = OpenDriver ("\p.BOut", &output_refnum);
      if (err != 0)
      if (err != 0)
        {
        {
          CloseDriver (input_refnum);
          CloseDriver (input_refnum);
          return (-1);
          return (-1);
        }
        }
      /* fake */
      /* fake */
      scb->fd = 1;
      scb->fd = 1;
      return 0;
      return 0;
    }
    }
  else
  else
    {
    {
      error ("You must specify a valid serial port name; your choices are `modem' or `printer'.");
      error ("You must specify a valid serial port name; your choices are `modem' or `printer'.");
      errno = ENOENT;
      errno = ENOENT;
      return (-1);
      return (-1);
    }
    }
  /* We got something open. */
  /* We got something open. */
  if (1 /* using custom buffer */ )
  if (1 /* using custom buffer */ )
    SerSetBuf (input_refnum, mac_input_buffer, 4096);
    SerSetBuf (input_refnum, mac_input_buffer, 4096);
  /* Set to a GDB-preferred state. */
  /* Set to a GDB-preferred state. */
  SerReset (input_refnum, stop10 | noParity | data8 | baud9600);
  SerReset (input_refnum, stop10 | noParity | data8 | baud9600);
  SerReset (output_refnum, stop10 | noParity | data8 | baud9600);
  SerReset (output_refnum, stop10 | noParity | data8 | baud9600);
  {
  {
    CntrlParam cb;
    CntrlParam cb;
    struct SerShk *handshake;
    struct SerShk *handshake;
 
 
    cb.ioCRefNum = output_refnum;
    cb.ioCRefNum = output_refnum;
    cb.csCode = 14;
    cb.csCode = 14;
    handshake = (struct SerShk *) &cb.csParam[0];
    handshake = (struct SerShk *) &cb.csParam[0];
    handshake->fXOn = 0;
    handshake->fXOn = 0;
    handshake->fCTS = 0;
    handshake->fCTS = 0;
    handshake->xOn = 0;
    handshake->xOn = 0;
    handshake->xOff = 0;
    handshake->xOff = 0;
    handshake->errs = 0;
    handshake->errs = 0;
    handshake->evts = 0;
    handshake->evts = 0;
    handshake->fInX = 0;
    handshake->fInX = 0;
    handshake->fDTR = 0;
    handshake->fDTR = 0;
    err = PBControl ((ParmBlkPtr) & cb, 0);
    err = PBControl ((ParmBlkPtr) & cb, 0);
    if (err < 0)
    if (err < 0)
      return (-1);
      return (-1);
  }
  }
  /* fake */
  /* fake */
  scb->fd = 1;
  scb->fd = 1;
  return 0;
  return 0;
}
}
 
 
static int
static int
mac_noop (scb)
mac_noop (scb)
     serial_t scb;
     serial_t scb;
{
{
  return 0;
  return 0;
}
}
 
 
static void
static void
mac_raw (scb)
mac_raw (scb)
     serial_t scb;
     serial_t scb;
{
{
  /* Always effectively in raw mode. */
  /* Always effectively in raw mode. */
}
}
 
 
/* Read a character with user-specified timeout.  TIMEOUT is number of seconds
/* Read a character with user-specified timeout.  TIMEOUT is number of seconds
   to wait, or -1 to wait forever.  Use timeout of 0 to effect a poll.  Returns
   to wait, or -1 to wait forever.  Use timeout of 0 to effect a poll.  Returns
   char if successful.  Returns -2 if timeout expired, EOF if line dropped
   char if successful.  Returns -2 if timeout expired, EOF if line dropped
   dead, or -3 for any other error (see errno in that case). */
   dead, or -3 for any other error (see errno in that case). */
 
 
static int
static int
mac_readchar (scb, timeout)
mac_readchar (scb, timeout)
     serial_t scb;
     serial_t scb;
     int timeout;
     int timeout;
{
{
  int status, n;
  int status, n;
  /* time_t */ unsigned long start_time, now;
  /* time_t */ unsigned long start_time, now;
  OSErr err;
  OSErr err;
  CntrlParam cb;
  CntrlParam cb;
  IOParam pb;
  IOParam pb;
 
 
  if (scb->bufcnt-- > 0)
  if (scb->bufcnt-- > 0)
    return *scb->bufp++;
    return *scb->bufp++;
 
 
  time (&start_time);
  time (&start_time);
 
 
  while (1)
  while (1)
    {
    {
      cb.ioCRefNum = input_refnum;
      cb.ioCRefNum = input_refnum;
      cb.csCode = 2;
      cb.csCode = 2;
      err = PBStatus ((ParmBlkPtr) & cb, 0);
      err = PBStatus ((ParmBlkPtr) & cb, 0);
      if (err < 0)
      if (err < 0)
        return SERIAL_ERROR;
        return SERIAL_ERROR;
      n = *((long *) &cb.csParam[0]);
      n = *((long *) &cb.csParam[0]);
      if (n > 0)
      if (n > 0)
        {
        {
          pb.ioRefNum = input_refnum;
          pb.ioRefNum = input_refnum;
          pb.ioBuffer = (Ptr) (scb->buf);
          pb.ioBuffer = (Ptr) (scb->buf);
          pb.ioReqCount = (n > 64 ? 64 : n);
          pb.ioReqCount = (n > 64 ? 64 : n);
          err = PBRead ((ParmBlkPtr) & pb, 0);
          err = PBRead ((ParmBlkPtr) & pb, 0);
          if (err < 0)
          if (err < 0)
            return SERIAL_ERROR;
            return SERIAL_ERROR;
          scb->bufcnt = pb.ioReqCount;
          scb->bufcnt = pb.ioReqCount;
          scb->bufcnt--;
          scb->bufcnt--;
          scb->bufp = scb->buf;
          scb->bufp = scb->buf;
          return *scb->bufp++;
          return *scb->bufp++;
        }
        }
      else if (timeout == 0)
      else if (timeout == 0)
        return SERIAL_TIMEOUT;
        return SERIAL_TIMEOUT;
      else if (timeout == -1)
      else if (timeout == -1)
        ;
        ;
      else
      else
        {
        {
          time (&now);
          time (&now);
          if (now > start_time + timeout)
          if (now > start_time + timeout)
            return SERIAL_TIMEOUT;
            return SERIAL_TIMEOUT;
        }
        }
      PROGRESS (1);
      PROGRESS (1);
    }
    }
}
}
 
 
/* mac_{get set}_tty_state() are both dummys to fill out the function
/* mac_{get set}_tty_state() are both dummys to fill out the function
   vector.  Someday, they may do something real... */
   vector.  Someday, they may do something real... */
 
 
static serial_ttystate
static serial_ttystate
mac_get_tty_state (scb)
mac_get_tty_state (scb)
     serial_t scb;
     serial_t scb;
{
{
  struct mac_ttystate *state;
  struct mac_ttystate *state;
 
 
  state = (struct mac_ttystate *) xmalloc (sizeof *state);
  state = (struct mac_ttystate *) xmalloc (sizeof *state);
 
 
  return (serial_ttystate) state;
  return (serial_ttystate) state;
}
}
 
 
static int
static int
mac_set_tty_state (scb, ttystate)
mac_set_tty_state (scb, ttystate)
     serial_t scb;
     serial_t scb;
     serial_ttystate ttystate;
     serial_ttystate ttystate;
{
{
  return 0;
  return 0;
}
}
 
 
static int
static int
mac_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
mac_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
     serial_t scb;
     serial_t scb;
     serial_ttystate new_ttystate;
     serial_ttystate new_ttystate;
     serial_ttystate old_ttystate;
     serial_ttystate old_ttystate;
{
{
  return 0;
  return 0;
}
}
 
 
static void
static void
mac_print_tty_state (serial_t scb,
mac_print_tty_state (serial_t scb,
                     serial_ttystate ttystate,
                     serial_ttystate ttystate,
                     struct ui_file *stream)
                     struct ui_file *stream)
{
{
  /* Nothing to print.  */
  /* Nothing to print.  */
  return;
  return;
}
}
 
 
/* If there is a tricky formula to relate real baud rates
/* If there is a tricky formula to relate real baud rates
   to what the serial driver wants, we should use it.  Until
   to what the serial driver wants, we should use it.  Until
   we get one, this table will have to do.  */
   we get one, this table will have to do.  */
 
 
static struct
static struct
{
{
  int real_rate;
  int real_rate;
  int bits;
  int bits;
}
}
mac_baud_rate_table[] =
mac_baud_rate_table[] =
{
{
  {
  {
    57600, baud57600
    57600, baud57600
  }
  }
  ,
  ,
  {
  {
    38400, 1
    38400, 1
  }
  }
  ,
  ,
  {
  {
    19200, baud19200
    19200, baud19200
  }
  }
  ,
  ,
  {
  {
    9600, baud9600
    9600, baud9600
  }
  }
  ,
  ,
  {
  {
    7200, baud7200
    7200, baud7200
  }
  }
  ,
  ,
  {
  {
    4800, baud4800
    4800, baud4800
  }
  }
  ,
  ,
  {
  {
    3600, baud3600
    3600, baud3600
  }
  }
  ,
  ,
  {
  {
    2400, baud2400
    2400, baud2400
  }
  }
  ,
  ,
  {
  {
    1800, baud1800
    1800, baud1800
  }
  }
  ,
  ,
  {
  {
    1200, baud1200
    1200, baud1200
  }
  }
  ,
  ,
  {
  {
    600, baud600
    600, baud600
  }
  }
  ,
  ,
  {
  {
    300, baud300
    300, baud300
  }
  }
  ,
  ,
  {
  {
    0, 0
    0, 0
  }
  }
};
};
 
 
static int
static int
mac_set_baud_rate (scb, rate)
mac_set_baud_rate (scb, rate)
     serial_t scb;
     serial_t scb;
     int rate;
     int rate;
{
{
  int i, bits;
  int i, bits;
 
 
  for (i = 0; mac_baud_rate_table[i].real_rate != 0; ++i)
  for (i = 0; mac_baud_rate_table[i].real_rate != 0; ++i)
    {
    {
      if (mac_baud_rate_table[i].real_rate == rate)
      if (mac_baud_rate_table[i].real_rate == rate)
        {
        {
          bits = mac_baud_rate_table[i].bits;
          bits = mac_baud_rate_table[i].bits;
          break;
          break;
        }
        }
    }
    }
  SerReset (input_refnum, stop10 | noParity | data8 | bits);
  SerReset (input_refnum, stop10 | noParity | data8 | bits);
  SerReset (output_refnum, stop10 | noParity | data8 | bits);
  SerReset (output_refnum, stop10 | noParity | data8 | bits);
}
}
 
 
static int
static int
mac_set_stop_bits (scb, num)
mac_set_stop_bits (scb, num)
     serial_t scb;
     serial_t scb;
     int num;
     int num;
{
{
  return 0;
  return 0;
}
}
 
 
int first_mac_write = 0;
int first_mac_write = 0;
 
 
static int
static int
mac_write (scb, str, len)
mac_write (scb, str, len)
     serial_t scb;
     serial_t scb;
     const char *str;
     const char *str;
     int len;
     int len;
{
{
  OSErr err;
  OSErr err;
  IOParam pb;
  IOParam pb;
 
 
  if (first_mac_write++ < 4)
  if (first_mac_write++ < 4)
    {
    {
      sleep (1);
      sleep (1);
    }
    }
  pb.ioRefNum = output_refnum;
  pb.ioRefNum = output_refnum;
  pb.ioBuffer = (Ptr) str;
  pb.ioBuffer = (Ptr) str;
  pb.ioReqCount = len;
  pb.ioReqCount = len;
  err = PBWrite ((ParmBlkPtr) & pb, 0);
  err = PBWrite ((ParmBlkPtr) & pb, 0);
  if (err < 0)
  if (err < 0)
    {
    {
      return 1;
      return 1;
    }
    }
  return 0;
  return 0;
}
}
 
 
static void
static void
mac_close (serial_t scb)
mac_close (serial_t scb)
{
{
  if (input_refnum)
  if (input_refnum)
    {
    {
      if (1 /* custom buffer */ )
      if (1 /* custom buffer */ )
        SerSetBuf (input_refnum, mac_input_buffer, 0);
        SerSetBuf (input_refnum, mac_input_buffer, 0);
      CloseDriver (input_refnum);
      CloseDriver (input_refnum);
      input_refnum = 0;
      input_refnum = 0;
    }
    }
  if (output_refnum)
  if (output_refnum)
    {
    {
      if (0 /* custom buffer */ )
      if (0 /* custom buffer */ )
        SerSetBuf (input_refnum, mac_output_buffer, 0);
        SerSetBuf (input_refnum, mac_output_buffer, 0);
      CloseDriver (output_refnum);
      CloseDriver (output_refnum);
      output_refnum = 0;
      output_refnum = 0;
    }
    }
}
}
 
 
static struct serial_ops mac_ops =
static struct serial_ops mac_ops =
{
{
  "hardwire",
  "hardwire",
  0,
  0,
  mac_open,
  mac_open,
  mac_close,
  mac_close,
  mac_readchar,
  mac_readchar,
  mac_write,
  mac_write,
  mac_noop,                     /* flush output */
  mac_noop,                     /* flush output */
  mac_noop,                     /* flush input */
  mac_noop,                     /* flush input */
  mac_noop,                     /* send break -- currently only for nindy */
  mac_noop,                     /* send break -- currently only for nindy */
  mac_raw,
  mac_raw,
  mac_get_tty_state,
  mac_get_tty_state,
  mac_set_tty_state,
  mac_set_tty_state,
  mac_print_tty_state,
  mac_print_tty_state,
  mac_noflush_set_tty_state,
  mac_noflush_set_tty_state,
  mac_set_baud_rate,
  mac_set_baud_rate,
  mac_set_stop_bits,
  mac_set_stop_bits,
  mac_noop,                     /* wait for output to drain */
  mac_noop,                     /* wait for output to drain */
};
};
 
 
void
void
_initialize_ser_mac ()
_initialize_ser_mac ()
{
{
  serial_add_interface (&mac_ops);
  serial_add_interface (&mac_ops);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.