mmap.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # __mmap.S, part of the i960 support for the uClibc library.
  3. #
  4. # Copyright (C) 2002 by Okiok Data Ltd. http://www.okiok.com/
  5. #
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU Library General Public License as published by the Free
  8. # Software Foundation; either version 2 of the License, or (at your option) any
  9. # 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 FITNESS
  13. # FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  14. # 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, Inc.,
  18. # at 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # Derived from an old port of uC-libc to the i960 by Keith Adams (kma@cse.ogi.edu).
  21. #
  22. #include <sys/syscall.h>
  23. /* This is a plain system call. The 6 arguments are already set up correctly */
  24. /* void * mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset) */
  25. .globl _mmap
  26. _mmap:
  27. mov g13, r3
  28. ldconst __NR_mmap, g13
  29. calls 0
  30. mov r3, g13
  31. /* We now need to check if the return value is a small negative integer. */
  32. /* This is somewhat tricky as the return code (normally an address) is an */
  33. /* unsigned type, or an ordinal in i960 assembler. */
  34. /* We'll use the fact that, integers from -256 to -1 are ordinals 0xFFFFFF00 to 0xFFFFFFFF. */
  35. /* So by checking that the return address is in the top range of the ordinals, we'll */
  36. /* in fact be checking if it's not an encoded negated erro code. */
  37. /* The range -256 to -1 should be enough since that in uClinux 2.0.39, there are */
  38. /* 124 system calls for the i960. */
  39. ldconst 0xFFFFFF00, r3 /* This is the integer's -256 representation */
  40. cmpobl g0, r3, 1f /* Something smaller than this means it's out of the range, and a valid address */
  41. subi g0, 0, r3 /* If it's an errno, save its negated (now positive) value in _errno. */
  42. st r3, _errno
  43. subi 1, 0, g0 /* And return -1. */
  44. 1:
  45. ret