Changeset b3fb2ff in rtems


Ignore:
Timestamp:
May 26, 2014, 1:44:48 AM (5 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11, master
Children:
d134adeb
Parents:
5c123985
git-author:
Chris Johns <chrisj@…> (05/26/14 01:44:48)
git-committer:
Chris Johns <chrisj@…> (05/26/14 01:52:02)
Message:

bsp/gdbarmsim: Change syscall functions to not clash with RTEMS functions.

The syscall functions overlapped with RTEMS, for example _write, _read, etc.
Change these to be internal to the BSP and avoid any clash with names in
RTEMS. Add support for SWI_Write0.

Change the console driver to use SWI_Write0. This outputs the character
to the host's stdout. Writing to file name 0 is not captured and managed
by GDB's simulation code while the SWI_Write0 is. The managed stdout
data is encapulated in the MI protocol while writes to file handle 0 are
dropped by GDB when in MI mode.

Location:
c/src/lib/libbsp/arm/gdbarmsim
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/gdbarmsim/console/console-io.c

    r5c123985 rb3fb2ff  
    2424}
    2525
    26 int _write(int fd, char *ptr, int len);
    27 
    2826/*
    2927 *  console_outbyte_polled
     
    3634)
    3735{
    38   _write(2, &ch, 1);
     36  gdbarmsim_writec(ch);
    3937}
    4038
  • c/src/lib/libbsp/arm/gdbarmsim/include/bsp.h

    r5c123985 rb3fb2ff  
    4141 */
    4242
     43//#define BSP_GET_WORK_AREA_DEBUG 1
     44
    4345/**
    4446 * @brief Support for simulated clock tick
     
    4648Thread clock_driver_sim_idle_body(uintptr_t);
    4749#define BSP_IDLE_TASK_BODY clock_driver_sim_idle_body
     50
     51/*
     52 * Access to the GDB simulator.
     53 */
     54int     gdbarmsim_system(const char *);
     55int     gdbarmsim_rename(const char *, const char *);
     56int     gdbarmsim__isatty(int);
     57clock_t gdbarmsim_times(struct tms *);
     58int     gdbarmsim_gettimeofday(struct timeval *, void *);
     59int     gdbarmsim_unlink(const char *);
     60int     gdbarmsim_link(void);
     61int     gdbarmsim_stat(const char *, struct stat *);
     62int     gdbarmsim_fstat(int, struct stat *);
     63int         gdbarmsim_swistat(int fd, struct stat * st);
     64int     gdbarmsim_close(int);
     65clock_t gdbarmsim_clock(void);
     66int     gdbarmsim_swiclose(int);
     67int     gdbarmsim_open(const char *, int, ...);
     68int     gdbarmsim_swiopen(const char *, int);
     69int     gdbarmsim_writec(const char c);
     70int     gdbarmsim_write(int, char *, int);
     71int     gdbarmsim_swiwrite(int, char *, int);
     72int     gdbarmsim_lseek(int, int, int);
     73int     gdbarmsim_swilseek(int, int, int);
     74int     gdbarmsim_read(int, char *, int);
     75int     gdbarmsim_swiread(int, char *, int);
     76void    initialise_monitor_handles(void);
    4877
    4978/** @} */
  • c/src/lib/libbsp/arm/gdbarmsim/startup/syscalls.c

    r5c123985 rb3fb2ff  
    77   Files in the C namespace (ie those that do not start with an
    88   underscore) go in .c.  */
     9
     10/*
     11 * Rename all the functions present here to stop then clashing with RTEMS
     12 * names.
     13 */
    914
    1015#include <_ansi.h>
     
    2328#include <bsp/swi.h>
    2429
     30#include <bsp.h>
     31
    2532/* Forward prototypes.  */
    26 int     _system     _PARAMS ((const char *));
    27 int     _rename     _PARAMS ((const char *, const char *));
    28 int     __isatty                _PARAMS ((int));
    29 clock_t _times          _PARAMS ((struct tms *));
    30 int     _gettimeofday   _PARAMS ((struct timeval *, void *));
    31 int     _unlink         _PARAMS ((const char *));
    32 int     _link           _PARAMS ((void));
    33 int     _stat           _PARAMS ((const char *, struct stat *));
    34 int     _fstat          _PARAMS ((int, struct stat *));
    35 int     _swistat        _PARAMS ((int fd, struct stat * st));
    36 caddr_t _sbrk           _PARAMS ((int));
    37 int     _getpid         _PARAMS ((int));
    38 int     _close          _PARAMS ((int));
    39 clock_t _clock          _PARAMS ((void));
    40 int     _swiclose       _PARAMS ((int));
    41 int     _open           _PARAMS ((const char *, int, ...));
    42 int     _swiopen        _PARAMS ((const char *, int));
    43 int     _write          _PARAMS ((int, char *, int));
    44 int     _swiwrite       _PARAMS ((int, char *, int));
    45 int     _lseek          _PARAMS ((int, int, int));
    46 int     _swilseek       _PARAMS ((int, int, int));
    47 int     _read           _PARAMS ((int, char *, int));
    48 int     _swiread        _PARAMS ((int, char *, int));
    49 void    initialise_monitor_handles _PARAMS ((void));
    50 
    51 static int      checkerror      _PARAMS ((int));
    52 static int      error           _PARAMS ((int));
    53 static int      get_errno       _PARAMS ((void));
     33static int      checkerror(int);
     34static int      error(int);
     35static int      get_errno(void);
    5436
    5537/* Struct used to keep track of the file position, just so we
     
    8062static struct fdent openfiles [MAX_OPEN_FILES];
    8163
    82 static struct fdent*    findslot        _PARAMS ((int));
    83 static int              newslot         _PARAMS ((void));
     64static struct fdent*    findslot (int);
     65static int              newslot (void);
    8466
    8567/* Register name faking - works in collusion with the linker.  */
     
    244226   Returns the number of bytes *not* written. */
    245227int
    246 _swiread (int fh,
    247           char * ptr,
    248           int len)
     228gdbarmsim_swiread (int fh,
     229                   char * ptr,
     230                   int len)
    249231{
    250232#ifdef ARM_RDI_MONITOR
     
    274256   bytes read. */
    275257int
    276 _read (int fd,
    277        char * ptr,
    278        int len)
     258gdbarmsim_read (int fd,
     259                char * ptr,
     260                int len)
    279261{
    280262  int res;
     
    288270    }
    289271
    290   res = _swiread (pfd->handle, ptr, len);
     272  res = gdbarmsim_swiread (pfd->handle, ptr, len);
    291273
    292274  if (res == -1)
     
    302284/* fd, is a user file descriptor. */
    303285int
    304 _swilseek (int fd,
    305         int ptr,
    306         int dir)
     286gdbarmsim_swilseek (int fd,
     287                    int ptr,
     288                    int dir)
    307289{
    308290  int res;
     
    387369
    388370int
    389 _lseek (int fd,
    390         int ptr,
    391         int dir)
    392 {
    393   return _swilseek (fd, ptr, dir);
     371gdbarmsim_lseek (int fd,
     372                 int ptr,
     373                 int dir)
     374{
     375  return gdbarmsim_swilseek (fd, ptr, dir);
     376}
     377
     378/* write a single character out the hosts stdout */
     379int
     380gdbarmsim_writec (const char c)
     381{
     382#ifdef ARM_RDI_MONITOR
     383  int block[1];
     384
     385  block[0] = ((int) c) & 0xff;;
     386
     387  return checkerror (do_AngelSWI (AngelSWI_Reason_WriteC, block));
     388#else
     389  register int r0 __asm__ ("r0");
     390  r0 = ((int) c) & 0xff;
     391  __asm__ ("swi %a2"
     392       : "=r" (r0)
     393       : "0"(r0), "i"(SWI_WriteC));
     394  return checkerror (r0);
     395#endif
    394396}
    395397
     
    397399   Returns the number of bytes *not* written. */
    398400int
    399 _swiwrite (
    400            int    fh,
    401            char * ptr,
    402            int    len)
     401gdbarmsim_swiwrite (int    fh,
     402                    char * ptr,
     403                    int    len)
    403404{
    404405#ifdef ARM_RDI_MONITOR
     
    426427/* fd, is a user file descriptor. */
    427428int
    428 _write (int    fd,
    429         char * ptr,
    430         int    len)
     429gdbarmsim_write (int    fd,
     430                 char * ptr,
     431                 int    len)
    431432{
    432433  int res;
     
    440441    }
    441442
    442   res = _swiwrite (pfd->handle, ptr,len);
     443  res = gdbarmsim_swiwrite (pfd->handle, ptr,len);
    443444
    444445  /* Clearly an error. */
     
    457458
    458459int
    459 _swiopen (const char * path, int flags)
     460gdbarmsim_swiopen (const char * path, int flags)
    460461{
    461462  int aflags = 0, fh;
     
    478479      struct stat st;
    479480      int res;
    480       res = _stat (path, &st);
     481      res = gdbarmsim_stat (path, &st);
    481482      if (res != -1)
    482483        {
     
    535536
    536537int
    537 _open (const char * path, int flags, ...)
    538 {
    539   return _swiopen (path, flags);
     538gdbarmsim_open (const char * path, int flags, ...)
     539{
     540  return gdbarmsim_swiopen (path, flags);
    540541}
    541542
    542543/* fh, is a valid internal file handle. */
    543544int
    544 _swiclose (int fh)
     545gdbarmsim_swiclose (int fh)
    545546{
    546547#ifdef ARM_RDI_MONITOR
     
    558559/* fd, is a user file descriptor. */
    559560int
    560 _close (int fd)
     561gdbarmsim_close (int fd)
    561562{
    562563  int res;
     
    579580
    580581  /* Attempt to close the handle. */
    581   res = _swiclose (pfd->handle);
     582  res = gdbarmsim_swiclose (pfd->handle);
    582583
    583584  /* Reclaim handle? */
     
    588589}
    589590
    590 int __attribute__((weak))
    591 _getpid (int n __attribute__ ((unused)))
    592 {
    593   return 1;
    594 }
    595 
    596 #if !defined(__rtems__)
    597 caddr_t
    598 _sbrk (int incr)
    599 {
    600   extern char end __asm__ ("end"); /* Defined by the linker.  */
    601   static char * heap_end;
    602   char * prev_heap_end;
    603 
    604   if (heap_end == NULL)
    605     heap_end = & end;
    606 
    607   prev_heap_end = heap_end;
    608 
    609   if (heap_end + incr > stack_ptr)
    610     {
    611       /* Some of the libstdc++-v3 tests rely upon detecting
    612          out of memory errors, so do not abort here.  */
    613 #if 0
    614       extern void abort (void);
    615 
    616       _write (1, "_sbrk: Heap and stack collision\n", 32);
    617 
    618       abort ();
    619 #else
    620       errno = ENOMEM;
    621       return (caddr_t) -1;
    622 #endif
    623     }
    624 
    625   heap_end += incr;
    626 
    627   return (caddr_t) prev_heap_end;
    628 }
    629 #endif
    630 
    631 int
    632 _swistat (int fd, struct stat * st)
     591int
     592gdbarmsim_swistat (int fd, struct stat * st)
    633593{
    634594  struct fdent *pfd;
     
    662622}
    663623
    664 int __attribute__((weak))
    665 _fstat (int fd, struct stat * st)
     624int
     625gdbarmsim_fstat (int fd, struct stat * st)
    666626{
    667627  memset (st, 0, sizeof (* st));
    668   return _swistat (fd, st);
    669 }
    670 
    671 int __attribute__((weak))
    672 _stat (const char *fname, struct stat *st)
     628  return gdbarmsim_swistat (fd, st);
     629}
     630
     631int
     632gdbarmsim_stat (const char *fname, struct stat *st)
    673633{
    674634  int fd, res;
     
    676636  /* The best we can do is try to open the file readonly.
    677637     If it exists, then we can guess a few things about it. */
    678   if ((fd = _open (fname, O_RDONLY)) == -1)
     638  if ((fd = gdbarmsim_open (fname, O_RDONLY)) == -1)
    679639    return -1;
    680640  st->st_mode |= S_IFREG | S_IREAD;
    681   res = _swistat (fd, st);
     641  res = gdbarmsim_swistat (fd, st);
    682642  /* Not interested in the error. */
    683   _close (fd);
     643  gdbarmsim_close (fd);
    684644  return res;
    685645}
    686646
    687 int __attribute__((weak))
    688 _link (void)
    689 {
    690   errno = ENOSYS;
    691   return -1;
    692 }
    693 
    694 int
    695 _unlink (const char *path)
     647int
     648gdbarmsim_unlink (const char *path)
    696649{
    697650  int res;
     
    714667}
    715668
    716 #if !defined(__rtems__)
    717 int
    718 _gettimeofday (struct timeval * tp, void * tzvp)
    719 {
    720   struct timezone *tzp = tzvp;
    721   if (tp)
    722     {
    723     /* Ask the host for the seconds since the Unix epoch.  */
    724 #ifdef ARM_RDI_MONITOR
    725       tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL);
    726 #else
    727       {
    728         int value;
    729         __asm__ ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
    730         tp->tv_sec = value;
    731       }
    732 #endif
    733       tp->tv_usec = 0;
    734     }
    735 
    736   /* Return fixed data for the timezone.  */
    737   if (tzp)
    738     {
    739       tzp->tz_minuteswest = 0;
    740       tzp->tz_dsttime = 0;
    741     }
    742 
    743   return 0;
    744 }
    745 #endif
    746 
    747669/* Return a clock that ticks at 100Hz.  */
    748670clock_t
    749 _clock (void)
     671gdbarmsim_clock (void)
    750672{
    751673  clock_t timeval;
     
    759681}
    760682
    761 #if !defined(__rtems__)
    762 /* Return a clock that ticks at 100Hz.  */
    763 clock_t
    764 _times (struct tms * tp)
    765 {
    766   clock_t timeval = _clock();
    767 
    768   if (tp)
    769     {
    770       tp->tms_utime  = timeval; /* user time */
    771       tp->tms_stime  = 0;       /* system time */
    772       tp->tms_cutime = 0;       /* user time, children */
    773       tp->tms_cstime = 0;       /* system time, children */
    774     }
    775 
    776   return timeval;
    777 };
    778 #endif
    779 
    780 
    781 int
    782 __isatty (int fd)
     683int
     684gdbarmsim__isatty (int fd)
    783685{
    784686  struct fdent *pfd;
     
    804706
    805707int
    806 _system (const char *s)
     708gdbarmsim_system (const char *s)
    807709{
    808710#ifdef ARM_RDI_MONITOR
     
    840742
    841743int
    842 _rename (const char * oldpath, const char * newpath)
     744gdbarmsim_rename (const char * oldpath, const char * newpath)
    843745{
    844746#ifdef ARM_RDI_MONITOR
Note: See TracChangeset for help on using the changeset viewer.