sparc.h

Go to the documentation of this file.
00001 /*
00002  * QuickThreads -- Threads-building toolkit.
00003  * Copyright (c) 1993 by David Keppel
00004  *
00005  * Permission to use, copy, modify and distribute this software and
00006  * its documentation for any purpose and without fee is hereby
00007  * granted, provided that the above copyright notice and this notice
00008  * appear in all copies.  This software is provided as a
00009  * proof-of-concept and for demonstration purposes; there is no
00010  * representation about the suitability of this software for any
00011  * purpose.
00012  */
00013 
00014 #ifndef QUICKTHREADS_SPARC_H
00015 #define QUICKTHREADS_SPARC_H
00016 
00017 typedef unsigned long qt_word_t;
00018 
00019 /* Stack layout on the sparc:
00020 
00021    non-varargs:
00022 
00023    +---
00024    | <blank space for alignment>
00025    | %o7 == return address -> qt_start
00026    | %i7
00027    | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
00028    | %i5 -> only
00029    | %i4 -> userf
00030    | %i3
00031    | %i2 -> pt
00032    | %i1 -> pu
00033    | %i0
00034    | %l7
00035    | %l6
00036    | %l5
00037    | %l4
00038    | %l3
00039    | %l2
00040    | %l1
00041    | %l0    <--- qt_t.sp
00042    +---
00043 
00044    varargs:
00045 
00046    |  :
00047    |  :
00048    | argument list
00049    | one-word aggregate return pointer
00050    +---
00051    | <blank space for alignment>
00052    | %o7 == return address -> qt_vstart
00053    | %i7
00054    | %i6 == frame pointer -> 0 (NULL-terminated stack frame chain)
00055    | %i5 -> startup
00056    | %i4 -> userf
00057    | %i3 -> cleanup
00058    | %i2 -> pt
00059    | %i1
00060    | %i0
00061    | %l7
00062    | %l6
00063    | %l5
00064    | %l4
00065    | %l3
00066    | %l2
00067    | %l1
00068    | %l0    <--- qt_t.sp
00069    +---
00070 
00071    */
00072 
00073 
00074 /* What to do to start a thread running. */
00075 extern void qt_start (void);
00076 extern void qt_vstart (void);
00077 
00078 
00079 /* Hold 17 saved registers + 1 word for alignment. */
00080 #define QUICKTHREADS_STKBASE    (18 * 4)
00081 #define QUICKTHREADS_VSTKBASE   QUICKTHREADS_STKBASE
00082 
00083 
00084 /* Stack must be doubleword aligned. */
00085 #define QUICKTHREADS_STKALIGN   (8) /* Doubleword aligned. */
00086 
00087 #define QUICKTHREADS_ONLY_INDEX (QUICKTHREADS_I5)
00088 #define QUICKTHREADS_USER_INDEX (QUICKTHREADS_I4)
00089 #define QUICKTHREADS_ARGT_INDEX (QUICKTHREADS_I2)
00090 #define QUICKTHREADS_ARGU_INDEX (QUICKTHREADS_I1)
00091 
00092 #define QUICKTHREADS_VSTARTUP_INDEX (QUICKTHREADS_I5)
00093 #define QUICKTHREADS_VUSERF_INDEX       (QUICKTHREADS_I4)
00094 #define QUICKTHREADS_VCLEANUP_INDEX (QUICKTHREADS_I3)
00095 #define QUICKTHREADS_VARGT_INDEX        (QUICKTHREADS_I2)
00096 
00097 #define QUICKTHREADS_O7 (16)
00098 #define QUICKTHREADS_I6 (14)
00099 #define QUICKTHREADS_I5 (13)
00100 #define QUICKTHREADS_I4 (12)
00101 #define QUICKTHREADS_I3 (11)
00102 #define QUICKTHREADS_I2 (10)
00103 #define QUICKTHREADS_I1 ( 9)
00104 
00105 
00106 /* The thread will ``return'' to the `qt_start' routine to get things
00107    going.  The normal return sequence takes us to QUICKTHREADS_O7+8, so we
00108    pre-subtract 8.  The frame pointer chain is 0-terminated to prevent
00109    the trap handler from chasing off in to random memory when flushing
00110    stack windows. */
00111 
00112 #define QUICKTHREADS_ARGS_MD(top) \
00113     (QUICKTHREADS_SPUT ((top), QUICKTHREADS_O7, ((void *)(((int)qt_start)-8))), \
00114      QUICKTHREADS_SPUT ((top), QUICKTHREADS_I6, 0))
00115 
00116 
00117 /* The varargs startup routine always reads 6 words of arguments
00118    (6 argument registers) from the stack, offset by one word to
00119    allow for an aggregate return area  pointer.  If the varargs
00120    routine actually pushed fewer words than that, qt_vstart could read
00121    off the top of the stack.  To prevent errors, we always allocate 8
00122    words.  The space is often just wasted. */
00123 
00124 #define QUICKTHREADS_VARGS_MD0(sp, vabytes) \
00125   ((qt_t *)(((char *)(sp)) - 8*4 - QUICKTHREADS_STKROUNDUP(vabytes)))
00126 
00127 #define QUICKTHREADS_VARGS_MD1(sp) \
00128   (QUICKTHREADS_SPUT (sp, QUICKTHREADS_O7, ((void *)(((int)qt_vstart)-8))))
00129 
00130 /* The SPARC has wierdo calling conventions which stores a hidden
00131    parameter for returning aggregate values, so the rest of the
00132    parameters are shoved up the stack by one place. */
00133 #define QUICKTHREADS_VARGS_ADJUST(sp)   (((char *)sp)+4)
00134 
00135 #define QUICKTHREADS_VARGS_DEFAULT
00136 
00137 
00138 #define QUICKTHREADS_GROW_DOWN
00139 
00140 #endif /* ndef QUICKTHREADS_SPARC_H */

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5