[patch] libgloss: bfin: implement getpid/fstat/stat/link/unlink syscalls

Mike Frysinger vapier@gentoo.org
Tue Jul 5 15:40:00 GMT 2011


The current syscalls.c implements getpid/fstat/stat/link/unlink as
mere stubs.  So replace them with useful calls to do_syscall now that
our sim can support them.

Committed.
-mike

2011-07-01  Mike Frysinger  <vapier@gentoo.org>

    * bfin/syscalls.c (_getpid): Call do_syscall with func argument n and
    return the result.
    (_fstat): Delete stub body.  Add block array and assign file/st to it.
    Call do_syscall with result.
    (_stat): Delete stub body.  Add block array and assign fname/st to
    it.  Call do_syscall with result.
    (_link): Change func arguments to accept two strings.  Add block array
    and assign existing/new to it.  Call do_syscall with result.
    (_unlink): Change func arguments to accept a string.  Call do_syscall
    with new argument.

--- libgloss/bfin/syscalls.c
+++ libgloss/bfin/syscalls.c
@@ -117,7 +117,7 @@ _kill (int n, int m)
 int
 _getpid (int n)
 {
-  return 1;
+  return do_syscall (SYS_getpid, &n);
 }

 caddr_t
@@ -156,40 +156,41 @@ _sbrk (int incr)
 extern void memset (struct stat *, int, unsigned int);

 int
-_fstat (int file, struct stat * st)
+_fstat (int file, struct stat *st)
 {
-  memset (st, 0, sizeof (* st));
-  st->st_mode = S_IFCHR;
-  st->st_blksize = 1024;
-  return 0;
+  int block[2];
+
+  block[0] = file;
+  block[1] = (int) st;
+
+  return do_syscall (SYS_fstat, block);
 }

 int _stat (const char *fname, struct stat *st)
 {
-  int file;
+  int block[2];

-  /* The best we can do is try to open the file readonly.  If it exists,
-     then we can guess a few things about it.  */
-  if ((file = _open (fname, O_RDONLY)) < 0)
-    return -1;
-
-  memset (st, 0, sizeof (* st));
-  st->st_mode = S_IFREG | S_IREAD;
-  st->st_blksize = 1024;
-  _close (file); /* Not interested in the error.  */
-  return 0;
+  block[0] = (int) fname;
+  block[1] = (int) st;
+
+  return do_syscall (SYS_stat, block);
 }

 int
-_link (void)
+_link (const char *existing, const char *new)
 {
-  return -1;
+  int block[2];
+
+  block[0] = (int) existing;
+  block[1] = (int) new;
+
+  return do_syscall (SYS_link, block);
 }

 int
-_unlink (void)
+_unlink (const char *path)
 {
-  return -1;
+  return do_syscall (SYS_unlink, path);
 }

 void



More information about the Newlib mailing list