sparc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * QuickThreads -- Threads-building toolkit.
  3. * Copyright (c) 1993 by David Keppel
  4. *
  5. * Permission to use, copy, modify and distribute this software and
  6. * its documentation for any purpose and without fee is hereby
  7. * granted, provided that the above copyright notice and this notice
  8. * appear in all copies. This software is provided as a
  9. * proof-of-concept and for demonstration purposes; there is no
  10. * representation about the suitability of this software for any
  11. * purpose.
  12. */
  13. #ifndef QT_SPARC_H
  14. #define QT_SPARC_H
  15. typedef unsigned long qt_word_t;
  16. /* Stack layout on the sparc:
  17. non-varargs:
  18. +---
  19. | <blank space for alignment>
  20. | %o7 == return address -> qt_start
  21. | %i7
  22. | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
  23. | %i5 -> only
  24. | %i4 -> userf
  25. | %i3
  26. | %i2 -> pt
  27. | %i1 -> pu
  28. | %i0
  29. | %l7
  30. | %l6
  31. | %l5
  32. | %l4
  33. | %l3
  34. | %l2
  35. | %l1
  36. | %l0 <--- qt_t.sp
  37. +---
  38. varargs:
  39. | :
  40. | :
  41. | argument list
  42. | one-word aggregate return pointer
  43. +---
  44. | <blank space for alignment>
  45. | %o7 == return address -> qt_vstart
  46. | %i7
  47. | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
  48. | %i5 -> startup
  49. | %i4 -> userf
  50. | %i3 -> cleanup
  51. | %i2 -> pt
  52. | %i1
  53. | %i0
  54. | %l7
  55. | %l6
  56. | %l5
  57. | %l4
  58. | %l3
  59. | %l2
  60. | %l1
  61. | %l0 <--- qt_t.sp
  62. +---
  63. */
  64. /* What to do to start a thread running. */
  65. extern void qt_start (void);
  66. extern void qt_vstart (void);
  67. /* Hold 17 saved registers + 1 word for alignment. */
  68. #define QT_STKBASE (18 * 4)
  69. #define QT_VSTKBASE QT_STKBASE
  70. /* Stack must be doubleword aligned. */
  71. #define QT_STKALIGN (8) /* Doubleword aligned. */
  72. #define QT_ONLY_INDEX (QT_I5)
  73. #define QT_USER_INDEX (QT_I4)
  74. #define QT_ARGT_INDEX (QT_I2)
  75. #define QT_ARGU_INDEX (QT_I1)
  76. #define QT_VSTARTUP_INDEX (QT_I5)
  77. #define QT_VUSERF_INDEX (QT_I4)
  78. #define QT_VCLEANUP_INDEX (QT_I3)
  79. #define QT_VARGT_INDEX (QT_I2)
  80. #define QT_O7 (16)
  81. #define QT_I6 (14)
  82. #define QT_I5 (13)
  83. #define QT_I4 (12)
  84. #define QT_I3 (11)
  85. #define QT_I2 (10)
  86. #define QT_I1 ( 9)
  87. /* The thread will ``return'' to the `qt_start' routine to get things
  88. going. The normal return sequence takes us to QT_O7+8, so we
  89. pre-subtract 8. The frame pointer chain is 0-terminated to prevent
  90. the trap handler from chasing off in to random memory when flushing
  91. stack windows. */
  92. #define QT_ARGS_MD(top) \
  93. (QT_SPUT ((top), QT_O7, ((void *)(((int)qt_start)-8))), \
  94. QT_SPUT ((top), QT_I6, 0))
  95. /* The varargs startup routine always reads 6 words of arguments
  96. (6 argument registers) from the stack, offset by one word to
  97. allow for an aggregate return area pointer. If the varargs
  98. routine actually pushed fewer words than that, qt_vstart could read
  99. off the top of the stack. To prevent errors, we always allocate 8
  100. words. The space is often just wasted. */
  101. #define QT_VARGS_MD0(sp, vabytes) \
  102. ((qt_t *)(((char *)(sp)) - 8*4 - QT_STKROUNDUP(vabytes)))
  103. #define QT_VARGS_MD1(sp) \
  104. (QT_SPUT (sp, QT_O7, ((void *)(((int)qt_vstart)-8))))
  105. /* The SPARC has wierdo calling conventions which stores a hidden
  106. parameter for returning aggregate values, so the rest of the
  107. parameters are shoved up the stack by one place. */
  108. #define QT_VARGS_ADJUST(sp) (((char *)sp)+4)
  109. #define QT_VARGS_DEFAULT
  110. #define QT_GROW_DOWN
  111. #endif /* ndef QT_SPARC_H */