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 / m68k / threads.h
C/C++ Source or Header  |  1996-09-28  |  4KB  |  98 lines

  1. /*
  2.  * m68k/threads.h
  3.  * m68k thread handling.
  4.  *
  5.  * Copyright (c) 1996 Matthias Hopf <mshopf@informatik.uni-erlangen.de>
  6.  *
  7.  * Permission granted for Tim Wilkinson to include this source in his
  8.  * Kaffe system, Copyright (c) 1996 Systems Architecture Research Centre,
  9.  *               City University, London, UK.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  */
  14.  
  15. #ifndef __m68k_threads_h
  16. #define __m68k_threads_h
  17.  
  18. /**/
  19. /* Thread handling */
  20. /**/
  21.  
  22. /* NOTE! a5 is asumed to be the frame pointer (only for frame counting). */
  23.  
  24. /*
  25.  * Stack of waiting thread:
  26.  *       +  12   pc  (return address)
  27.  *       +  8    a4  ()
  28.  *       +  4    a5  (frame pointer)
  29.  *       +  0    a6
  30.  * remaining registers are scratched.
  31.  */
  32.  
  33. #define USE_INTERNAL_THREADS
  34.  
  35. #define THREADSTACKSIZE         (32 * 1024)
  36.  
  37. #define M68K_THREADSWITCH(to, from)                      \
  38.             asm("                                \
  39.             pea 1f                               \n\
  40.             move.l a4, -(a7)                     \n\
  41.             move.l a5, -(a7)                     \n\
  42.             move.l a6, -(a7)                     \n\
  43.             move.l a7, (%0)                      \n\
  44.             move.l %1, a7                        \n\
  45.             move.l (a7)+,a6                      \n\
  46.             move.l (a7)+,a5                      \n\
  47.             move.l (a7)+,a4                      \n\
  48.             rts                                  \n\
  49.          1: nop                                " \
  50.             : : "a" (& from->restorePoint), "a" (to->restorePoint) : "cc","memory", \
  51.             "d0","d1","d2","d3","d4","d5","d6","d7","a0","a1","a2","a3")
  52.  
  53. #define M68K_THREADINIT(to, func)                        \
  54.           asm("                                  \
  55.           moveq #0, d0                           \n\
  56.           move.l %2, -(%0)                       \n\
  57.           move.l d0, -(%0)                       \n\
  58.           move.l d0, -(%0)                       \n\
  59.           move.l d0, -(%0)                     " \
  60.           : "=a" (to->restorePoint) : "0" (to->stackEnd), "g" (func) : "d0", "cc")
  61.  
  62. #define M68K_THREADINFO(ee)                                     \
  63.         do {                                            \
  64.             void** ptr;                             \
  65.             int i;                                  \
  66.             asm("move.l a5, %0" : "=r" (ptr));      \
  67.             for (i = 0; i != 2; i++) {              \
  68.                 ptr = (void**)*ptr;             \
  69.             }                                       \
  70.             (ee)->restorePoint = 0;                 \
  71.             (ee)->stackEnd = (void*)ptr;            \
  72.             (ee)->stackBase = (ee)->stackEnd - threadStackSize;\
  73.             (ee)->flags = THREAD_FLAGS_NOSTACKALLOC;\
  74.         } while(0)
  75.  
  76. #define M68K_THREADFRAMES(tid, cnt)                             \
  77.         do {                                            \
  78.             void** ptr;                             \
  79.             cnt = 0;                                \
  80.             if (tid == currentThread) {             \
  81.                 asm("move.l a5,%0" : "=r" (ptr));\
  82.             }                                       \
  83.             else {                                  \
  84.                 ptr = ((void***)tid->PrivateInfo->restorePoint)[1];\
  85.             }                                       \
  86.             while (*ptr != 0) {                     \
  87.                 cnt++;                          \
  88.                 ptr = (void**)*ptr;             \
  89.             }                                       \
  90.         } while (0)
  91.  
  92. #define THREADSWITCH(to, from)    M68K_THREADSWITCH(to, from)
  93. #define THREADINIT(to, func)      M68K_THREADINIT(to, func)
  94. #define THREADINFO(ee)            M68K_THREADINFO(ee)
  95. #define THREADFRAMES(tid,cnt)     M68K_THREADFRAMES(tid, cnt)
  96.  
  97. #endif
  98.