summaryrefslogtreecommitdiff
path: root/ext/systemc/src/sysc/qt/md/sparc.h
blob: edaf5325e8fb4ea8af594415c21dc5919a119206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * QuickThreads -- Threads-building toolkit.
 * Copyright (c) 1993 by David Keppel
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice and this notice
 * appear in all copies.  This software is provided as a
 * proof-of-concept and for demonstration purposes; there is no
 * representation about the suitability of this software for any
 * purpose.
 */

#ifndef QUICKTHREADS_SPARC_H
#define QUICKTHREADS_SPARC_H

typedef unsigned long qt_word_t;

/* Stack layout on the sparc:

   non-varargs:

   +---
   | <blank space for alignment>
   | %o7 == return address -> qt_start
   | %i7
   | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
   | %i5 -> only
   | %i4 -> userf
   | %i3
   | %i2 -> pt
   | %i1 -> pu
   | %i0
   | %l7
   | %l6
   | %l5
   | %l4
   | %l3
   | %l2
   | %l1
   | %l0	<--- qt_t.sp
   +---

   varargs:

   |  :
   |  :
   | argument list
   | one-word aggregate return pointer
   +---
   | <blank space for alignment>
   | %o7 == return address -> qt_vstart
   | %i7
   | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
   | %i5 -> startup
   | %i4 -> userf
   | %i3 -> cleanup
   | %i2 -> pt
   | %i1
   | %i0
   | %l7
   | %l6
   | %l5
   | %l4
   | %l3
   | %l2
   | %l1
   | %l0	<--- qt_t.sp
   +---

   */


/* What to do to start a thread running. */
extern void qt_start (void);
extern void qt_vstart (void);


/* Hold 17 saved registers + 1 word for alignment. */
#define QUICKTHREADS_STKBASE	(18 * 4)
#define QUICKTHREADS_VSTKBASE	QUICKTHREADS_STKBASE


/* Stack must be doubleword aligned. */
#define QUICKTHREADS_STKALIGN	(8)	/* Doubleword aligned. */

#define QUICKTHREADS_ONLY_INDEX	(QUICKTHREADS_I5)
#define QUICKTHREADS_USER_INDEX	(QUICKTHREADS_I4)
#define QUICKTHREADS_ARGT_INDEX	(QUICKTHREADS_I2)
#define QUICKTHREADS_ARGU_INDEX	(QUICKTHREADS_I1)

#define QUICKTHREADS_VSTARTUP_INDEX	(QUICKTHREADS_I5)
#define QUICKTHREADS_VUSERF_INDEX		(QUICKTHREADS_I4)
#define QUICKTHREADS_VCLEANUP_INDEX	(QUICKTHREADS_I3)
#define QUICKTHREADS_VARGT_INDEX		(QUICKTHREADS_I2)

#define QUICKTHREADS_O7	(16)
#define QUICKTHREADS_I6	(14)
#define QUICKTHREADS_I5	(13)
#define QUICKTHREADS_I4	(12)
#define QUICKTHREADS_I3	(11)
#define QUICKTHREADS_I2	(10)
#define QUICKTHREADS_I1	( 9)


/* The thread will ``return'' to the `qt_start' routine to get things
   going.  The normal return sequence takes us to QUICKTHREADS_O7+8, so we
   pre-subtract 8.  The frame pointer chain is 0-terminated to prevent
   the trap handler from chasing off in to random memory when flushing
   stack windows. */

#define QUICKTHREADS_ARGS_MD(top) \
    (QUICKTHREADS_SPUT ((top), QUICKTHREADS_O7, ((void *)(((int)qt_start)-8))), \
     QUICKTHREADS_SPUT ((top), QUICKTHREADS_I6, 0))


/* The varargs startup routine always reads 6 words of arguments
   (6 argument registers) from the stack, offset by one word to
   allow for an aggregate return area  pointer.  If the varargs
   routine actually pushed fewer words than that, qt_vstart could read
   off the top of the stack.  To prevent errors, we always allocate 8
   words.  The space is often just wasted. */

#define QUICKTHREADS_VARGS_MD0(sp, vabytes) \
  ((qt_t *)(((char *)(sp)) - 8*4 - QUICKTHREADS_STKROUNDUP(vabytes)))

#define QUICKTHREADS_VARGS_MD1(sp) \
  (QUICKTHREADS_SPUT (sp, QUICKTHREADS_O7, ((void *)(((int)qt_vstart)-8))))

/* The SPARC has wierdo calling conventions which stores a hidden
   parameter for returning aggregate values, so the rest of the
   parameters are shoved up the stack by one place. */
#define QUICKTHREADS_VARGS_ADJUST(sp)	(((char *)sp)+4)

#define QUICKTHREADS_VARGS_DEFAULT


#define QUICKTHREADS_GROW_DOWN

#endif /* ndef QUICKTHREADS_SPARC_H */