mmap.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Derived from an old port of uC-libc to the i960 by Keith Adams (kma@cse.ogi.edu).
  20. #
  21. #include <sys/syscall.h>
  22. /* This is a plain system call. The 6 arguments are already set up correctly */
  23. /* void * mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset) */
  24. .globl _mmap
  25. _mmap:
  26. mov g13, r3
  27. ldconst __NR_mmap, g13
  28. calls 0
  29. mov r3, g13
  30. /* We now need to check if the return value is a small negative integer. */
  31. /* This is somewhat tricky as the return code (normally an address) is an */
  32. /* unsigned type, or an ordinal in i960 assembler. */
  33. /* We'll use the fact that, integers from -256 to -1 are ordinals 0xFFFFFF00 to 0xFFFFFFFF. */
  34. /* So by checking that the return address is in the top range of the ordinals, we'll */
  35. /* in fact be checking if it's not an encoded negated erro code. */
  36. /* The range -256 to -1 should be enough since that in uClinux 2.0.39, there are */
  37. /* 124 system calls for the i960. */
  38. ldconst 0xFFFFFF00, r3 /* This is the integer's -256 representation */
  39. cmpobl g0, r3, 1f /* Something smaller than this means it's out of the range, and a valid address */
  40. subi g0, 0, r3 /* If it's an errno, save its negated (now positive) value in _errno. */
  41. st r3, _errno
  42. subi 1, 0, g0 /* And return -1. */
  43. 1:
  44. ret