syscall.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* vi: set sw=4 ts=4: */
  2. /* syscall for arm/uClibc
  3. *
  4. * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Library General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <features.h>
  21. #include <errno.h>
  22. #include <sys/types.h>
  23. #include <sys/syscall.h>
  24. long syscall(long sysnum, long a, long b, long c, long d, long e, long f)
  25. {
  26. #if !defined(__thumb__)
  27. register long _r0 asm("r0")=(long)(sysnum);
  28. register long _r6 asm("r6")=(long)(f);
  29. register long _r5 asm("r5")=(long)(e);
  30. register long _r4 asm("r4")=(long)(d);
  31. register long _r3 asm("r3")=(long)(c);
  32. register long _r2 asm("r2")=(long)(b);
  33. register long _r1 asm("r1")=(long)(a);
  34. asm volatile(
  35. "swi %1"
  36. : "=r"(_r0)
  37. : "i"(__NR_syscall), "r"(_r0), "r"(_r1),
  38. "r"(_r2), "r"(_r3), "r"(_r4), "r"(_r5),
  39. "r"(_r6)
  40. : "memory");
  41. #else
  42. register long _r7 asm("r7")=(long)(sysnum);
  43. register long _r5 asm("r5")=(long)(f);
  44. register long _r4 asm("r4")=(long)(e);
  45. register long _r3 asm("r3")=(long)(d);
  46. register long _r2 asm("r2")=(long)(c);
  47. register long _r1 asm("r1")=(long)(b);
  48. register long _r0 asm("r0")=(long)(a);
  49. asm volatile(
  50. "swi 0"
  51. : "=r"(_r0)
  52. : "r"(_r0), "r"(_r1), "r"(_r2), "r"(_r3),
  53. "r"(_r4), "r"(_r5), "r"(_r7)
  54. : "memory");
  55. #endif
  56. if(_r0 >=(unsigned long) -4095) {
  57. long err = _r0;
  58. (*__errno_location())=(-err);
  59. _r0=(unsigned long) -1;
  60. }
  61. return (long) _r0;
  62. }