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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [common/] [v2_0/] [src/] [gdb-fileio.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*==========================================================================
2
//
3
//      gdb-fileio.c
4
//
5
//      Implementation of File I/O using the GDB remote protocol
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):           jlarmour
44
// Contributors:
45
// Date:                2002-04-09
46
// Purpose:             Implementation of File I/O using the GDB remote
47
//                      protocol
48
// Description:         'F' packet requests are of the form:
49
//                      F<name>[,<parameter>]...
50
//                      where name is the ASCII syscall name, and the
51
//                      parameters are generally included as hex ints,
52
//                      in ASCII.
53
//
54
//####DESCRIPTIONEND####
55
//========================================================================*/
56
 
57
/* CONFIGURATION */
58
 
59
#include <pkgconf/hal.h>
60
 
61
/* HEADERS */
62
 
63
#include <stddef.h>                     // size_t
64
#include <cyg/infra/cyg_type.h>
65
#ifdef CYGPKG_ISOINFRA
66
# include <pkgconf/isoinfra.h>
67
# include <string.h>
68
#endif
69
#include "board.h"    // sets correct definitions for generic stub header
70
#include <cyg/hal/generic-stub.h>
71
#include "gdb-fileio.h"
72
 
73
/* TYPES */
74
 
75
// this is used by newlib's mode_t so we should match it
76
#ifdef __GNUC__
77
#define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
78
#else
79
#define _ST_INT32
80
#endif
81
 
82
typedef int             newlib_int_t;
83
typedef unsigned int    newlib_uint_t;
84
typedef long            newlib_long_t;
85
typedef long            newlib_time_t;
86
typedef unsigned int    newlib_mode_t _ST_INT32;
87
typedef short           newlib_dev_t;
88
typedef unsigned short  newlib_uid_t;
89
typedef unsigned short  newlib_gid_t;
90
typedef unsigned short  newlib_ino_t;
91
typedef unsigned short  newlib_nlink_t;
92
typedef long            newlib_off_t;
93
 
94
struct newlib_timeval {
95
  newlib_time_t tv_sec;
96
  newlib_long_t tv_usec;
97
};
98
 
99
struct newlib_stat
100
{
101
    newlib_dev_t     st_dev;
102
    newlib_ino_t     st_ino;
103
    newlib_mode_t    st_mode;
104
    newlib_nlink_t   st_nlink;
105
    newlib_uid_t     st_uid;
106
    newlib_gid_t     st_gid;
107
    newlib_dev_t     st_rdev;
108
    newlib_off_t     st_size;
109
    // We assume we've been compiled with the same flags as newlib here
110
#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
111
    newlib_time_t    st_atime;
112
    newlib_time_t    st_mtime;
113
    newlib_time_t    st_ctime;
114
#else
115
    newlib_time_t    st_atime;
116
    newlib_long_t    st_spare1;
117
    newlib_time_t    st_mtime;
118
    newlib_long_t    st_spare2;
119
    newlib_time_t    st_ctime;
120
    newlib_long_t    st_spare3;
121
    newlib_long_t    st_blksize;
122
    newlib_long_t    st_blocks;
123
    newlib_long_t    st_spare4[2];
124
#endif
125
};
126
 
127
/* EXTERNS */
128
 
129
__externC char __remcomInBuffer[];  // from generic-stub.c, for packet data
130
__externC char __remcomOutBuffer[]; // ditto
131
 
132
/* STATICS/GLOBALS */
133
 
134
static int __fileio_retcode, __fileio_errno;
135
static cyg_bool __fileio_retcode_set, __fileio_errno_set, __fileio_ctrlc_set;
136
 
137
/* MACROS */
138
 
139
// endian independent conversion functions from big endian protocol types
140
// to newlib types
141
 
142
#define GDBFILEIO_FIO_TO_NEWLIB( _f, _n, _ftype )                  \
143
CYG_MACRO_START                                                    \
144
  char *_cf = (char *)(_f);                                        \
145
  int _i;                                                          \
146
  char _sign = 0;                                                  \
147
  if (*_cf == '-') {                                               \
148
      _sign = 1;                                                   \
149
      _cf++;                                                       \
150
  }                                                                \
151
  (_n) = 0;                                                        \
152
  for (_i=0; _i<sizeof(_ftype); _i++) {                            \
153
      (_n) = ((_n) << 8) | _cf[_i];                                \
154
  }                                                                \
155
  if (_sign)                                                       \
156
      (_n) = -(_n);                                                \
157
CYG_MACRO_END
158
 
159
#define GDBABS(_x_) (((_x_) < 0) ? (-(_x_)) : (_x_))
160
 
161
#define GDBFILEIO_NEWLIB_TO_FIO( _f, _n, _ftype )                  \
162
CYG_MACRO_START                                                    \
163
  char *_cf = (char *)(_f);                                        \
164
  int _i = 0;                                                      \
165
  if ((_n) < 0)                                                    \
166
    _cf[_i++] = '-';                                               \
167
  for (; _i<sizeof(_ftype); _i++) {                                \
168
      _cf[_i] = ((GDBABS(_n)) >> 8*(sizeof(_ftype)-_i-1)) & 0xff;  \
169
  }                                                                \
170
CYG_MACRO_END
171
 
172
 
173
/* FUNCTIONS */
174
 
175
#ifndef CYGINT_ISO_STRING_STRFUNCS
176
static size_t strlen( const char *s )
177
{
178
    size_t retval;
179
    const char *start = s;
180
    while (*s)
181
        s++;
182
    retval = s - start;
183
    return retval;
184
}
185
#endif
186
 
187
static int
188
chars_to_hex( char *charsin, char *hexout, int bytes )
189
{
190
    int numChars = 0;
191
    int allzero = true;
192
 
193
    while (bytes--) {
194
        if (0 != *charsin)
195
            allzero = false;
196
        *hexout++ = __tohex( (*charsin / 16) & 15 );
197
        *hexout++ = __tohex( (*charsin++) & 15 );
198
        numChars += 2;
199
    }
200
    if (allzero) // doesn't matter if we actually set more than needed above
201
        return (numChars > 2 ? 2 : numChars);
202
    return numChars;
203
}
204
 
205
static void
206
gdbfileio_fio_to_newlib_time_t( fio_time_t *f, newlib_time_t *n )
207
{
208
    GDBFILEIO_FIO_TO_NEWLIB( f, *n, fio_time_t );
209
} // gdbfileio_fio_to_newlib_time_t()
210
 
211
static void
212
gdbfileio_newlib_to_fio_int_t( newlib_int_t *n, fio_int_t *f )
213
{
214
    GDBFILEIO_NEWLIB_TO_FIO( f, *n, fio_int_t );
215
} // gdbfileio_newlib_to_fio_int_t()
216
 
217
static void
218
gdbfileio_newlib_to_fio_uint_t( newlib_uint_t *n, fio_uint_t *f )
219
{
220
    GDBFILEIO_NEWLIB_TO_FIO( f, *n, fio_uint_t );
221
} // gdbfileio_newlib_to_fio_uint_t()
222
 
223
static void
224
gdbfileio_fio_to_newlib_long_t( fio_long_t *f, newlib_long_t *n )
225
{
226
    GDBFILEIO_FIO_TO_NEWLIB( f, *n, fio_long_t );
227
} // gdbfileio_fio_to_newlib_long_t()
228
 
229
static void
230
gdbfileio_newlib_to_fio_long_t( newlib_long_t *n, fio_long_t *f )
231
{
232
    GDBFILEIO_NEWLIB_TO_FIO( f, *n, fio_long_t );
233
} // gdbfileio_newlib_to_fio_long_t()
234
 
235
static void
236
gdbfileio_fio_to_newlib_mode_t( fio_mode_t *f, newlib_mode_t *n )
237
{
238
    GDBFILEIO_FIO_TO_NEWLIB( f, *n, fio_mode_t );
239
} // gdbfileio_fio_to_newlib_mode_t()
240
 
241
static void
242
gdbfileio_newlib_to_fio_mode_t( newlib_mode_t *n, fio_mode_t *f )
243
{
244
    GDBFILEIO_NEWLIB_TO_FIO( f, *n, fio_mode_t );
245
} // gdbfileio_newlib_to_fio_mode_t()
246
 
247
static void
248
gdbfileio_fio_to_newlib_dev_t( fio_uint_t *f, newlib_dev_t *n )
249
{
250
    GDBFILEIO_FIO_TO_NEWLIB( f, *n, fio_uint_t );
251
} // gdbfileio_fio_to_newlib_dev_t()
252
 
253
static void
254
gdbfileio_fio_to_newlib_ino_t( fio_uint_t *f, newlib_ino_t *n )
255
{
256
    GDBFILEIO_FIO_TO_NEWLIB( f, *n, fio_uint_t );
257
} // gdbfileio_fio_to_newlib_ino_t()
258
 
259
// these defines are good enough for now (to save code size) as they
260
// are the same functions in practice
261
#define gdbfileio_fio_to_newlib_nlink_t gdbfileio_fio_to_newlib_ino_t
262
#define gdbfileio_fio_to_newlib_uid_t   gdbfileio_fio_to_newlib_ino_t
263
#define gdbfileio_fio_to_newlib_gid_t   gdbfileio_fio_to_newlib_ino_t
264
#define gdbfileio_fio_to_newlib_off_t   gdbfileio_fio_to_newlib_long_t
265
 
266
 
267
// this function is commonly used by most functions to handle everything
268
// once the packet has been constructed. It doesn't have to be used - it's
269
// just nice to keep this in one place for maintenance reasons.
270
static int
271
gdbfileio_common_sendpkt( char *buf, int *sig )
272
{
273
    int status;
274
 
275
    __putpacket( buf );
276
 
277
    do {
278
        __getpacket( __remcomInBuffer );
279
        status = __process_packet( __remcomInBuffer );
280
    } while ( status == 0 );
281
 
282
    if ( __fileio_ctrlc_set )
283
        *sig = SIGINT;
284
    if ( !__fileio_retcode_set ) // deal with protocol failure
285
        return -FILEIO_EINVAL;
286
    if ( __fileio_retcode < 0 && __fileio_errno_set )
287
        return -__fileio_errno;
288
    else
289
        return __fileio_retcode;
290
} // gdbfileio_common_sendpkt()
291
 
292
// deal with a received F packet. This is called from __process_packet in
293
// generic-stub.c
294
__externC void
295
cyg_hal_gdbfileio_process_F_packet( char *packet,
296
                    char *__remcomOutBuffer )
297
{
298
    // Reply packet structure:
299
    // F<retcode>[,<errno>[,<Ctrl-C flag>]][;<call specific attachment>]
300
 
301
    char *p = &packet[1];
302
    cyg_bool minus = false;
303
    target_register_t temptrt;
304
 
305
    __fileio_retcode_set = __fileio_errno_set = __fileio_ctrlc_set = false;
306
 
307
    if (*p == '-') {
308
        minus = true;
309
        p++;
310
    }
311
 
312
    __hexToInt( &p, &temptrt );
313
    __fileio_retcode = minus ? -(int)temptrt : (int)temptrt;
314
    __fileio_retcode_set = true;
315
 
316
    if ( *p++ == ',' ) {
317
        // get errno
318
        __hexToInt( &p, &temptrt );
319
        __fileio_errno = (int)temptrt;
320
        __fileio_errno_set = true;
321
        if ( *p++ == ',' ) {
322
            if ( *p == 'C' ) {
323
                __fileio_ctrlc_set = true;
324
            }
325
        }
326
    }
327
    // ignore anything afterwards (e.g. call specific attachment) for now
328
 
329
} // cyg_hal_gdbfileio_process_F_packet()
330
 
331
__externC int
332
cyg_hal_gdbfileio_open( const char *name, int flags, int mode, int *sig )
333
{
334
    size_t namelen;
335
    unsigned int i=0;
336
    fio_mode_t fmode;
337
    fio_int_t fflags;
338
 
339
    // clear out unsupported flags/modes, as per the spec
340
    flags &= FILEIO_O_SUPPORTED;
341
    mode &= FILEIO_S_SUPPORTED;
342
 
343
    gdbfileio_newlib_to_fio_int_t( &flags, &fflags );
344
    gdbfileio_newlib_to_fio_mode_t( &mode, &fmode );
345
 
346
    __remcomOutBuffer[i++] = 'F';
347
    __remcomOutBuffer[i++] = 'o';
348
    __remcomOutBuffer[i++] = 'p';
349
    __remcomOutBuffer[i++] = 'e';
350
    __remcomOutBuffer[i++] = 'n';
351
    __remcomOutBuffer[i++] = ',';
352
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)name,
353
                     sizeof(name)*8 );
354
    // i now points after the parameter
355
    __remcomOutBuffer[i++] = '/';
356
    namelen = strlen( name )+1; // includes '\0'
357
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
358
                     sizeof(namelen)*8 );
359
    __remcomOutBuffer[i++] = ',';
360
    i += chars_to_hex( (char *)&fflags, &__remcomOutBuffer[i], sizeof(fflags) );
361
    __remcomOutBuffer[i++] = ',';
362
    i += chars_to_hex( (char *)&fmode, &__remcomOutBuffer[i], sizeof(fmode) );
363
    __remcomOutBuffer[i] = 0;
364
 
365
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
366
} // cyg_hal_gdbfileio_open()
367
 
368
__externC int
369
cyg_hal_gdbfileio_close( int fd, int *sig )
370
{
371
    unsigned int i=0;
372
    fio_int_t ffd;
373
 
374
    gdbfileio_newlib_to_fio_int_t( &fd, &ffd );
375
    __remcomOutBuffer[i++] = 'F';
376
    __remcomOutBuffer[i++] = 'c';
377
    __remcomOutBuffer[i++] = 'l';
378
    __remcomOutBuffer[i++] = 'o';
379
    __remcomOutBuffer[i++] = 's';
380
    __remcomOutBuffer[i++] = 'e';
381
    __remcomOutBuffer[i++] = ',';
382
    i += chars_to_hex( (char *)&ffd, &__remcomOutBuffer[i], sizeof(ffd) );
383
    // i now points after the parameter
384
    __remcomOutBuffer[i] = 0;
385
 
386
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
387
} // cyg_hal_gdbfileio_close()
388
 
389
__externC int
390
cyg_hal_gdbfileio_read( int fd, void *buf, size_t count, int *sig )
391
{
392
    unsigned int i=0;
393
    fio_int_t ffd;
394
    fio_uint_t fcount;
395
    unsigned int uicount = (unsigned int)count;
396
 
397
    gdbfileio_newlib_to_fio_int_t( &fd, &ffd );
398
    gdbfileio_newlib_to_fio_uint_t( &uicount, &fcount );
399
 
400
    __remcomOutBuffer[i++] = 'F';
401
    __remcomOutBuffer[i++] = 'r';
402
    __remcomOutBuffer[i++] = 'e';
403
    __remcomOutBuffer[i++] = 'a';
404
    __remcomOutBuffer[i++] = 'd';
405
    __remcomOutBuffer[i++] = ',';
406
    i += chars_to_hex( (char *)&ffd, &__remcomOutBuffer[i], sizeof(ffd) );
407
    // i now points after the parameter
408
    __remcomOutBuffer[i++] = ',';
409
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)buf,
410
                     sizeof(buf)*8 );
411
    __remcomOutBuffer[i++] = ',';
412
    i += chars_to_hex( (char *)&fcount, &__remcomOutBuffer[i], sizeof(fcount) );
413
    __remcomOutBuffer[i] = 0;
414
 
415
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
416
} // cyg_hal_gdbfileio_read()
417
 
418
__externC int
419
cyg_hal_gdbfileio_write( int fd, const void *buf, size_t count, int *sig )
420
{
421
    unsigned int i=0;
422
    fio_int_t ffd;
423
    fio_uint_t fcount;
424
    unsigned int uicount = (unsigned int)count;
425
 
426
    gdbfileio_newlib_to_fio_int_t( &fd, &ffd );
427
    gdbfileio_newlib_to_fio_uint_t( &uicount, &fcount );
428
 
429
    __remcomOutBuffer[i++] = 'F';
430
    __remcomOutBuffer[i++] = 'w';
431
    __remcomOutBuffer[i++] = 'r';
432
    __remcomOutBuffer[i++] = 'i';
433
    __remcomOutBuffer[i++] = 't';
434
    __remcomOutBuffer[i++] = 'e';
435
    __remcomOutBuffer[i++] = ',';
436
    i += chars_to_hex( (char *)&ffd, &__remcomOutBuffer[i], sizeof(ffd) );
437
    // i now points after the parameter
438
    __remcomOutBuffer[i++] = ',';
439
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)buf,
440
                     sizeof(buf)*8 );
441
    __remcomOutBuffer[i++] = ',';
442
    i += chars_to_hex( (char *)&fcount, &__remcomOutBuffer[i], sizeof(fcount) );
443
    __remcomOutBuffer[i] = 0;
444
 
445
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
446
} // cyg_hal_gdbfileio_write()
447
 
448
__externC int
449
cyg_hal_gdbfileio_lseek( int fd, /* off_t */ long offset, int whence, int *sig )
450
{
451
    unsigned int i=0;
452
    fio_int_t ffd;
453
    fio_long_t foffset;
454
    fio_int_t fwhence;
455
 
456
    gdbfileio_newlib_to_fio_int_t( &fd, &ffd );
457
    gdbfileio_newlib_to_fio_long_t( &offset, &foffset );
458
    gdbfileio_newlib_to_fio_int_t( &whence, &fwhence );
459
 
460
    __remcomOutBuffer[i++] = 'F';
461
    __remcomOutBuffer[i++] = 'l';
462
    __remcomOutBuffer[i++] = 's';
463
    __remcomOutBuffer[i++] = 'e';
464
    __remcomOutBuffer[i++] = 'e';
465
    __remcomOutBuffer[i++] = 'k';
466
    __remcomOutBuffer[i++] = ',';
467
    i += chars_to_hex( (char *)&ffd, &__remcomOutBuffer[i], sizeof(ffd) );
468
    // i now points after the parameter
469
    __remcomOutBuffer[i++] = ',';
470
    i += chars_to_hex( (char *)&foffset, &__remcomOutBuffer[i],
471
                       sizeof(foffset) );
472
    __remcomOutBuffer[i++] = ',';
473
    i += chars_to_hex( (char *)&fwhence, &__remcomOutBuffer[i],
474
                       sizeof(fwhence) );
475
    __remcomOutBuffer[i] = 0;
476
 
477
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
478
} // cyg_hal_gdbfileio_lseek()
479
 
480
__externC int
481
cyg_hal_gdbfileio_rename( const char *oldpath, const char *newpath, int *sig )
482
{
483
    unsigned int i=0;
484
    size_t namelen;
485
 
486
    __remcomOutBuffer[i++] = 'F';
487
    __remcomOutBuffer[i++] = 'r';
488
    __remcomOutBuffer[i++] = 'e';
489
    __remcomOutBuffer[i++] = 'n';
490
    __remcomOutBuffer[i++] = 'a';
491
    __remcomOutBuffer[i++] = 'm';
492
    __remcomOutBuffer[i++] = 'e';
493
    __remcomOutBuffer[i++] = ',';
494
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)oldpath,
495
                     sizeof(oldpath)*8 );
496
    // i now points after the parameter
497
    __remcomOutBuffer[i++] = '/';
498
    namelen = strlen( oldpath )+1; // includes '\0'
499
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
500
                     sizeof(namelen)*8 );
501
    __remcomOutBuffer[i++] = ',';
502
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)newpath,
503
                     sizeof(newpath)*8 );
504
    // i now points after the parameter
505
    __remcomOutBuffer[i++] = '/';
506
    namelen = strlen( newpath )+1; // includes '\0'
507
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
508
                     sizeof(namelen)*8 );
509
    __remcomOutBuffer[i] = 0;
510
 
511
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
512
} // cyg_hal_gdbfileio_rename()
513
 
514
__externC int
515
cyg_hal_gdbfileio_unlink( const char *pathname, int *sig )
516
{
517
    unsigned int i=0;
518
    size_t namelen;
519
 
520
    __remcomOutBuffer[i++] = 'F';
521
    __remcomOutBuffer[i++] = 'u';
522
    __remcomOutBuffer[i++] = 'n';
523
    __remcomOutBuffer[i++] = 'l';
524
    __remcomOutBuffer[i++] = 'i';
525
    __remcomOutBuffer[i++] = 'n';
526
    __remcomOutBuffer[i++] = 'k';
527
    __remcomOutBuffer[i++] = ',';
528
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)pathname,
529
                     sizeof(pathname)*8 );
530
    // i now points after the parameter
531
    __remcomOutBuffer[i++] = '/';
532
    namelen = strlen( pathname )+1; // includes '\0'
533
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
534
                     sizeof(namelen)*8 );
535
    __remcomOutBuffer[i] = 0;
536
 
537
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
538
} // cyg_hal_gdbfileio_unlink()
539
 
540
__externC int
541
cyg_hal_gdbfileio_isatty( int fd, int *sig )
542
{
543
    unsigned int i=0;
544
    fio_int_t ffd;
545
 
546
    gdbfileio_newlib_to_fio_int_t( &fd, &ffd );
547
 
548
    __remcomOutBuffer[i++] = 'F';
549
    __remcomOutBuffer[i++] = 'i';
550
    __remcomOutBuffer[i++] = 's';
551
    __remcomOutBuffer[i++] = 'a';
552
    __remcomOutBuffer[i++] = 't';
553
    __remcomOutBuffer[i++] = 't';
554
    __remcomOutBuffer[i++] = 'y';
555
    __remcomOutBuffer[i++] = ',';
556
    i += chars_to_hex( (char *)&ffd, &__remcomOutBuffer[i], sizeof(ffd) );
557
    // i now points after the parameter
558
    __remcomOutBuffer[i] = 0;
559
 
560
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
561
} // cyg_hal_gdbfileio_isatty()
562
 
563
__externC int
564
cyg_hal_gdbfileio_system( const char *command, int *sig )
565
{
566
    unsigned int i=0;
567
    size_t namelen;
568
 
569
    __remcomOutBuffer[i++] = 'F';
570
    __remcomOutBuffer[i++] = 's';
571
    __remcomOutBuffer[i++] = 'y';
572
    __remcomOutBuffer[i++] = 's';
573
    __remcomOutBuffer[i++] = 't';
574
    __remcomOutBuffer[i++] = 'e';
575
    __remcomOutBuffer[i++] = 'm';
576
    __remcomOutBuffer[i++] = ',';
577
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)command,
578
                     sizeof(command)*8 );
579
    // i now points after the parameter
580
    __remcomOutBuffer[i++] = '/';
581
    namelen = strlen( command )+1; // includes '\0'
582
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
583
                     sizeof(namelen)*8 );
584
    __remcomOutBuffer[i] = 0;
585
 
586
    return gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
587
} // cyg_hal_gdbfileio_system()
588
 
589
__externC int
590
cyg_hal_gdbfileio_gettimeofday( void *tv, void *tz, int *sig )
591
{
592
    unsigned int i=0;
593
    struct newlib_timeval *ntv = (struct newlib_timeval *)tv;
594
    struct fio_timeval ftv;
595
    int rc;
596
 
597
    // protocol doesn't support non-null timezone. Just enforce it here.
598
    if (NULL != tz)
599
        return -FILEIO_EINVAL;
600
 
601
    __remcomOutBuffer[i++] = 'F';
602
    __remcomOutBuffer[i++] = 'g';
603
    __remcomOutBuffer[i++] = 'e';
604
    __remcomOutBuffer[i++] = 't';
605
    __remcomOutBuffer[i++] = 't';
606
    __remcomOutBuffer[i++] = 'i';
607
    __remcomOutBuffer[i++] = 'm';
608
    __remcomOutBuffer[i++] = 'e';
609
    __remcomOutBuffer[i++] = 'o';
610
    __remcomOutBuffer[i++] = 'f';
611
    __remcomOutBuffer[i++] = 'd';
612
    __remcomOutBuffer[i++] = 'a';
613
    __remcomOutBuffer[i++] = 'y';
614
    __remcomOutBuffer[i++] = ',';
615
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)&ftv,
616
                     sizeof(&ftv)*8 );
617
    __remcomOutBuffer[i++] = ',';
618
    __remcomOutBuffer[i++] = '0'; // tzptr
619
    __remcomOutBuffer[i] = 0;
620
 
621
    rc = gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
622
 
623
    // now ftv should have its contents filled
624
    gdbfileio_fio_to_newlib_time_t( &ftv.tv_sec, &ntv->tv_sec );
625
    gdbfileio_fio_to_newlib_long_t( &ftv.tv_usec, &ntv->tv_usec );
626
 
627
    return rc;
628
} // cyg_hal_gdbfileio_gettimeofday()
629
 
630
__externC int
631
cyg_hal_gdbfileio_stat( const char *pathname, struct newlib_stat *buf,
632
                        int *sig )
633
{
634
    unsigned int i=0;
635
    int rc;
636
    size_t namelen;
637
    struct fio_stat fbuf;
638
 
639
    __remcomOutBuffer[i++] = 'F';
640
    __remcomOutBuffer[i++] = 's';
641
    __remcomOutBuffer[i++] = 't';
642
    __remcomOutBuffer[i++] = 'a';
643
    __remcomOutBuffer[i++] = 't';
644
    __remcomOutBuffer[i++] = ',';
645
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)pathname,
646
                     sizeof(pathname)*8 );
647
    // i now points after the parameter
648
    __remcomOutBuffer[i++] = '/';
649
    namelen = strlen( pathname )+1; // includes '\0'
650
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)namelen,
651
                     sizeof(namelen)*8 );
652
    __remcomOutBuffer[i++] = ',';
653
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)&fbuf,
654
                     sizeof(&fbuf)*8 );
655
    __remcomOutBuffer[i] = 0;
656
 
657
    rc = gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
658
 
659
    // now fbuf should have its contents filled
660
    gdbfileio_fio_to_newlib_dev_t( &fbuf.st_dev, &buf->st_dev );
661
    gdbfileio_fio_to_newlib_ino_t( &fbuf.st_ino, &buf->st_ino );
662
    gdbfileio_fio_to_newlib_mode_t( &fbuf.st_mode, &buf->st_mode );
663
    gdbfileio_fio_to_newlib_nlink_t( &fbuf.st_nlink, &buf->st_nlink );
664
    gdbfileio_fio_to_newlib_uid_t( &fbuf.st_uid, &buf->st_uid );
665
    gdbfileio_fio_to_newlib_gid_t( &fbuf.st_gid, &buf->st_gid );
666
    gdbfileio_fio_to_newlib_dev_t( &fbuf.st_rdev, &buf->st_rdev );
667
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
668
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
669
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
670
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
671
#if !defined(__svr4__) || defined(__PPC__) || defined(__sun__)
672
    gdbfileio_fio_to_newlib_long_t( &fbuf.st_blksize, &buf->st_blksize );
673
    gdbfileio_fio_to_newlib_long_t( &fbuf.st_blocks, &buf->st_blocks );
674
#endif
675
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_atime, &buf->st_atime );
676
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_mtime, &buf->st_mtime );
677
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_ctime, &buf->st_ctime );
678
 
679
    return rc;
680
} // cyg_hal_gdbfileio_stat()
681
 
682
__externC int
683
cyg_hal_gdbfileio_fstat( int fd, struct newlib_stat *buf, int *sig )
684
{
685
    unsigned int i=0;
686
    int rc;
687
    struct fio_stat fbuf;
688
 
689
    __remcomOutBuffer[i++] = 'F';
690
    __remcomOutBuffer[i++] = 'f';
691
    __remcomOutBuffer[i++] = 's';
692
    __remcomOutBuffer[i++] = 't';
693
    __remcomOutBuffer[i++] = 'a';
694
    __remcomOutBuffer[i++] = 't';
695
    __remcomOutBuffer[i++] = ',';
696
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)fd,
697
                     sizeof(fd)*8 );
698
    // i now points after the parameter
699
    __remcomOutBuffer[i++] = ',';
700
    i += __intToHex( &__remcomOutBuffer[i], (target_register_t)&fbuf,
701
                     sizeof(&fbuf)*8 );
702
    __remcomOutBuffer[i] = 0;
703
 
704
    rc = gdbfileio_common_sendpkt( __remcomOutBuffer, sig );
705
 
706
    // now fbuf should have its contents filled
707
    gdbfileio_fio_to_newlib_dev_t( &fbuf.st_dev, &buf->st_dev );
708
    gdbfileio_fio_to_newlib_ino_t( &fbuf.st_ino, &buf->st_ino );
709
    gdbfileio_fio_to_newlib_mode_t( &fbuf.st_mode, &buf->st_mode );
710
    gdbfileio_fio_to_newlib_nlink_t( &fbuf.st_nlink, &buf->st_nlink );
711
    gdbfileio_fio_to_newlib_uid_t( &fbuf.st_uid, &buf->st_uid );
712
    gdbfileio_fio_to_newlib_gid_t( &fbuf.st_gid, &buf->st_gid );
713
    gdbfileio_fio_to_newlib_dev_t( &fbuf.st_rdev, &buf->st_rdev );
714
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
715
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
716
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
717
    gdbfileio_fio_to_newlib_off_t( &fbuf.st_size, &buf->st_size );
718
#if !defined(__svr4__) || defined(__PPC__) || defined(__sun__)
719
    gdbfileio_fio_to_newlib_long_t( &fbuf.st_blksize, &buf->st_blksize );
720
    gdbfileio_fio_to_newlib_long_t( &fbuf.st_blocks, &buf->st_blocks );
721
#endif
722
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_atime, &buf->st_atime );
723
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_mtime, &buf->st_mtime );
724
    gdbfileio_fio_to_newlib_time_t( &fbuf.st_ctime, &buf->st_ctime );
725
 
726
    return rc;
727
} // cyg_hal_gdbfileio_fstat()
728
 
729
/* EOF gdb-fileio.c */

powered by: WebSVN 2.1.0

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