iX86_64.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_X86_64_H
00015 #define QUICKTHREADS_X86_64_H
00016 
00017 typedef unsigned long qt_word_t;
00018 
00019 /* Thread's initial stack layout on the iX86_64:
00020 
00021    non-varargs:
00022 
00023    +---
00024    | arg[2] === `userf' on startup
00025    | arg[1] === `pt' on startup
00026    | arg[0] === `pu' on startup
00027    +---
00028    | ret pc === qt_error
00029    +---
00030    | ret pc === `only' on startup
00031    +---
00032    | %ebp
00033    | %esi
00034    | %edi
00035    | %ebx               <--- qt_t.sp
00036    +---
00037 
00038    When a non-varargs thread is started, it ``returns'' directly to
00039    the client's `only' function.
00040 
00041    varargs:
00042 
00043    +---
00044    | arg[n-1]
00045    | ..
00046    | arg[0]
00047    +---
00048    | ret pc === `qt_vstart'
00049    +---
00050    | %ebp   === `startup'
00051    | %esi   === `cleanup'
00052    | %edi   === `pt'
00053    | %ebx   === `vuserf'        <--- qt_t.sp
00054    +---
00055 
00056    When a varargs thread is started, it ``returns'' to the `qt_vstart'
00057    startup code.  The startup code calls the appropriate functions. */
00058 
00059 
00060 /* What to do to start a varargs thread running. */
00061 extern void qt_vstart (void);
00062 
00063 
00064 /* Hold two return pcs (qt_error, qt_start) plus thirteen args. */
00065 #define QUICKTHREADS_STKBASE    (15 * sizeof(long))
00066 
00067 /* Hold 4 saved regs plus one return pc (qt_vstart). */
00068 #define QUICKTHREADS_VSTKBASE   (5 * sizeof(long))
00069 
00070 
00071 /* Stack must be long-word aligned. */
00072 #define QUICKTHREADS_STKALIGN   (sizeof(long))
00073 
00074 
00075 /* Where to place various arguments. */
00076 #define QUICKTHREADS_ONLY_INDEX (QUICKTHREADS_PC)
00077 #define QUICKTHREADS_USER_INDEX (QUICKTHREADS_ARG2)
00078 #define QUICKTHREADS_ARGT_INDEX (QUICKTHREADS_ARG1)
00079 #define QUICKTHREADS_ARGU_INDEX (QUICKTHREADS_ARG0)
00080 
00081 #define QUICKTHREADS_VSTARTUP_INDEX (QUICKTHREADS_EBP)
00082 #define QUICKTHREADS_VUSERF_INDEX   (QUICKTHREADS_EBX)
00083 #define QUICKTHREADS_VCLEANUP_INDEX (QUICKTHREADS_ESI)
00084 #define QUICKTHREADS_VARGT_INDEX    (QUICKTHREADS_EDI)
00085 
00086 
00087 /* Stack layout offsets relative to stack when save stack function called. */
00088 
00089 #define QUICKTHREADS_PC    14
00090 #define QUICKTHREADS_RPC   13
00091 
00092 #define QUICKTHREADS_R8    12
00093 #define QUICKTHREADS_R9    11
00094 #define QUICKTHREADS_R10   10
00095 #define QUICKTHREADS_R11    9
00096 #define QUICKTHREADS_R12    8
00097 #define QUICKTHREADS_R13    7
00098 #define QUICKTHREADS_R14    6
00099 #define QUICKTHREADS_R15    5
00100 #define QUICKTHREADS_RBX    4
00101 #define QUICKTHREADS_RCX    3
00102 #define QUICKTHREADS_RDX    2
00103 #define QUICKTHREADS_RDI    1
00104 #define QUICKTHREADS_RSI    0
00105 
00106 
00107 /* Arguments to save stack function. */
00108 
00109 #define QUICKTHREADS_ARG0 QUICKTHREADS_RDI
00110 #define QUICKTHREADS_ARG1 QUICKTHREADS_RSI
00111 #define QUICKTHREADS_ARG2 QUICKTHREADS_RDX
00112 
00113 
00114 /* Stack grows down.  The top of the stack is the first thing to
00115    pop off (preincrement, postdecrement). */
00116 #define QUICKTHREADS_GROW_DOWN
00117 
00118 extern void qt_error (void);
00119 
00120 /* Push on the error return address. */
00121 #define QUICKTHREADS_ARGS_MD(sto) \
00122   (QUICKTHREADS_SPUT (sto, QUICKTHREADS_RPC, qt_error))
00123 
00124 
00125 /* When varargs are pushed, allocate space for all the args. */
00126 #define QUICKTHREADS_VARGS_MD0(sto, nbytes) \
00127   ((qt_t *)(((char *)(sto)) - QUICKTHREADS_STKROUNDUP(nbytes)))
00128 
00129 #define QUICKTHREADS_VARGS_MD1(sto) \
00130   (QUICKTHREADS_SPUT (sto, QUICKTHREADS_PC, qt_vstart))
00131 
00132 #define QUICKTHREADS_VARGS_DEFAULT
00133 
00134 #endif /* QUICKTHREADS_X86_64_H */

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