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 / sparc / threads.h
C/C++ Source or Header  |  1996-09-28  |  3KB  |  102 lines

  1. /*
  2.  * sparc/threads.h
  3.  * Sparc 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 __sparc_threads_h
  15. #define __sparc_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.     int regstore[6];                    \
  26.     asm("                            \n\
  27.         call 1f                        \n\
  28.         nop                        \n\
  29. 1:                                \n\
  30.         add %%o7,%%lo(2f-1b+8),%%l0            \n\
  31.                                 \n\
  32.         ta 3                        \n\
  33.         st %%l0,[%2+0]                    \n\
  34.         st %%fp,[%2+4]                    \n\
  35.         st %%sp,[%2+8]                    \n\
  36.         st %%l7,[%2+12]                    \n\
  37.         st %%i7,[%2+16]                    \n\
  38.         st %2,[%0]                    \n\
  39.                                 \n\
  40.         ld [%1],%2                    \n\
  41.         ld [%2+16],%%i7                    \n\
  42.         ld [%2+12],%%l7                    \n\
  43.         ld [%2+8],%%sp                    \n\
  44.         ld [%2+4],%%fp                    \n\
  45.         ld [%2+0],%%l0                    \n\
  46.                                 \n\
  47.         jmpl %%l0,%%g0                    \n\
  48.         nop                         \n\
  49. 2:        nop                        \n\
  50.         " : : "r" (&((from)->restorePoint)),        \
  51.               "r" (&((to)->restorePoint)),        \
  52.               "r" (®store)                \
  53.         : "i0", "i1", "i2", "i3", "i4", "i5", "i7",    \
  54.           "l0", "l1", "l2", "l3", "l4", "l5", "l6",    \
  55.           "o0", "o1", "o2", "o3", "o4", "o5", "o7"    \
  56.         );                        \
  57.     }
  58.  
  59. #define THREADINIT(to, func) {                                  \
  60.                 int* regstore = (int*)((to)->stackEnd - (6 * 4));\
  61.                 (to)->restorePoint = (void*)regstore;        \
  62.                 regstore[0] = (int)func;            \
  63.                 regstore[1] = 0;                \
  64.                 regstore[2] = ((int)regstore) - (16 * 4);    \
  65.                 regstore[3] = 0;                \
  66.                 regstore[4] = 0;                \
  67.         }
  68.  
  69. #define    THREADINFO(ee)                        \
  70.         do {                        \
  71.             void** ptr;                \
  72.             int i;                    \
  73.             asm("ta 3");                \
  74.             asm("mov %%sp,%0" : "=r" (ptr));    \
  75.             for (i = 0; i != 2; i++) {              \
  76.                 ptr = (void**)ptr[14];        \
  77.             }                    \
  78.             (ee)->restorePoint = 0;            \
  79.             (ee)->stackEnd = (void*)ptr;        \
  80.             (ee)->stackBase = (ee)->stackEnd - threadStackSize;\
  81.             (ee)->flags = THREAD_FLAGS_NOSTACKALLOC;\
  82.         } while(0)
  83.  
  84. #define    THREADFRAMES(tid, cnt)                    \
  85.         do {                        \
  86.             void** ptr;                \
  87.             cnt = 0;                \
  88.             if (tid == currentThread) {        \
  89.                 asm("ta 3");            \
  90.                 asm("mov %%sp,%0" : "=r" (ptr));\
  91.             }                    \
  92.             else {                    \
  93.                 ptr = ((void***)tid->PrivateInfo->restorePoint)[2];\
  94.             }                    \
  95.             while (*ptr != 0) {            \
  96.                 cnt++;                \
  97.                 ptr = (void**)ptr[14];        \
  98.             }                    \
  99.         } while (0)
  100.  
  101. #endif
  102.