comparison ProcrContext.h @ 77:fe5ec83f1baf

separated hardware dependent code
author Merten Sach <msach@mailbox.tu-berlin.de>
date Wed, 22 Jun 2011 16:12:27 +0200
parents SwitchAnimators.h@9ddbb071142d
children 521c75d64cef
comparison
equal deleted inserted replaced
5:00e9e65e4ff9 0:dc6bf28fce24
4 * 4 *
5 * Author: seanhalle@yahoo.com 5 * Author: seanhalle@yahoo.com
6 * 6 *
7 */ 7 */
8 8
9 #ifndef _SwitchAnimators_H 9 #ifndef _ProcrContext_H
10 #define _SwitchAnimators_H 10 #define _ProcrContext_H
11 #define _GNU_SOURCE 11 #define _GNU_SOURCE
12 12
13 void saveCoreLoopReturnAddr(void **returnAddress); 13 void saveCoreLoopReturnAddr(void **returnAddress);
14 14
15 void switchToVP(VirtProcr *nextProcr); 15 void switchToVP(VirtProcr *nextProcr);
21 void startVirtProcrFn(); 21 void startVirtProcrFn();
22 22
23 #define flushRegisters() \ 23 #define flushRegisters() \
24 asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15") 24 asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15")
25 25
26 /*Isolating code for switching between animators within these macros -- at 26 inline VirtProcr *
27 * some point will make switches to compile for 32 bit or for 64 bit, which 27 create_procr_helper( VirtProcr *newPr, VirtProcrFnPtr fnPtr,
28 * having these isolated will make cleaner 28 void *initialData, void *stackLocs );
29 *
30 *This also makes it easier to change architectures, at some point
31 *And it cleans the code up, having the ugly assembly out of the way
32 */
33 29
34 /*Originally, let GCC handle input and output variables, which 30 #endif /* _ProcrContext_H */
35 * worked fine with -O0, but with -O3, it eliminated what it
36 * thought was un-used stores -- to fix this, am now hard-coding
37 * the offsets of the fields of VirtProcr and VMSMasterEnv data
38 * structs into the assembly for switching between VPs.
39 *To see what the offsets are, copy the following code to
40 * someplace, set compile to -O0 so it doesn't optimize, and
41 * set a break-point on the first line. In DDD or Eclipse, look
42 * at the disassembly to see what it compiled for the offsets.
43 *
44 void *foo;
45 foo = currPr->stackPtr; \
46 foo = currPr->framePtr; \
47 foo = currPr->nextInstrPt; \
48 foo = currPr->coreLoopStackPtr;
49 foo = currPr->coreLoopFramePtr;
50 foo = _VMSMasterEnv->coreLoopStartPt;
51 foo = _VMSMasterEnv->coreLoopEndPt;
52 foo = _VMSMasterEnv->masterLock;
53 31
54 * VirtProcr offsets:
55 * 0xc stackPtr
56 * 0x10 framePtr
57 * 0x14 nextInstrPt
58 * 0x1c coreLoopFramePtr
59 * 0x20 coreLoopStackPtr
60 *
61 * _VMSMasterEnv offsets:
62 * 0x24 coreLoopStartPt
63 * 0x28 coreLoopEndPt
64 * 0x30 masterLock
65 *
66 *For reference on the switch-VP assembly, the %%eax, %%ebx, %%ecx are
67 * general purpose registers -- the "clobber" at the end tells GCC that the
68 * values in the listed registers are overwritten inside the assembly, so
69 * that GCC doesn't rely on keeping values in registers across the assembly.
70 *The "input" tells GCC to generate the assembly form of the variable name.
71 *The "%0" and "%1" mean the first and second items in the "input" list at
72 * the bottom, respectively. So, where %0 appears, GCC looks at the bottom,
73 * gets the first item it sees, generates the assembly for accessing that
74 * variable, and replaces %0 with that.
75 *
76 *%%ebp is the frame-ptr register and %%esp is the stack-ptr register
77 */
78
79
80
81 //=========================== SlaveVP to CoreLoop ===========================
82 //
83
84
85 //============================== CoreLoop to VP =============================
86 //
87 //Save the core loop's stack and frame pointers into virt procr struct
88 // then switch to stack ptr and frame ptr of virt procr & jmp to it
89 //This was a pain to get right because GCC converts the "(jmpPt)" to
90 // frame-relative mem-op -- so generated machine code first changed the
91 // frame pointer, then tried to jump to an addr stored on stack, which
92 // it accessed as an offset from frame-ptr! (wrong frame-ptr now)
93 //Explicitly loading into eax before changing frame-ptr fixed it
94 //Also, it turns "(currPr->coreLoopFramePtr)" into a temporary on the
95 // stack, so "movl %%ebp, %0" saves to the temp, NOT the data-struc!
96
97
98
99
100 #endif /* _SwitchAnimators_H */
101