home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / kaffe-0.5p4-src.tgz / tar.out / contrib / kaffe / config / i386 / threads.h < prev   
C/C++ Source or Header  |  1996-09-28  |  2KB  |  79 lines

  1. /*
  2.  * i386/threads.h
  3.  * i386 threading information.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, May 1996.
  12.  */
  13.  
  14. #ifndef __i386_threads_h
  15. #define __i386_threads_h
  16.  
  17. /**/
  18. /* Thread handling */
  19. /**/
  20. #define    USE_INTERNAL_THREADS
  21.  
  22. #define    THREADSTACKSIZE        (32 * 1024)
  23.  
  24. #define    THREADSWITCH(to, from)                    \
  25.     asm("    pushl $1f                    \n\
  26.         pushal                        \n\
  27.         movl %%esp,%0                    \n\
  28.         movl %1,%%esp                    \n\
  29.         popal                        \n\
  30.         ret                        \n\
  31. 1:        nop                        \n\
  32.         " : : "g" (from->restorePoint), "g" (to->restorePoint))
  33.  
  34. #define    THREADINIT(to, func)                    \
  35.     asm("                            \n\
  36.         movl %0,-4(%1)                    \n\
  37.         movl $0,-8(%1)                   \n\
  38.         movl $0,-12(%1)                  \n\
  39.         movl $0,-16(%1)                  \n\
  40.         movl $0,-20(%1)                  \n\
  41.         movl $0,-24(%1)                 \n\
  42.         movl $0,-28(%1)                  \n\
  43.         movl $0,-32(%1)                  \n\
  44.         movl $0,-36(%1)                  \n\
  45.         " : : "r" (func), "r" (to->stackEnd));        \
  46.         to->restorePoint = to->stackEnd - 36
  47.  
  48. #define    THREADINFO(ee)                        \
  49.         do {                        \
  50.             void** ptr;                \
  51.             int i;                    \
  52.             asm("movl %%ebp,%0" : "=r" (ptr));    \
  53.             for (i = 0; i != 2; i++) {              \
  54.                 ptr = (void**)*ptr;        \
  55.             }                    \
  56.             (ee)->restorePoint = 0;            \
  57.             (ee)->stackEnd = (void*)ptr;        \
  58.             (ee)->stackBase = (ee)->stackEnd - threadStackSize;\
  59.             (ee)->flags = THREAD_FLAGS_NOSTACKALLOC;\
  60.         } while(0)
  61.  
  62. #define    THREADFRAMES(tid, cnt)                    \
  63.         do {                        \
  64.             void** ptr;                \
  65.             cnt = 0;                \
  66.             if (tid == currentThread) {        \
  67.                 asm("movl %%ebp,%0" : "=r" (ptr));\
  68.             }                    \
  69.             else {                    \
  70.                 ptr = ((void***)tid->PrivateInfo->restorePoint)[2];\
  71.             }                    \
  72.             while (*ptr != 0) {            \
  73.                 cnt++;                \
  74.                 ptr = (void**)*ptr;        \
  75.             }                    \
  76.         } while (0)
  77.  
  78. #endif
  79.