4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-23 09:09:35 +08:00

Add more semihosting support for BDM mode on ColdFire

This commit is contained in:
Sandra Loosemore 2006-05-22 22:29:17 +00:00
parent 398cdf8781
commit 22bd8d8dc6
3 changed files with 299 additions and 0 deletions

140
libgloss/m68k/bdm-gdb.c Normal file
View File

@ -0,0 +1,140 @@
/*
* bdm support for GDB's remote fileio protocol
*
* Copyright (c) 2006 CodeSourcery Inc
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include "bdm-gdb.h"
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
gdb_mode_t
convert_to_gdb_mode_t (mode_t m)
{
gdb_mode_t result = 0;
if (m & S_IFREG)
result |= GDB_S_IFREG;
if (m & S_IFDIR)
result |= GDB_S_IFDIR;
if (m & S_IRUSR)
result |= GDB_S_IRUSR;
if (m & S_IWUSR)
result |= GDB_S_IWUSR;
if (m & S_IXUSR)
result |= GDB_S_IXUSR;
if (m & S_IRGRP)
result |= GDB_S_IRGRP;
if (m & S_IWGRP)
result |= GDB_S_IWGRP;
if (m & S_IXGRP)
result |= GDB_S_IXGRP;
if (m & S_IROTH)
result |= GDB_S_IROTH;
if (m & S_IWOTH)
result |= GDB_S_IWOTH;
if (m & S_IXOTH)
result |= GDB_S_IXOTH;
return result;
}
int32_t
convert_to_gdb_open_flags (int f)
{
int32_t result = 0;
if (f & O_RDONLY)
result |= GDB_O_RDONLY;
if (f & O_WRONLY)
result |= GDB_O_WRONLY;
if (f & O_RDWR)
result |= GDB_O_RDWR;
if (f & O_APPEND)
result |= GDB_O_APPEND;
if (f & O_CREAT)
result |= GDB_O_CREAT;
if (f & O_TRUNC)
result |= GDB_O_TRUNC;
if (f & O_EXCL)
result |= GDB_O_EXCL;
return result;
}
int32_t
convert_to_gdb_lseek_flags (int f)
{
if (f == SEEK_CUR)
return GDB_SEEK_CUR;
else if (f == SEEK_END)
return GDB_SEEK_END;
else
return GDB_SEEK_SET;
}
void
convert_from_gdb_stat (const struct gdb_stat *gs,
struct stat *s)
{
s->st_dev = gs->st_dev;
s->st_ino = gs->st_ino;
s->st_mode = gs->st_mode;
s->st_nlink = gs->st_nlink;
s->st_uid = gs->st_uid;
s->st_gid = gs->st_gid;
s->st_rdev = gs->st_rdev;
s->st_size = gs->st_size;
s->st_blksize = gs->st_blksize;
s->st_blocks = gs->st_blocks;
s->st_atime = gs->st_atime;
s->st_mtime = gs->st_mtime;
s->st_ctime = gs->st_ctime;
}
void
convert_from_gdb_timeval (const struct gdb_timeval *gt,
struct timeval *t)
{
t->tv_sec = gt->tv_sec;
t->tv_usec = gt->tv_usec;
}
int
convert_from_gdb_errno (int32_t err)
{
switch (err)
{
case 0: return 0;
case GDB_EPERM: return EPERM;
case GDB_ENOENT: return ENOENT;
case GDB_EINTR: return EINTR;
case GDB_EBADF: return EBADF;
case GDB_EACCES: return EACCES;
case GDB_EFAULT: return EFAULT;
case GDB_EBUSY: return EBUSY;
case GDB_EEXIST: return EEXIST;
case GDB_ENODEV: return ENODEV;
case GDB_ENOTDIR: return ENOTDIR;
case GDB_EISDIR: return EISDIR;
case GDB_EINVAL: return EINVAL;
case GDB_ENFILE: return ENFILE;
case GDB_EMFILE: return EMFILE;
case GDB_EFBIG: return EFBIG;
case GDB_ENOSPC: return ENOSPC;
case GDB_ESPIPE: return ESPIPE;
case GDB_EROFS: return EROFS;
case GDB_ENAMETOOLONG: return ENAMETOOLONG;
case GDB_EUNKNOWN:
default:
return EIO;
}
}

128
libgloss/m68k/bdm-gdb.h Normal file
View File

@ -0,0 +1,128 @@
/*
* bdm support for GDB's remote fileio protocol
*
* Copyright (c) 2006 CodeSourcery Inc
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
/* Protocol specific representation of datatypes, as specified in D.9.11
* of the GDB manual.
* Note that since the m68k is big-endian, we can use native
* representations of integer datatypes in structured datatypes. */
typedef uint32_t gdb_mode_t;
typedef uint32_t gdb_time_t;
struct gdb_stat {
uint32_t st_dev; /* device */
uint32_t st_ino; /* inode */
gdb_mode_t st_mode; /* protection */
uint32_t st_nlink; /* number of hard links */
uint32_t st_uid; /* user ID of owner */
uint32_t st_gid; /* group ID of owner */
uint32_t st_rdev; /* device type (if inode device) */
uint64_t st_size; /* total size, in bytes */
uint64_t st_blksize; /* blocksize for filesystem I/O */
uint64_t st_blocks; /* number of blocks allocated */
gdb_time_t st_atime; /* time of last access */
gdb_time_t st_mtime; /* time of last modification */
gdb_time_t st_ctime; /* time of last change */
};
struct gdb_timeval {
gdb_time_t tv_sec; /* second */
uint64_t tv_usec; /* microsecond */
};
/* Parameters are passed between the library and the debugging stub
* in a fixed-size buffer.
*/
typedef uint32_t gdb_parambuf_t[4];
/* open flags */
#define GDB_O_RDONLY 0x0
#define GDB_O_WRONLY 0x1
#define GDB_O_RDWR 0x2
#define GDB_O_APPEND 0x8
#define GDB_O_CREAT 0x200
#define GDB_O_TRUNC 0x400
#define GDB_O_EXCL 0x800
/* mode_t values */
#define GDB_S_IFREG 0100000
#define GDB_S_IFDIR 040000
#define GDB_S_IRUSR 0400
#define GDB_S_IWUSR 0200
#define GDB_S_IXUSR 0100
#define GDB_S_IRGRP 040
#define GDB_S_IWGRP 020
#define GDB_S_IXGRP 010
#define GDB_S_IROTH 04
#define GDB_S_IWOTH 02
#define GDB_S_IXOTH 01
/* errno values */
#define GDB_EPERM 1
#define GDB_ENOENT 2
#define GDB_EINTR 4
#define GDB_EBADF 9
#define GDB_EACCES 13
#define GDB_EFAULT 14
#define GDB_EBUSY 16
#define GDB_EEXIST 17
#define GDB_ENODEV 19
#define GDB_ENOTDIR 20
#define GDB_EISDIR 21
#define GDB_EINVAL 22
#define GDB_ENFILE 23
#define GDB_EMFILE 24
#define GDB_EFBIG 27
#define GDB_ENOSPC 28
#define GDB_ESPIPE 29
#define GDB_EROFS 30
#define GDB_ENAMETOOLONG 91
#define GDB_EUNKNOWN 9999
/* lseek flags */
#define GDB_SEEK_SET 0
#define GDB_SEEK_CUR 1
#define GDB_SEEK_END 2
/* conversion functions */
extern gdb_mode_t convert_to_gdb_mode_t (mode_t m);
extern int32_t convert_to_gdb_open_flags (int f);
extern int32_t convert_to_gdb_lseek_flags (int f);
extern void convert_from_gdb_stat (const struct gdb_stat *gs,
struct stat *s);
extern void convert_from_gdb_timeval (const struct gdb_timeval *gt,
struct timeval *t);
extern int convert_from_gdb_errno (int32_t err);

View File

@ -0,0 +1,31 @@
#include "bdm-semihost.h"
#include "bdm-gdb.h"
#include <sys/time.h>
#include <errno.h>
/*
* gettimeofday -- get the current time
* input parameters:
* 0 : timeval ptr
* output parameters:
* 0 : result
* 1 : errno
*/
int gettimeofday (struct timeval *tv, struct timezone *tz)
{
gdb_parambuf_t parameters;
struct gdb_timeval gtv;
if (!tv)
return 0;
if (tz)
{
errno = EINVAL;
return -1;
}
parameters[0] = (uint32_t) &gtv;
BDM_TRAP (BDM_GETTIMEOFDAY, (uint32_t)parameters);
convert_from_gdb_timeval (&gtv, tv);
errno = convert_from_gdb_errno (parameters[1]);
return parameters[0];
}