112027Sjungma@eit.uni-kl.de/* 212027Sjungma@eit.uni-kl.de * QuickThreads -- Threads-building toolkit. 312027Sjungma@eit.uni-kl.de * Copyright (c) 1993 by David Keppel 412027Sjungma@eit.uni-kl.de * 512027Sjungma@eit.uni-kl.de * Permission to use, copy, modify and distribute this software and 612027Sjungma@eit.uni-kl.de * its documentation for any purpose and without fee is hereby 712027Sjungma@eit.uni-kl.de * granted, provided that the above copyright notice and this notice 812027Sjungma@eit.uni-kl.de * appear in all copies. This software is provided as a 912027Sjungma@eit.uni-kl.de * proof-of-concept and for demonstration purposes; there is no 1012027Sjungma@eit.uni-kl.de * representation about the suitability of this software for any 1112027Sjungma@eit.uni-kl.de * purpose. 1212027Sjungma@eit.uni-kl.de */ 1312027Sjungma@eit.uni-kl.de 1412027Sjungma@eit.uni-kl.de#ifndef QUICKTHREADS_MIPS_H 1512027Sjungma@eit.uni-kl.de#define QUICKTHREADS_MIPS_H 1612027Sjungma@eit.uni-kl.de 1712027Sjungma@eit.uni-kl.detypedef unsigned long qt_word_t; 1812027Sjungma@eit.uni-kl.de 1912027Sjungma@eit.uni-kl.de#define QUICKTHREADS_GROW_DOWN 2012027Sjungma@eit.uni-kl.de 2112027Sjungma@eit.uni-kl.de/* Stack layout on the mips: 2212027Sjungma@eit.uni-kl.de 2312027Sjungma@eit.uni-kl.de Callee-save registers are: $16-$23, $30; $f20-$f30. 2412027Sjungma@eit.uni-kl.de Also save $31, return pc. 2512027Sjungma@eit.uni-kl.de 2612027Sjungma@eit.uni-kl.de Non-varargs: 2712027Sjungma@eit.uni-kl.de 2812027Sjungma@eit.uni-kl.de +--- 2912027Sjungma@eit.uni-kl.de | $f30 The first clump is only saved if `qt_block' 3012027Sjungma@eit.uni-kl.de | $f28 is called, in which case it saves the fp regs 3112027Sjungma@eit.uni-kl.de | $f26 then calls `qt_blocki' to save the int regs. 3212027Sjungma@eit.uni-kl.de | $f24 3312027Sjungma@eit.uni-kl.de | $f22 3412027Sjungma@eit.uni-kl.de | $f20 3512027Sjungma@eit.uni-kl.de | $31 === return pc in `qt_block' 3612027Sjungma@eit.uni-kl.de +--- 3712027Sjungma@eit.uni-kl.de | $31 === return pc; on startup == qt_start 3812027Sjungma@eit.uni-kl.de | $30 3912027Sjungma@eit.uni-kl.de | $23 4012027Sjungma@eit.uni-kl.de | $22 4112027Sjungma@eit.uni-kl.de | $21 4212027Sjungma@eit.uni-kl.de | $20 4312027Sjungma@eit.uni-kl.de | $19 on startup === only 4412027Sjungma@eit.uni-kl.de | $18 on startup === $a2 === userf 4512027Sjungma@eit.uni-kl.de | $17 on startup === $a1 === pt 4612027Sjungma@eit.uni-kl.de | $16 on startup === $a0 === pu 4712027Sjungma@eit.uni-kl.de | <a3> save area req'd by MIPS calling convention 4812027Sjungma@eit.uni-kl.de | <a2> save area req'd by MIPS calling convention 4912027Sjungma@eit.uni-kl.de | <a1> save area req'd by MIPS calling convention 5012027Sjungma@eit.uni-kl.de | <a0> save area req'd by MIPS calling convention <--- sp 5112027Sjungma@eit.uni-kl.de +--- 5212027Sjungma@eit.uni-kl.de 5312027Sjungma@eit.uni-kl.de Conventions for varargs: 5412027Sjungma@eit.uni-kl.de 5512027Sjungma@eit.uni-kl.de | args ... 5612027Sjungma@eit.uni-kl.de +--- 5712027Sjungma@eit.uni-kl.de | : 5812027Sjungma@eit.uni-kl.de | : 5912027Sjungma@eit.uni-kl.de | $21 6012027Sjungma@eit.uni-kl.de | $20 6112027Sjungma@eit.uni-kl.de | $19 on startup === `userf' 6212027Sjungma@eit.uni-kl.de | $18 on startup === `startup' 6312027Sjungma@eit.uni-kl.de | $17 on startup === `pt' 6412027Sjungma@eit.uni-kl.de | $16 on startup === `cleanup' 6512027Sjungma@eit.uni-kl.de | <a3> 6612027Sjungma@eit.uni-kl.de | <a2> 6712027Sjungma@eit.uni-kl.de | <a1> 6812027Sjungma@eit.uni-kl.de | <a0> <--- sp 6912027Sjungma@eit.uni-kl.de +--- 7012027Sjungma@eit.uni-kl.de 7112027Sjungma@eit.uni-kl.de Note: if we wanted to, we could muck about and try to get the 4 7212027Sjungma@eit.uni-kl.de argument registers loaded in to, e.g., $22, $23, $30, and $31, 7312027Sjungma@eit.uni-kl.de and the return pc in, say, $20. Then, the first 4 args would 7412027Sjungma@eit.uni-kl.de not need to be loaded from memory, they could just use 7512027Sjungma@eit.uni-kl.de register-to-register copies. */ 7612027Sjungma@eit.uni-kl.de 7712027Sjungma@eit.uni-kl.de 7812027Sjungma@eit.uni-kl.de/* Stack must be doubleword aligned. */ 7912027Sjungma@eit.uni-kl.de#define QUICKTHREADS_STKALIGN (8) /* Doubleword aligned. */ 8012027Sjungma@eit.uni-kl.de 8112027Sjungma@eit.uni-kl.de/* How much space is allocated to hold all the crud for 8212027Sjungma@eit.uni-kl.de initialization: $16-$23, $30, $31. Just do an integer restore, 8312027Sjungma@eit.uni-kl.de no need to restore floating-point. Four words are needed for the 8412027Sjungma@eit.uni-kl.de argument save area for the helper function that will be called for 8512027Sjungma@eit.uni-kl.de the old thread, just before the new thread starts to run. */ 8612027Sjungma@eit.uni-kl.de 8712027Sjungma@eit.uni-kl.de#define QUICKTHREADS_STKBASE (14 * 4) 8812027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VSTKBASE QUICKTHREADS_STKBASE 8912027Sjungma@eit.uni-kl.de 9012027Sjungma@eit.uni-kl.de 9112027Sjungma@eit.uni-kl.de/* Offsets of various registers. */ 9212027Sjungma@eit.uni-kl.de#define QUICKTHREADS_31 (9+4) 9312027Sjungma@eit.uni-kl.de#define QUICKTHREADS_19 (3+4) 9412027Sjungma@eit.uni-kl.de#define QUICKTHREADS_18 (2+4) 9512027Sjungma@eit.uni-kl.de#define QUICKTHREADS_17 (1+4) 9612027Sjungma@eit.uni-kl.de#define QUICKTHREADS_16 (0+4) 9712027Sjungma@eit.uni-kl.de 9812027Sjungma@eit.uni-kl.de 9912027Sjungma@eit.uni-kl.de/* When a never-before-run thread is restored, the return pc points 10012027Sjungma@eit.uni-kl.de to a fragment of code that starts the thread running. For 10112027Sjungma@eit.uni-kl.de non-vargs functions, it just calls the client's `only' function. 10212027Sjungma@eit.uni-kl.de For varargs functions, it calls the startup, user, and cleanup 10312027Sjungma@eit.uni-kl.de functions. 10412027Sjungma@eit.uni-kl.de 10512027Sjungma@eit.uni-kl.de The varargs startup routine always reads 4 words of arguments from 10612027Sjungma@eit.uni-kl.de the stack. If there are less than 4 words of arguments, then the 10712027Sjungma@eit.uni-kl.de startup routine can read off the top of the stack. To prevent 10812027Sjungma@eit.uni-kl.de errors we always allocate 4 words. If there are more than 3 words 10912027Sjungma@eit.uni-kl.de of arguments, the 4 preallocated words are simply wasted. */ 11012027Sjungma@eit.uni-kl.de 11112027Sjungma@eit.uni-kl.deextern void qt_start(void); 11212027Sjungma@eit.uni-kl.de#define QUICKTHREADS_ARGS_MD(sp) (QUICKTHREADS_SPUT (sp, QUICKTHREADS_31, qt_start)) 11312027Sjungma@eit.uni-kl.de 11412027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VARGS_MD0(sp, vabytes) \ 11512027Sjungma@eit.uni-kl.de ((qt_t *)(((char *)(sp)) - 4*4 - QUICKTHREADS_STKROUNDUP(vabytes))) 11612027Sjungma@eit.uni-kl.de 11712027Sjungma@eit.uni-kl.deextern void qt_vstart(void); 11812027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VARGS_MD1(sp) (QUICKTHREADS_SPUT (sp, QUICKTHREADS_31, qt_vstart)) 11912027Sjungma@eit.uni-kl.de 12012027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VARGS_DEFAULT 12112027Sjungma@eit.uni-kl.de 12212027Sjungma@eit.uni-kl.de 12312027Sjungma@eit.uni-kl.de/* The *index* (positive offset) of where to put each value. */ 12412027Sjungma@eit.uni-kl.de#define QUICKTHREADS_ONLY_INDEX (QUICKTHREADS_19) 12512027Sjungma@eit.uni-kl.de#define QUICKTHREADS_USER_INDEX (QUICKTHREADS_18) 12612027Sjungma@eit.uni-kl.de#define QUICKTHREADS_ARGT_INDEX (QUICKTHREADS_17) 12712027Sjungma@eit.uni-kl.de#define QUICKTHREADS_ARGU_INDEX (QUICKTHREADS_16) 12812027Sjungma@eit.uni-kl.de 12912027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VCLEANUP_INDEX (QUICKTHREADS_16) 13012027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VUSERF_INDEX (QUICKTHREADS_19) 13112027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VSTARTUP_INDEX (QUICKTHREADS_18) 13212027Sjungma@eit.uni-kl.de#define QUICKTHREADS_VARGT_INDEX (QUICKTHREADS_17) 13312027Sjungma@eit.uni-kl.de 13412027Sjungma@eit.uni-kl.de#endif /* ndef QUICKTHREADS_MIPS_H */ 135