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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [common/] [current/] [src/] [gdb-fileio.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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