Main Page | Alphabetical List | Class List | File List | Class Members | File Members

switch.h

Go to the documentation of this file.
00001 /* switch.h 00002 * Definitions needed for implementing context switching. 00003 * 00004 * Context switching is inherently machine dependent, since 00005 * the registers to be saved, how to set up an initial 00006 * call frame, etc, are all specific to a processor architecture. 00007 * 00008 * This file currently supports the DEC MIPS, DEC Alpha, SUN SPARC, 00009 * HP PARISC, IBM PowerPC, and Intel x86 architectures. 00010 */ 00011 00012 /* 00013 Copyright (c) 1992-1996 The Regents of the University of California. 00014 All rights reserved. See copyright.h for copyright notice and limitation 00015 of liability and disclaimer of warranty provisions. 00016 */ 00017 00018 #ifndef SWITCH_H 00019 #define SWITCH_H 00020 00021 #include "copyright.h" 00022 00023 00024 #ifdef DECMIPS 00025 00026 /* Registers that must be saved during a context switch. 00027 * These are the offsets from the beginning of the Thread object, 00028 * in bytes, used in switch.s 00029 */ 00030 #define SP 0 00031 #define S0 4 00032 #define S1 8 00033 #define S2 12 00034 #define S3 16 00035 #define S4 20 00036 #define S5 24 00037 #define S6 28 00038 #define S7 32 00039 #define FP 36 00040 #define PC 40 00041 00042 /* To fork a thread, we set up its saved register state, so that 00043 * when we switch to the thread, it will start running in ThreadRoot. 00044 * 00045 * The following are the initial registers we need to set up to 00046 * pass values into ThreadRoot (for instance, containing the procedure 00047 * for the thread to run). The first set is the registers as used 00048 * by ThreadRoot; the second set is the locations for these initial 00049 * values in the Thread object -- used in Thread::AllocateStack(). 00050 */ 00051 00052 #define InitialPC s0 00053 #define InitialArg s1 00054 #define WhenDonePC s2 00055 #define StartupPC s3 00056 00057 #define PCState (PC/4-1) 00058 #define FPState (FP/4-1) 00059 #define InitialPCState (S0/4-1) 00060 #define InitialArgState (S1/4-1) 00061 #define WhenDonePCState (S2/4-1) 00062 #define StartupPCState (S3/4-1) 00063 00064 #endif // DECMIPS 00065 00066 #ifdef SPARC 00067 00068 /* Registers that must be saved during a context switch. See comment above. */ 00069 #define I0 4 00070 #define I1 8 00071 #define I2 12 00072 #define I3 16 00073 #define I4 20 00074 #define I5 24 00075 #define I6 28 00076 #define I7 32 00077 00078 /* Aliases used for clearing code. */ 00079 #define FP I6 00080 #define PC I7 00081 00082 /* Registers for ThreadRoot. See comment above. */ 00083 #define InitialPC %o0 00084 #define InitialArg %o1 00085 #define WhenDonePC %o2 00086 #define StartupPC %o3 00087 00088 #define PCState (PC/4-1) 00089 #define InitialPCState (I0/4-1) 00090 #define InitialArgState (I1/4-1) 00091 #define WhenDonePCState (I2/4-1) 00092 #define StartupPCState (I3/4-1) 00093 00094 #endif // SPARC 00095 00096 #ifdef PARISC 00097 00098 /* Registers that must be saved during a context switch. See comment above. */ 00099 #define SP 0 00100 #define S0 4 00101 #define S1 8 00102 #define S2 12 00103 #define S3 16 00104 #define S4 20 00105 #define S5 24 00106 #define S6 28 00107 #define S7 32 00108 #define S8 36 00109 #define S9 40 00110 #define S10 44 00111 #define S11 48 00112 #define S12 52 00113 #define S13 56 00114 #define S14 60 00115 #define S15 64 00116 #define PC 68 00117 00118 /* Registers for ThreadRoot. See comment above. */ 00119 #define InitialPC %r3 /* S0 */ 00120 #define InitialArg %r4 00121 #define WhenDonePC %r5 00122 #define StartupPC %r6 00123 00124 #define PCState (PC/4-1) 00125 #define InitialPCState (S0/4-1) 00126 #define InitialArgState (S1/4-1) 00127 #define WhenDonePCState (S2/4-1) 00128 #define StartupPCState (S3/4-1) 00129 00130 #endif // PARISC 00131 00132 #ifdef x86 00133 00134 /* the offsets of the registers from the beginning of the thread object */ 00135 #define _ESP 0 00136 #define _EAX 4 00137 #define _EBX 8 00138 #define _ECX 12 00139 #define _EDX 16 00140 #define _EBP 20 00141 #define _ESI 24 00142 #define _EDI 28 00143 #define _PC 32 00144 00145 /* These definitions are used in Thread::AllocateStack(). */ 00146 #define PCState (_PC/4-1) 00147 #define FPState (_EBP/4-1) 00148 #define InitialPCState (_ESI/4-1) 00149 #define InitialArgState (_EDX/4-1) 00150 #define WhenDonePCState (_EDI/4-1) 00151 #define StartupPCState (_ECX/4-1) 00152 00153 #define InitialPC %esi 00154 #define InitialArg %edx 00155 #define WhenDonePC %edi 00156 #define StartupPC %ecx 00157 00158 #endif // x86 00159 00160 #ifdef PowerPC 00161 00162 #define SP 0 // stack pointer 00163 #define P1 4 // parameters 00164 #define P2 8 00165 #define P3 12 00166 #define P4 16 00167 #define GP13 20 // general purpose registers 13-31 00168 #define GP14 24 00169 #define GP15 28 00170 #define GP16 32 00171 #define GP17 36 00172 #define GP18 40 00173 #define GP19 44 00174 #define GP20 48 00175 #define GP21 52 00176 #define GP22 56 00177 #define GP23 60 00178 #define GP24 64 00179 #define GP25 68 00180 #define GP26 72 00181 #define GP27 76 00182 #define GP28 80 00183 #define GP29 84 00184 #define GP30 88 00185 #define GP31 92 00186 #define FP13 96 // floating point registers 14-31 00187 #define FP15 104 00188 #define FP16 112 00189 #define FP17 120 00190 #define FP18 128 00191 #define FP19 136 00192 #define FP20 144 00193 #define FP21 152 00194 #define FP22 160 00195 #define FP23 168 00196 #define FP24 176 00197 #define FP25 184 00198 #define FP26 192 00199 #define FP27 200 00200 #define FP28 208 00201 #define FP29 216 00202 #define FP30 224 00203 #define FP31 232 00204 #define CR 240 // control register 00205 #define LR 244 // link register 00206 #define TOC 248 // Table Of Contents 00207 00208 00209 // for ThreadRoot assembly function 00210 00211 #define InitialPCState 0 // (P1/4 - 1) // user function address 00212 #define InitialArgState 1 // (P2/4 - 1) // user function argument 00213 #define WhenDonePCState 2 // (P3/4 - 1) // clean up function addr 00214 #define StartupPCState 3 // (P4/4 - 1) // start up function addr 00215 #define PCState 60 // (LR/4 - 1) // ThreadRoot addr (first time). 00216 // Later PC addr when SWITCH 00217 // occured 00218 00219 #define InitialLR 21 00220 #define InitialArg 22 00221 #define WhenDoneLR 23 00222 #define StartupLR 24 00223 00224 #endif // PowerPC 00225 00226 #ifdef ALPHA 00227 00228 /* 00229 * Porting to Alpha was done by Shuichi Oikawa (shui@sfc.keio.ac.jp). 00230 */ 00231 /* Registers that must be saved during a context switch. 00232 * These are the offsets from the beginning of the Thread object, 00233 * in bytes, used in switch.s 00234 */ 00235 #define SP (0*8) 00236 #define S0 (1*8) 00237 #define S1 (2*8) 00238 #define S2 (3*8) 00239 #define S3 (4*8) 00240 #define S4 (5*8) 00241 #define S5 (6*8) 00242 #define S6 (7*8) /* used as FP (Frame Pointer) */ 00243 #define GP (8*8) 00244 #define PC (9*8) 00245 00246 /* To fork a thread, we set up its saved register state, so that 00247 * when we switch to the thread, it will start running in ThreadRoot. 00248 * 00249 * The following are the initial registers we need to set up to 00250 * pass values into ThreadRoot (for instance, containing the procedure 00251 * for the thread to run). The first set is the registers as used 00252 * by ThreadRoot; the second set is the locations for these initial 00253 * values in the Thread object -- used in Thread::StackAllocate(). 00254 */ 00255 #define InitialPC s0 00256 #define InitialArg s1 00257 #define WhenDonePC s2 00258 #define StartupPC s3 00259 00260 #define PCState (PC/8-1) 00261 #define FPState (S6/8-1) 00262 #define InitialPCState (S0/8-1) 00263 #define InitialArgState (S1/8-1) 00264 #define WhenDonePCState (S2/8-1) 00265 #define StartupPCState (S3/8-1) 00266 00267 #endif // HOST_ALPHA 00268 00269 #endif // SWITCH_H

Generated on Thu Sep 16 12:33:45 2004 for NachOS by doxygen 1.3.8