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 / powerpc / threads.h
C/C++ Source or Header  |  1996-09-28  |  5KB  |  176 lines

  1.  
  2. /*
  3.  * powerpc/threads.h
  4.  * Sparc threading information.
  5.  *
  6.  * Copyright (c) 1996 Systems Architecture Research Centre,
  7.  *           City University, London, UK.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, May 1996.
  13.  * Ported  by Attila Molnar <gusthy@hu.bonus.com>, July 1996.
  14.  */
  15.  
  16. #ifndef __powerpc_threads_h
  17. #define __powerpc_threads_h
  18.  
  19. /**/
  20. /* Thread handling */
  21. /**/
  22. #define    USE_INTERNAL_THREADS
  23.  
  24. #define    THREADSTACKSIZE        (32 * 1024)
  25.  
  26. #define    THREADSWITCH(to, from) {                \
  27.     int regstore[64];                    \
  28.  /*                                \
  29.     printf("switch %x %x\n", (int)((to)->restorePoint),     \
  30.         (int)((from)->restorePoint));            \
  31.     printf("®store = %x\n", (int)(regstore));        \
  32.     if((to)->restorePoint)                    \
  33.     printf("cim: %x\n", *((int *)((to)->restorePoint)+1));    \
  34.  */                                \
  35.     { int aa = 0; thread_dummy("%d\n", aa); }        \
  36.     asm("                            \n\
  37.         stw 1, 4+%2                    \n\
  38.         stw 2, 8+%2                    \n\
  39.         stw 3, 12+%2                    \n\
  40.         stw 4, 16+%2                    \n\
  41.         stw 5, 20+%2                    \n\
  42.         stw 6, 24+%2                    \n\
  43.         stw 7, 28+%2                    \n\
  44.         stw 8, 32+%2                    \n\
  45.         stw 9, 36+%2                    \n\
  46.         stw 10, 40+%2                    \n\
  47.         stw 11, 44+%2                    \n\
  48.         stw 12, 48+%2                    \n\
  49.         stw 13, 52+%2                    \n\
  50.         stw 14, 56+%2                    \n\
  51.         stw 15, 60+%2                    \n\
  52.         stw 16, 64+%2                    \n\
  53.         stw 17, 68+%2                    \n\
  54.         stw 18, 72+%2                    \n\
  55.         stw 19, 76+%2                    \n\
  56.         stw 20, 80+%2                    \n\
  57.         stw 21, 84+%2                    \n\
  58.         stw 22, 88+%2                    \n\
  59.         stw 23, 92+%2                    \n\
  60.         stw 24, 96+%2                    \n\
  61.         stw 25, 100+%2                    \n\
  62.         stw 26, 104+%2                    \n\
  63.         stw 27, 108+%2                    \n\
  64.         stw 28, 112+%2                    \n\
  65.         stw 29, 116+%2                    \n\
  66.         stw 30, 120+%2                    \n\
  67.         stw 0, 124+%2                    \n\
  68.         stw 31, 128+%2                    \n\
  69.         lwz 27, %3                    \n\
  70.         stw 27, %0                     \n\
  71.         bl 1f                        \n\
  72.         nop                        \n\
  73.         nop                        \n\
  74.         nop                        \n\
  75.         nop                        \n\
  76.     1:    nop                        \n\
  77.         nop                        \n\
  78.         nop                        \n\
  79.         nop                        \n\
  80.         mflr 27                        \n\
  81.         addi 27, 27, 2f-1b                \n\
  82.         stw 27, %2                    \n\
  83.         lwz 31, %1                    \n\
  84.         lwz 27, 0(31)                    \n\
  85.         mtlr 27                        \n\
  86.         lwz 1, 4(31)                    \n\
  87.         lwz 2, 8(31)                    \n\
  88.         lwz 3, 12(31)                    \n\
  89.         lwz 4, 16(31)                    \n\
  90.         lwz 5, 20(31)                    \n\
  91.         lwz 6, 24(31)                    \n\
  92.         lwz 7, 28(31)                    \n\
  93.         lwz 8, 32(31)                    \n\
  94.         lwz 9, 36(31)                    \n\
  95.         lwz 10, 40(31)                    \n\
  96.         lwz 11, 44(31)                    \n\
  97.         lwz 12, 48(31)                    \n\
  98.         lwz 13, 52(31)                    \n\
  99.         lwz 14, 56(31)                    \n\
  100.         lwz 15, 60(31)                    \n\
  101.         lwz 16, 64(31)                    \n\
  102.         lwz 17, 68(31)                    \n\
  103.         lwz 18, 72(31)                    \n\
  104.         lwz 19, 76(31)                    \n\
  105.         lwz 20, 80(31)                    \n\
  106.         lwz 21, 84(31)                    \n\
  107.         lwz 22, 88(31)                    \n\
  108.         lwz 23, 92(31)                    \n\
  109.         lwz 24, 96(31)                    \n\
  110.         lwz 25, 100(31)                    \n\
  111.         lwz 26, 104(31)                    \n\
  112.         lwz 27, 108(31)                    \n\
  113.         lwz 28, 112(31)                    \n\
  114.         lwz 29, 116(31)                    \n\
  115.         lwz 30, 120(31)                    \n\
  116.         lwz 0, 124(31)                    \n\
  117.         lwz 31, 128(31)                    \n\
  118.         blr                        \n\
  119.         nop                        \n\
  120.         nop                        \n\
  121.         nop                        \n\
  122.         nop                        \n\
  123. 2:        nop                        \n\
  124.         nop                        \n\
  125.         nop                        \n\
  126.         nop                        \n\
  127.         " : "=m" ((from)->restorePoint),        \
  128.               "=m" ((to)->restorePoint),        \
  129.               "=m" (regstore):"m"((int)(®store)) :    \
  130.               "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",    \
  131.               /*"11", "12", "13",*/ "14", "15", "16", \
  132.               "17", "18", "19", "20",    \
  133.               "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");    \
  134.     }
  135.  
  136. #define THREADINIT(to, func) {                                  \
  137.                 int* regstore = (int*)((to)->stackEnd - (64 * 4));\
  138.                 int aa;    \
  139.                 (to)->restorePoint = (void*)regstore;        \
  140.                 regstore[0] = (int)func;            \
  141.                 regstore[1] = ((int)regstore)-80*4;            \
  142.         }
  143.  
  144. #define    THREADINFO(ee)                        \
  145.         do {                        \
  146.             register void** ptr;                \
  147.             int i;                    \
  148.             asm("mr %0, 1" : "=r" (ptr) : );         \
  149.             for (i = 0; i != 2; i++) {              \
  150.                 ptr = (void**)*ptr;        \
  151.             }                    \
  152.             (ee)->restorePoint = 0;            \
  153.             (ee)->stackEnd = (void*)ptr;        \
  154.             (ee)->stackBase = (ee)->stackEnd - threadStackSize;\   
  155.             (ee)->flags = THREAD_FLAGS_NOSTACKALLOC;\
  156.         } while(0)
  157.  
  158. #define    THREADFRAMES(tid, cnt)                    \
  159. /*        printf("threadframes tid = %x ct = %x cnt = %d\n", tid, currentThread, cnt); \
  160. */        do {                        \
  161.             void** ptr;                \
  162.             cnt = 0;                \
  163.             if (tid == currentThread) {        \
  164. /*                asm("stw 1, %0" : :"m" (&ptr)); */\
  165.             }                    \
  166.             else {                    \
  167.                 ptr = ((void***)tid->PrivateInfo->restorePoint)[2];\
  168.             }                    \
  169.             while (*ptr != 0) {            \
  170.                 cnt++;                \
  171.                 ptr = (void**)ptr[14];        \
  172.             }                    \
  173.         } while (0)
  174.  
  175. #endif
  176.