1/* 2 * QuickThreads -- Threads-building toolkit. 3 * Copyright (c) 1993 by David Keppel 4 * 5 * Permission to use, copy, modify and distribute this software and 6 * its documentation for any purpose and without fee is hereby 7 * granted, provided that the above copyright notice and this notice 8 * appear in all copies. This software is provided as a 9 * proof-of-concept and for demonstration purposes; there is no 10 * representation about the suitability of this software for any 11 * purpose. 12 */ 13 14#ifndef QUICKTHREADS_MIPS_H 15#define QUICKTHREADS_MIPS_H 16 17typedef unsigned long qt_word_t; 18 19#define QUICKTHREADS_GROW_DOWN 20 21/* Stack layout on the mips: 22 23 Callee-save registers are: $16-$23, $30; $f20-$f30. 24 Also save $31, return pc. 25 26 Non-varargs: 27 28 +--- 29 | $f30 The first clump is only saved if `qt_block' 30 | $f28 is called, in which case it saves the fp regs 31 | $f26 then calls `qt_blocki' to save the int regs. 32 | $f24 33 | $f22 34 | $f20 35 | $31 === return pc in `qt_block' 36 +--- 37 | $31 === return pc; on startup == qt_start 38 | $30 39 | $23 40 | $22 41 | $21 42 | $20 43 | $19 on startup === only 44 | $18 on startup === $a2 === userf 45 | $17 on startup === $a1 === pt 46 | $16 on startup === $a0 === pu 47 | <a3> save area req'd by MIPS calling convention 48 | <a2> save area req'd by MIPS calling convention 49 | <a1> save area req'd by MIPS calling convention 50 | <a0> save area req'd by MIPS calling convention <--- sp 51 +--- 52 53 Conventions for varargs: 54 55 | args ... 56 +--- 57 | : 58 | : 59 | $21 60 | $20 61 | $19 on startup === `userf' 62 | $18 on startup === `startup' 63 | $17 on startup === `pt' 64 | $16 on startup === `cleanup' 65 | <a3> 66 | <a2> 67 | <a1> 68 | <a0> <--- sp 69 +--- 70 71 Note: if we wanted to, we could muck about and try to get the 4 72 argument registers loaded in to, e.g., $22, $23, $30, and $31, 73 and the return pc in, say, $20. Then, the first 4 args would 74 not need to be loaded from memory, they could just use 75 register-to-register copies. */ 76 77 78/* Stack must be doubleword aligned. */ 79#define QUICKTHREADS_STKALIGN (8) /* Doubleword aligned. */ 80 81/* How much space is allocated to hold all the crud for 82 initialization: $16-$23, $30, $31. Just do an integer restore, 83 no need to restore floating-point. Four words are needed for the 84 argument save area for the helper function that will be called for 85 the old thread, just before the new thread starts to run. */ 86 87#define QUICKTHREADS_STKBASE (14 * 4) 88#define QUICKTHREADS_VSTKBASE QUICKTHREADS_STKBASE 89 90 91/* Offsets of various registers. */ 92#define QUICKTHREADS_31 (9+4) 93#define QUICKTHREADS_19 (3+4) 94#define QUICKTHREADS_18 (2+4) 95#define QUICKTHREADS_17 (1+4) 96#define QUICKTHREADS_16 (0+4) 97 98 99/* When a never-before-run thread is restored, the return pc points 100 to a fragment of code that starts the thread running. For 101 non-vargs functions, it just calls the client's `only' function. 102 For varargs functions, it calls the startup, user, and cleanup 103 functions. 104 105 The varargs startup routine always reads 4 words of arguments from 106 the stack. If there are less than 4 words of arguments, then the 107 startup routine can read off the top of the stack. To prevent 108 errors we always allocate 4 words. If there are more than 3 words 109 of arguments, the 4 preallocated words are simply wasted. */ 110 111extern void qt_start(void); 112#define QUICKTHREADS_ARGS_MD(sp) (QUICKTHREADS_SPUT (sp, QUICKTHREADS_31, qt_start)) 113 114#define QUICKTHREADS_VARGS_MD0(sp, vabytes) \ 115 ((qt_t *)(((char *)(sp)) - 4*4 - QUICKTHREADS_STKROUNDUP(vabytes))) 116 117extern void qt_vstart(void); 118#define QUICKTHREADS_VARGS_MD1(sp) (QUICKTHREADS_SPUT (sp, QUICKTHREADS_31, qt_vstart)) 119 120#define QUICKTHREADS_VARGS_DEFAULT 121 122 123/* The *index* (positive offset) of where to put each value. */ 124#define QUICKTHREADS_ONLY_INDEX (QUICKTHREADS_19) 125#define QUICKTHREADS_USER_INDEX (QUICKTHREADS_18) 126#define QUICKTHREADS_ARGT_INDEX (QUICKTHREADS_17) 127#define QUICKTHREADS_ARGU_INDEX (QUICKTHREADS_16) 128 129#define QUICKTHREADS_VCLEANUP_INDEX (QUICKTHREADS_16) 130#define QUICKTHREADS_VUSERF_INDEX (QUICKTHREADS_19) 131#define QUICKTHREADS_VSTARTUP_INDEX (QUICKTHREADS_18) 132#define QUICKTHREADS_VARGT_INDEX (QUICKTHREADS_17) 133 134#endif /* ndef QUICKTHREADS_MIPS_H */ 135