home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / elf / d-link / i386 / syscall.h < prev   
Encoding:
C/C++ Source or Header  |  1994-11-27  |  5.4 KB  |  202 lines

  1.  
  2. extern inline volatile void _dl_exit(int status);
  3. extern inline volatile void _dl_close(int fd);
  4. extern inline int _dl_mmap(void * addr, unsigned int size,
  5.                     unsigned int prot,
  6.                     unsigned int flags, int fd,
  7.                     unsigned int f_offset);
  8. #ifndef _dl_MAX_ERRNO
  9. #define _dl_MAX_ERRNO 4096
  10. #endif
  11. #define _dl_mmap_check_error(__res)    \
  12.     (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO)
  13. extern inline int _dl_open(char * addr, unsigned int flags);
  14. extern inline int _dl_write(int fd, const char * buf, int len);
  15. extern inline int _dl_read(int fd, const char * buf, int len);
  16. extern inline int _dl_mprotect(const char * addr, int size, int prot);
  17.  
  18. /* Here are the definitions for a bunch of syscalls that are required
  19.    by the dynamic linker.  The idea is that we want to be able
  20.    to call these before the errno symbol is dynamicly linked, so
  21.    we use our own version here.  Note that we cannot assume any
  22.    dynamic linking at all, so we cannot return any error codes.
  23.    We just punt if there is an error. */
  24.  
  25. extern inline volatile void _dl_exit(int status)
  26. {
  27.   int __res;
  28. #ifdef IBCS_COMPATIBLE
  29.   __asm__ volatile ("pushl %0\n\tpushl $0\n\tmovl %1,%%eax\n\t" \
  30.             "lcall $7,$0" : : "r" (status), "a" (__IBCS_exit));
  31. #else
  32.   __asm__ volatile ("movl %%ecx,%%ebx\n"\
  33.             "int $0x80" \
  34.             :  "=a" (__res) : "0" (__NR_exit),"c" ((long)(status)));
  35. #endif
  36. }
  37.  
  38. extern inline volatile void _dl_close(int fd)
  39. {
  40.     int status;
  41.  
  42. #ifdef IBCS_COMPATIBLE
  43.     __asm__ volatile ("pushl %1\n\t" \
  44.         "pushl $0\n\t" \
  45.         "movl %2,%%eax\n\t" \
  46.         "lcall $7,$0\n\t" \
  47.         "jnb .+4\n\t" \
  48.         "xor %%eax, %%eax\n\t" \
  49.         "addl $8,%%esp\n\t" \
  50.         : "=a" (status) : "r" (fd), "a" (__IBCS_close));
  51. #else
  52.   __asm__ volatile ("pushl %%ebx\n"\
  53.             "movl %%ecx,%%ebx\n"\
  54.             "int $0x80\n" \
  55.             "popl %%ebx\n"\
  56.             : "=a" (status) \
  57.             : "0" (__NR_close),"c" ((long)(fd)));
  58.     
  59. #endif
  60. }
  61.  
  62. extern inline int _dl_mmap(void * addr, unsigned int size,
  63.                     unsigned int prot,
  64.                     unsigned int flags, int fd,
  65.                     unsigned int f_offset)
  66. {
  67.   int malloc_buffer;
  68. #ifdef IBCS_COMPATIBLE
  69.   __asm__ volatile ("pushl %7\n\t" \
  70.             "pushl %6\n\t" \
  71.             "pushl %5\n\t" \
  72.             "pushl %4\n\t" \
  73.             "pushl %3\n\t" \
  74.             "pushl %2\n\t" \
  75.             "pushl $0\n\t" \
  76.             "movl %1,%%eax\n\t" \
  77.             "lcall $7,$0\n\t" \
  78.             "jnb .+4\n\t" \
  79.             "xor %%eax, %%eax\n\t" \
  80.             "addl $28,%%esp\n\t" \
  81.             : "=a" (malloc_buffer) : "a" (__IBCS_mmap),
  82.             "rm" (addr), "rm" (size), "rm" (prot), "rm" (flags), 
  83.             "rm" (fd), "rm" (f_offset));
  84. #else
  85.   __asm__ volatile ("pushl %%ebx\n\t" \
  86.             "pushl %7\n\t" \
  87.             "pushl %6\n\t" \
  88.             "pushl %5\n\t" \
  89.             "pushl %4\n\t" \
  90.             "pushl %3\n\t" \
  91.             "pushl %2\n\t" \
  92.             "movl %%esp,%%ebx\n\t" \
  93.             "int $0x80\n\t" \
  94.             "addl $24,%%esp\n\t" \
  95.             "popl %%ebx\n" \
  96.             : "=a" (malloc_buffer) : "a" (__NR_mmap),
  97.             "rm" (addr), "rm" (size), "rm" (prot), "rm" (flags), 
  98.             "rm" (fd), "rm" (f_offset));
  99. #endif
  100.   return malloc_buffer;
  101. }
  102.  
  103.  
  104. extern inline int _dl_open(char * addr, unsigned int flags)
  105. {
  106.   int zfileno;
  107. #ifdef IBCS_COMPATIBLE
  108.   __asm__ volatile ("pushl %3\n\t" \
  109.         "pushl %2\n\t" \
  110.         "pushl $0\n\t" \
  111.         "movl %1,%%eax\n\t" \
  112.         "lcall $7,$0\n\t" \
  113.         "jnb .+7\n\t" \
  114.         "movl $-1, %%eax\n\t" \
  115.         "addl $12,%%esp\n\t" \
  116.         :"=a" (zfileno) : "i" (__IBCS_open), "rm" (addr), "rm" (flags));
  117. #else
  118.   __asm__ volatile ("pushl %%ebx\n"\
  119.             "movl %%esi,%%ebx\n"\
  120.             "int $0x80\n" \
  121.             "popl %%ebx\n"\
  122.             : "=a" (zfileno) \
  123.             : "0" (__NR_open),"S" ((long)(addr)),"c" ((long)(flags)));
  124. #endif
  125.  
  126.   return zfileno;
  127. }
  128.  
  129. extern inline int _dl_write(int fd, const char * buf, int len)
  130. {
  131.   int status;
  132. #ifdef IBCS_COMPATIBLE
  133.   __asm__ volatile ("pushl %4\n\t" \
  134.       "pushl %3\n\t" \
  135.       "pushl %2\n\t" \
  136.       "pushl $0\n\t" \
  137.       "movl %1,%%eax\n\t" \
  138.       "lcall $7,$0\n\t" \
  139.       "jnb .+4\n\t" \
  140.       "xor %%eax, %%eax\n\t" \
  141.       "addl $12,%%esp\n\t" \
  142.       :"=a" (status) : "i" (__IBCS_write), "rm" (fd), "rm" (buf), "rm" (len));
  143. #else
  144.   __asm__ volatile ("pushl %%ebx\n"\
  145.             "movl %%esi,%%ebx\n"\
  146.             "int $0x80\n" \
  147.             "popl %%ebx\n"\
  148.             : "=a" (status) \
  149.             : "0" (__NR_write),"S" ((long)(fd)),"c" ((long)(buf)),"d" ((long)(len)));
  150. #endif
  151. }
  152.  
  153.  
  154. extern inline int _dl_read(int fd, const char * buf, int len)
  155. {
  156.   int status;
  157. #ifdef IBCS_COMPATIBLE
  158.   __asm__ volatile ("pushl %4\n\t" \
  159.       "pushl %3\n\t" \
  160.       "pushl %2\n\t" \
  161.       "pushl $0\n\t" \
  162.       "movl %1,%%eax\n\t" \
  163.       "lcall $7,$0\n\t" \
  164.       "jnb .+4\n\t" \
  165.       "xor %%eax, %%eax\n\t" \
  166.       "addl $12,%%esp\n\t" \
  167.       : "=a" (status) : "i" (__IBCS_read), "rm" (fd), "rm" (buf), "rm" (len));
  168. #else
  169.   __asm__ volatile ("pushl %%ebx\n"\
  170.             "movl %%esi,%%ebx\n"\
  171.             "int $0x80\n" \
  172.             "popl %%ebx\n"\
  173.             : "=a" (status) \
  174.             : "0" (__NR_read),"S" ((long)(fd)),"c" ((long)(buf)),"d" ((long)(len)));
  175. #endif
  176. }
  177.  
  178. extern inline int _dl_mprotect(const char * addr, int size, int prot)
  179. {
  180.   int status;
  181. #ifdef IBCS_COMPATIBLE
  182.   __asm__ volatile ("pushl %4\n\t" \
  183.       "pushl %3\n\t" \
  184.       "pushl %2\n\t" \
  185.       "pushl $0\n\t" \
  186.       "movl %1,%%eax\n\t" \
  187.       "lcall $7,$0\n\t" \
  188.       "jnb .+7\n\t" \
  189.       "movl $-1, %%eax\n\t" \
  190.       "addl $16,%%esp\n\t" \
  191.       :"=a" (status) : "i" (__IBCS_mprotect), "rm" (addr), "rm" (size), "rm" (prot));
  192. #else
  193.   __asm__ volatile ("pushl %%ebx\n"\
  194.             "movl %%esi,%%ebx\n"\
  195.             "int $0x80\n" \
  196.             "popl %%ebx\n"\
  197.             : "=a" (status) \
  198.             : "0" (__NR_mprotect),"S" ((long)(addr)),"c" ((long)(size)),"d" ((long)(prot)));
  199. #endif
  200.   return status;
  201. }
  202.