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