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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [libgloss/] [arm/] [syscalls.c] - Blame information for rev 300

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Support files for GNU libc.  Files in the system namespace go here.
2
   Files in the C namespace (ie those that do not start with an
3
   underscore) go in .c.  */
4
 
5
#include <_ansi.h>
6
#include <sys/types.h>
7
#include <sys/stat.h>
8
#include <sys/fcntl.h>
9
#include <stdio.h>
10
#include <string.h>
11
#include <time.h>
12
#include <sys/time.h>
13
#include <sys/times.h>
14
#include <errno.h>
15
#include <reent.h>
16
#include <unistd.h>
17
#include <sys/wait.h>
18
#include "swi.h"
19
 
20
/* Forward prototypes.  */
21
int     _system     _PARAMS ((const char *));
22
int     _rename     _PARAMS ((const char *, const char *));
23
int     _isatty         _PARAMS ((int));
24
clock_t _times          _PARAMS ((struct tms *));
25
int     _gettimeofday   _PARAMS ((struct timeval *, void *));
26
int     _unlink         _PARAMS ((const char *));
27
int     _link           _PARAMS ((void));
28
int     _stat           _PARAMS ((const char *, struct stat *));
29
int     _fstat          _PARAMS ((int, struct stat *));
30
int     _swistat        _PARAMS ((int fd, struct stat * st));
31
caddr_t _sbrk           _PARAMS ((int));
32
int     _getpid         _PARAMS ((int));
33
int     _close          _PARAMS ((int));
34
clock_t _clock          _PARAMS ((void));
35
int     _swiclose       _PARAMS ((int));
36
int     _open           _PARAMS ((const char *, int, ...));
37
int     _swiopen        _PARAMS ((const char *, int));
38
int     _write          _PARAMS ((int, char *, int));
39
int     _swiwrite       _PARAMS ((int, char *, int));
40
int     _lseek          _PARAMS ((int, int, int));
41
int     _swilseek       _PARAMS ((int, int, int));
42
int     _read           _PARAMS ((int, char *, int));
43
int     _swiread        _PARAMS ((int, char *, int));
44
void    initialise_monitor_handles _PARAMS ((void));
45
 
46
static int      checkerror      _PARAMS ((int));
47
static int      error           _PARAMS ((int));
48
static int      get_errno       _PARAMS ((void));
49
 
50
/* Struct used to keep track of the file position, just so we
51
   can implement fseek(fh,x,SEEK_CUR).  */
52
struct fdent
53
{
54
  int handle;
55
  int pos;
56
};
57
 
58
#define MAX_OPEN_FILES 20
59
 
60
/* User file descriptors (fd) are integer indexes into
61
   the openfiles[] array. Error checking is done by using
62
   findslot().
63
 
64
   This openfiles array is manipulated directly by only
65
   these 5 functions:
66
 
67
        findslot() - Translate entry.
68
        newslot() - Find empty entry.
69
        initilise_monitor_handles() - Initialize entries.
70
        _swiopen() - Initialize entry.
71
        _close() - Handle stdout == stderr case.
72
 
73
   Every other function must use findslot().  */
74
 
75
static struct fdent openfiles [MAX_OPEN_FILES];
76
 
77
static struct fdent*    findslot        _PARAMS ((int));
78
static int              newslot         _PARAMS ((void));
79
 
80
/* Register name faking - works in collusion with the linker.  */
81
register char * stack_ptr asm ("sp");
82
 
83
 
84
/* following is copied from libc/stdio/local.h to check std streams */
85
extern void   _EXFUN(__sinit,(struct _reent *));
86
#define CHECK_INIT(ptr) \
87
  do                                            \
88
    {                                           \
89
      if ((ptr) && !(ptr)->__sdidinit)          \
90
        __sinit (ptr);                          \
91
    }                                           \
92
  while (0)
93
 
94
static int monitor_stdin;
95
static int monitor_stdout;
96
static int monitor_stderr;
97
 
98
/* Return a pointer to the structure associated with
99
   the user file descriptor fd. */
100
static struct fdent*
101
findslot (int fd)
102
{
103
  CHECK_INIT(_REENT);
104
 
105
  /* User file descriptor is out of range. */
106
  if ((unsigned int)fd >= MAX_OPEN_FILES)
107
    return NULL;
108
 
109
  /* User file descriptor is open? */
110
  if (openfiles[fd].handle == -1)
111
    return NULL;
112
 
113
  /* Valid. */
114
  return &openfiles[fd];
115
}
116
 
117
/* Return the next lowest numbered free file
118
   structure, or -1 if we can't find one. */
119
static int
120
newslot (void)
121
{
122
  int i;
123
 
124
  for (i = 0; i < MAX_OPEN_FILES; i++)
125
    if (openfiles[i].handle == -1)
126
      break;
127
 
128
  if (i == MAX_OPEN_FILES)
129
    return -1;
130
 
131
  return i;
132
}
133
 
134
void
135
initialise_monitor_handles (void)
136
{
137
  int i;
138
 
139
  /* Open the standard file descriptors by opening the special
140
   * teletype device, ":tt", read-only to obtain a descritpor for
141
   * standard input and write-only to obtain a descriptor for standard
142
   * output. Finally, open ":tt" in append mode to obtain a descriptor
143
   * for standard error. Since this is a write mode, most kernels will
144
   * probably return the same value as for standard output, but the
145
   * kernel can differentiate the two using the mode flag and return a
146
   * different descriptor for standard error.
147
   */
148
 
149
#ifdef ARM_RDI_MONITOR
150
  int volatile block[3];
151
 
152
  block[0] = (int) ":tt";
153
  block[2] = 3;     /* length of filename */
154
  block[1] = 0;     /* mode "r" */
155
  monitor_stdin = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
156
 
157
  block[0] = (int) ":tt";
158
  block[2] = 3;     /* length of filename */
159
  block[1] = 4;     /* mode "w" */
160
  monitor_stdout = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
161
 
162
  block[0] = (int) ":tt";
163
  block[2] = 3;     /* length of filename */
164
  block[1] = 8;     /* mode "a" */
165
  monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
166
#else
167
  int fh;
168
  const char * name;
169
 
170
  name = ":tt";
171
  asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
172
       : "=r"(fh)
173
       : "i" (SWI_Open),"r"(name)
174
       : "r0","r1");
175
  monitor_stdin = fh;
176
 
177
  name = ":tt";
178
  asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
179
       : "=r"(fh)
180
       : "i" (SWI_Open),"r"(name)
181
       : "r0","r1");
182
  monitor_stdout = fh;
183
 
184
  name = ":tt";
185
  asm ("mov r0,%2; mov r1, #8; swi %a1; mov %0, r0"
186
       : "=r"(fh)
187
       : "i" (SWI_Open),"r"(name)
188
       : "r0","r1");
189
  monitor_stderr = fh;
190
#endif
191
 
192
  /* If we failed to open stderr, redirect to stdout. */
193
  if (monitor_stderr == -1)
194
    monitor_stderr = monitor_stdout;
195
 
196
  for (i = 0; i < MAX_OPEN_FILES; i ++)
197
    openfiles[i].handle = -1;
198
 
199
  openfiles[0].handle = monitor_stdin;
200
  openfiles[0].pos = 0;
201
  openfiles[1].handle = monitor_stdout;
202
  openfiles[1].pos = 0;
203
  openfiles[2].handle = monitor_stderr;
204
  openfiles[2].pos = 0;
205
}
206
 
207
static int
208
get_errno (void)
209
{
210
#ifdef ARM_RDI_MONITOR
211
  return do_AngelSWI (AngelSWI_Reason_Errno, NULL);
212
#else
213
  register r0 asm("r0");
214
  asm ("swi %a1" : "=r"(r0) : "i" (SWI_GetErrno));
215
  return r0;
216
#endif
217
}
218
 
219
/* Set errno and return result. */
220
static int
221
error (int result)
222
{
223
  errno = get_errno ();
224
  return result;
225
}
226
 
227
/* Check the return and set errno appropriately. */
228
static int
229
checkerror (int result)
230
{
231
  if (result == -1)
232
    return error (-1);
233
  return result;
234
}
235
 
236
/* fh, is a valid internal file handle.
237
   ptr, is a null terminated string.
238
   len, is the length in bytes to read.
239
   Returns the number of bytes *not* written. */
240
int
241
_swiread (int fh,
242
          char * ptr,
243
          int len)
244
{
245
#ifdef ARM_RDI_MONITOR
246
  int block[3];
247
 
248
  block[0] = fh;
249
  block[1] = (int) ptr;
250
  block[2] = len;
251
 
252
  return checkerror (do_AngelSWI (AngelSWI_Reason_Read, block));
253
#else
254
  register r0 asm("r0");
255
  register r1 asm("r1");
256
  register r2 asm("r2");
257
  r0 = fh;
258
  r1 = (int)ptr;
259
  r2 = len;
260
  asm ("swi %a4"
261
       : "=r" (r0)
262
       : "0"(r0), "r"(r1), "r"(r2), "i"(SWI_Read));
263
  return checkerror (r0);
264
#endif
265
}
266
 
267
/* fd, is a valid user file handle.
268
   Translates the return of _swiread into
269
   bytes read. */
270
int
271
_read (int fd,
272
       char * ptr,
273
       int len)
274
{
275
  int res;
276
  struct fdent *pfd;
277
 
278
  pfd = findslot (fd);
279
  if (pfd == NULL)
280
    {
281
      errno = EBADF;
282
      return -1;
283
    }
284
 
285
  res = _swiread (pfd->handle, ptr, len);
286
 
287
  if (res == -1)
288
    return res;
289
 
290
  pfd->pos += len - res;
291
 
292
  /* res == len is not an error,
293
     at least if we want feof() to work.  */
294
  return len - res;
295
}
296
 
297
/* fd, is a user file descriptor. */
298
int
299
_swilseek (int fd,
300
        int ptr,
301
        int dir)
302
{
303
  int res;
304
  struct fdent *pfd;
305
 
306
  /* Valid file descriptor? */
307
  pfd = findslot (fd);
308
  if (pfd == NULL)
309
    {
310
      errno = EBADF;
311
      return -1;
312
    }
313
 
314
  /* Valid whence? */
315
  if ((dir != SEEK_CUR)
316
      && (dir != SEEK_SET)
317
      && (dir != SEEK_END))
318
    {
319
      errno = EINVAL;
320
      return -1;
321
    }
322
 
323
  /* Convert SEEK_CUR to SEEK_SET */
324
  if (dir == SEEK_CUR)
325
    {
326
      ptr = pfd->pos + ptr;
327
      /* The resulting file offset would be negative. */
328
      if (ptr < 0)
329
        {
330
          errno = EINVAL;
331
          if ((pfd->pos > 0) && (ptr > 0))
332
            errno = EOVERFLOW;
333
          return -1;
334
        }
335
      dir = SEEK_SET;
336
    }
337
 
338
#ifdef ARM_RDI_MONITOR
339
  int block[2];
340
  if (dir == SEEK_END)
341
    {
342
      block[0] = pfd->handle;
343
      res = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, block));
344
      if (res == -1)
345
        return -1;
346
      ptr += res;
347
    }
348
 
349
  /* This code only does absolute seeks.  */
350
  block[0] = pfd->handle;
351
  block[1] = ptr;
352
  res = checkerror (do_AngelSWI (AngelSWI_Reason_Seek, block));
353
#else
354
  if (dir == SEEK_END)
355
    {
356
      asm ("mov r0, %2; swi %a1; mov %0, r0"
357
           : "=r" (res)
358
           : "i" (SWI_Flen), "r" (pfd->handle)
359
           : "r0");
360
      checkerror (res);
361
      if (res == -1)
362
        return -1;
363
      ptr += res;
364
    }
365
 
366
  /* This code only does absolute seeks.  */
367
  asm ("mov r0, %2; mov r1, %3; swi %a1; mov %0, r0"
368
       : "=r" (res)
369
       : "i" (SWI_Seek), "r" (pfd->handle), "r" (ptr)
370
       : "r0", "r1");
371
  checkerror (res);
372
#endif
373
  /* At this point ptr is the current file position. */
374
  if (res >= 0)
375
    {
376
      pfd->pos = ptr;
377
      return ptr;
378
    }
379
  else
380
    return -1;
381
}
382
 
383
_lseek (int fd,
384
        int ptr,
385
        int dir)
386
{
387
  return _swilseek (fd, ptr, dir);
388
}
389
 
390
/* fh, is a valid internal file handle.
391
   Returns the number of bytes *not* written. */
392
int
393
_swiwrite (
394
           int    fh,
395
           char * ptr,
396
           int    len)
397
{
398
#ifdef ARM_RDI_MONITOR
399
  int block[3];
400
 
401
  block[0] = fh;
402
  block[1] = (int) ptr;
403
  block[2] = len;
404
 
405
  return checkerror (do_AngelSWI (AngelSWI_Reason_Write, block));
406
#else
407
  register r0 asm("r0");
408
  register r1 asm("r1");
409
  register r2 asm("r2");
410
  r0 = fh;
411
  r1 = (int)ptr;
412
  r2 = len;
413
  asm ("swi %a4"
414
       : "=r" (r0)
415
       : "0"(r0), "r"(r1), "r"(r2), "i"(SWI_Write));
416
  return checkerror (r0);
417
#endif
418
}
419
 
420
/* fd, is a user file descriptor. */
421
int
422
_write (int    fd,
423
        char * ptr,
424
        int    len)
425
{
426
  int res;
427
  struct fdent *pfd;
428
 
429
  pfd = findslot (fd);
430
  if (pfd == NULL)
431
    {
432
      errno = EBADF;
433
      return -1;
434
    }
435
 
436
  res = _swiwrite (pfd->handle, ptr,len);
437
 
438
  /* Clearly an error. */
439
  if (res < 0)
440
    return -1;
441
 
442
  pfd->pos += len - res;
443
 
444
  /* We wrote 0 bytes?
445
     Retrieve errno just in case. */
446
  if ((len - res) == 0)
447
    return error (0);
448
 
449
  return (len - res);
450
}
451
 
452
int
453
_swiopen (const char * path, int flags)
454
{
455
  int aflags = 0, fh;
456
#ifdef ARM_RDI_MONITOR
457
  int block[3];
458
#endif
459
 
460
  int fd = newslot ();
461
 
462
  if (fd == -1)
463
    {
464
      errno = EMFILE;
465
      return -1;
466
    }
467
 
468
  /* It is an error to open a file that already exists. */
469
  if ((flags & O_CREAT)
470
      && (flags & O_EXCL))
471
    {
472
      struct stat st;
473
      int res;
474
      res = _stat (path, &st);
475
      if (res != -1)
476
        {
477
          errno = EEXIST;
478
          return -1;
479
        }
480
    }
481
 
482
  /* The flags are Unix-style, so we need to convert them. */
483
#ifdef O_BINARY
484
  if (flags & O_BINARY)
485
    aflags |= 1;
486
#endif
487
 
488
  /* In O_RDONLY we expect aflags == 0. */
489
 
490
  if (flags & O_RDWR)
491
    aflags |= 2;
492
 
493
  if ((flags & O_CREAT)
494
      || (flags & O_TRUNC)
495
      || (flags & O_WRONLY))
496
    aflags |= 4;
497
 
498
  if (flags & O_APPEND)
499
    {
500
      /* Can't ask for w AND a; means just 'a'.  */
501
      aflags &= ~4;
502
      aflags |= 8;
503
    }
504
 
505
#ifdef ARM_RDI_MONITOR
506
  block[0] = (int) path;
507
  block[2] = strlen (path);
508
  block[1] = aflags;
509
 
510
  fh = do_AngelSWI (AngelSWI_Reason_Open, block);
511
 
512
#else
513
  asm ("mov r0,%2; mov r1, %3; swi %a1; mov %0, r0"
514
       : "=r"(fh)
515
       : "i" (SWI_Open),"r"(path),"r"(aflags)
516
       : "r0","r1");
517
#endif
518
 
519
  /* Return a user file descriptor or an error. */
520
  if (fh >= 0)
521
    {
522
      openfiles[fd].handle = fh;
523
      openfiles[fd].pos = 0;
524
      return fd;
525
    }
526
  else
527
    return error (fh);
528
}
529
 
530
int
531
_open (const char * path, int flags, ...)
532
{
533
  return _swiopen (path, flags);
534
}
535
 
536
/* fh, is a valid internal file handle. */
537
int
538
_swiclose (int fh)
539
{
540
#ifdef ARM_RDI_MONITOR
541
  return checkerror (do_AngelSWI (AngelSWI_Reason_Close, &fh));
542
#else
543
  register r0 asm("r0");
544
  r0 = fh;
545
  asm ("swi %a2"
546
       : "=r"(r0)
547
       : "0"(r0), "i" (SWI_Close));
548
  return checkerror (r0);
549
#endif
550
}
551
 
552
/* fd, is a user file descriptor. */
553
int
554
_close (int fd)
555
{
556
  int res;
557
  struct fdent *pfd;
558
 
559
  pfd = findslot (fd);
560
  if (pfd == NULL)
561
    {
562
      errno = EBADF;
563
      return -1;
564
    }
565
 
566
  /* Handle stderr == stdout. */
567
  if ((fd == 1 || fd == 2)
568
      && (openfiles[1].handle == openfiles[2].handle))
569
    {
570
      pfd->handle = -1;
571
      return 0;
572
    }
573
 
574
  /* Attempt to close the handle. */
575
  res = _swiclose (pfd->handle);
576
 
577
  /* Reclaim handle? */
578
  if (res == 0)
579
    pfd->handle = -1;
580
 
581
  return res;
582
}
583
 
584
int __attribute__((weak))
585
_getpid (int n __attribute__ ((unused)))
586
{
587
  return 1;
588
}
589
 
590
caddr_t
591
_sbrk (int incr)
592
{
593
  extern char end asm ("end"); /* Defined by the linker.  */
594
  static char * heap_end;
595
  char * prev_heap_end;
596
 
597
  if (heap_end == NULL)
598
    heap_end = & end;
599
 
600
  prev_heap_end = heap_end;
601
 
602
  if (heap_end + incr > stack_ptr)
603
    {
604
      /* Some of the libstdc++-v3 tests rely upon detecting
605
         out of memory errors, so do not abort here.  */
606
#if 0
607
      extern void abort (void);
608
 
609
      _write (1, "_sbrk: Heap and stack collision\n", 32);
610
 
611
      abort ();
612
#else
613
      errno = ENOMEM;
614
      return (caddr_t) -1;
615
#endif
616
    }
617
 
618
  heap_end += incr;
619
 
620
  return (caddr_t) prev_heap_end;
621
}
622
 
623
int
624
_swistat (int fd, struct stat * st)
625
{
626
  struct fdent *pfd;
627
  int res;
628
 
629
  pfd = findslot (fd);
630
  if (pfd == NULL)
631
    {
632
      errno = EBADF;
633
      return -1;
634
    }
635
 
636
  /* Always assume a character device,
637
     with 1024 byte blocks. */
638
  st->st_mode |= S_IFCHR;
639
  st->st_blksize = 1024;
640
#ifdef ARM_RDI_MONITOR
641
  res = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &pfd->handle));
642
#else
643
  asm ("mov r0, %2; swi %a1; mov %0, r0"
644
       : "=r" (res)
645
       : "i" (SWI_Flen), "r" (pfd->handle)
646
       : "r0");
647
  checkerror (res);
648
#endif
649
  if (res == -1)
650
    return -1;
651
  /* Return the file size. */
652
  st->st_size = res;
653
  return 0;
654
}
655
 
656
int __attribute__((weak))
657
_fstat (int fd, struct stat * st)
658
{
659
  memset (st, 0, sizeof (* st));
660
  return _swistat (fd, st);
661
}
662
 
663
int __attribute__((weak))
664
_stat (const char *fname, struct stat *st)
665
{
666
  int fd, res;
667
  memset (st, 0, sizeof (* st));
668
  /* The best we can do is try to open the file readonly.
669
     If it exists, then we can guess a few things about it. */
670
  if ((fd = _open (fname, O_RDONLY)) == -1)
671
    return -1;
672
  st->st_mode |= S_IFREG | S_IREAD;
673
  res = _swistat (fd, st);
674
  /* Not interested in the error. */
675
  _close (fd);
676
  return res;
677
}
678
 
679
int __attribute__((weak))
680
_link (void)
681
{
682
  errno = ENOSYS;
683
  return -1;
684
}
685
 
686
int
687
_unlink (const char *path)
688
{
689
  int res;
690
#ifdef ARM_RDI_MONITOR
691
  int block[2];
692
  block[0] = (int)path;
693
  block[1] = strlen(path);
694
  res = do_AngelSWI (AngelSWI_Reason_Remove, block);
695
#else
696
  register r0 asm("r0");
697
  r0 = (int)path;
698
  asm ("swi %a2"
699
       : "=r"(r0)
700
       : "0"(r0), "i" (SWI_Remove));
701
  res = r0;
702
#endif
703
  if (res == -1)
704
    return error (res);
705
  return 0;
706
}
707
 
708
int
709
_gettimeofday (struct timeval * tp, void * tzvp)
710
{
711
  struct timezone *tzp = tzvp;
712
  if (tp)
713
    {
714
    /* Ask the host for the seconds since the Unix epoch.  */
715
#ifdef ARM_RDI_MONITOR
716
      tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL);
717
#else
718
      {
719
        int value;
720
        asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
721
        tp->tv_sec = value;
722
      }
723
#endif
724
      tp->tv_usec = 0;
725
    }
726
 
727
  /* Return fixed data for the timezone.  */
728
  if (tzp)
729
    {
730
      tzp->tz_minuteswest = 0;
731
      tzp->tz_dsttime = 0;
732
    }
733
 
734
  return 0;
735
}
736
 
737
/* Return a clock that ticks at 100Hz.  */
738
clock_t
739
_clock (void)
740
{
741
  clock_t timeval;
742
 
743
#ifdef ARM_RDI_MONITOR
744
  timeval = do_AngelSWI (AngelSWI_Reason_Clock,NULL);
745
#else
746
  asm ("swi %a1; mov %0, r0" : "=r" (timeval): "i" (SWI_Clock) : "r0");
747
#endif
748
  return timeval;
749
}
750
 
751
/* Return a clock that ticks at 100Hz.  */
752
clock_t
753
_times (struct tms * tp)
754
{
755
  clock_t timeval = _clock();
756
 
757
  if (tp)
758
    {
759
      tp->tms_utime  = timeval; /* user time */
760
      tp->tms_stime  = 0;        /* system time */
761
      tp->tms_cutime = 0;        /* user time, children */
762
      tp->tms_cstime = 0;        /* system time, children */
763
    }
764
 
765
  return timeval;
766
};
767
 
768
 
769
int
770
_isatty (int fd)
771
{
772
  struct fdent *pfd;
773
 
774
  pfd = findslot (fd);
775
  if (pfd == NULL)
776
    {
777
      errno = EBADF;
778
      return -1;
779
    }
780
 
781
#ifdef ARM_RDI_MONITOR
782
  return checkerror (do_AngelSWI (AngelSWI_Reason_IsTTY, &pfd->handle));
783
#else
784
  register r0 asm("r0");
785
  r0 = pfd->handle;
786
  asm ("swi %a2"
787
       : "=r" (r0)
788
       : "0"(r0), "i" (SWI_IsTTY));
789
  return checkerror (r0);
790
#endif
791
}
792
 
793
int
794
_system (const char *s)
795
{
796
#ifdef ARM_RDI_MONITOR
797
  int block[2];
798
  int e;
799
 
800
  /* Hmmm.  The ARM debug interface specification doesn't say whether
801
     SYS_SYSTEM does the right thing with a null argument, or assign any
802
     meaning to its return value.  Try to do something reasonable....  */
803
  if (!s)
804
    return 1;  /* maybe there is a shell available? we can hope. :-P */
805
  block[0] = (int)s;
806
  block[1] = strlen (s);
807
  e = checkerror (do_AngelSWI (AngelSWI_Reason_System, block));
808
  if ((e >= 0) && (e < 256))
809
    {
810
      /* We have to convert e, an exit status to the encoded status of
811
         the command.  To avoid hard coding the exit status, we simply
812
         loop until we find the right position.  */
813
      int exit_code;
814
 
815
      for (exit_code = e; e && WEXITSTATUS (e) != exit_code; e <<= 1)
816
        continue;
817
    }
818
  return e;
819
#else
820
  register r0 asm("r0");
821
  r0 = (int)s;
822
  asm ("swi %a2"
823
       : "=r" (r0)
824
       : "0"(r0), "i" (SWI_CLI));
825
  return checkerror (r0);
826
#endif
827
}
828
 
829
int
830
_rename (const char * oldpath, const char * newpath)
831
{
832
#ifdef ARM_RDI_MONITOR
833
  int block[4];
834
  block[0] = (int)oldpath;
835
  block[1] = strlen(oldpath);
836
  block[2] = (int)newpath;
837
  block[3] = strlen(newpath);
838
  return checkerror (do_AngelSWI (AngelSWI_Reason_Rename, block)) ? -1 : 0;
839
#else
840
  register r0 asm("r0");
841
  register r1 asm("r1");
842
  r0 = (int)oldpath;
843
  r1 = (int)newpath;
844
  asm ("swi %a3"
845
       : "=r" (r0)
846
       : "0" (r0), "r" (r1), "i" (SWI_Rename));
847
  return checkerror (r0);
848
#endif
849
}

powered by: WebSVN 2.1.0

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