Debian Codegraph @

src/h/cs.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */
3
4 /*
5 * Copyright (c) 1990, Giuseppe Attardi.
6 *
7 * See file 'LICENSE' for the copyright details.
8 *
9 */
10
11 /* cs.h -- C stack manipulation. */
12
13 /*
14 *----------------------------------------------------------------------
15 * Low level stack manipulation macros
16 *----------------------------------------------------------------------
17 */
18
19 #define asm __asm__
20
21 /*
22 *----------------------------------------------------------------------
23 * Stack of predefined size
24 *----------------------------------------------------------------------
25 */
26
27 #define cl_nextarg(arg) va_arg((arg),cl_object)
28
29 #define CSTACK(size) register cl_object *_stack_top; \
30 cl_object _stack_bot[size]; \
31 _stack_top = _stack_bot /* __GNUC__ */
32 #define CPUSH(val) *_stack_top++ = (val);
33
34 #define CSTACK_BOT _stack_bot
35 #define CSTACK_TOP _stack_top
36
37 /*---------------------------------------------------------------------- */
38
39 #if defined(__i386__) && 0
40 /* Stack usage:
41
42 sp | lclm |
43 | ... |
44 | lcl1 |
45 bp | obp |
46 | ret? |
47 | arg1 |
48 | ... |
49 osp | argn |
50 | ... |
51 obp | |
52
53 Caller pushes args and pops them after return. Result in ax.
54 */
55
56 #ifdef __GO32__ /* DJGPP */
57 typedef char * caddr_t;
58 #endif
59
60 #define GET_CURRENT_FRAME(frame) asm("movl (%%ebp),%0" : "=r" (frame))
61 #define FRAME_CHAIN(frame) ((char **)frame)[0]
62 #define FRAME_SAVED_PC(frame) ((char **)frame)[1]
63
64 #define PC_INDEX 8
65
66 #if 0
67 #define TRANSFER_CALL(fun) asm("leave"); goto *(fun) /* __GNUC__ */
68 #endif
69
70 #define CCALL(narg,fun) ({register cl_object eax asm("%eax"); \
71 asm("push %0" :: "g" (narg)); \
72 asm("call %0" :: "g" (fun) : "eax"); \
73 asm("addl $4, %%esp" :: ); eax;})
74
75 #if !defined(__linux__) && !defined(__FreeBSD__)
76 #define ARGCALL CCALL
77 #define ARGSTACK(size) CSTACK(size)
78 #endif
79
80 #endif
81
82 /*---------------------------------------------------------------------- */
83
84 #ifdef __mips
85
86 /* stack usage:
87
88 sp | |
89 | ... |
90 | save $31 | \ return pointer
91 | save regs | > frame offset
92 | locals | /
93 fp | arg1 | first arg of this function
94 | ... |
95 | argn |
96 | ... |
97 | |
98
99 */
100 /* Unfortunately MIPS stacks do not have enough information to chain through
101 them. FP is virtual, has no allocated register. We might reconstruct
102 framesize and frameoffset from first two instructions of procedure:
103
104 subu $sp, framesize
105 sw $ra, framesize+frameoffset($sp)
106
107 However we have no way to find the entry to a function given a PC.
108 GDB uses symbol information from the function to determine FP.
109 */
110
111 #define ARGSTACK(size) register cl_object *_stack_top; \
112 cl_object _stack_bot[size+1]; \
113 _stack_top = _stack_bot /* __GNUC__ */
114
115 #endif
116
117 /*---------------------------------------------------------------------- */
118
119 #if defined(sparc) && 0
120
121 /*
122 #define JB_SP 1
123 #define JB_PC 2
124 #define JB_FP 3
125 #define JB_NPC 4
126 #define JB_PSR 5
127 */
128
129 /*
130 * Got this info from gdb (config/sparc/tm-sparc.h and sparc-tdep.c)
131 */
132
133 #define GET_CURRENT_FRAME(frame) asm("mov %%fp,%0" : "=r" (frame))
134 #define FRAME_CHAIN(frame) ((caddr_t *)frame)[14]
135 #define FRAME_SAVED_PC(frame) ((caddr_t *)frame)[15]
136
137
138 /* GCC reserves 6 words for saving registers o0-05, but never does that */
139
140 #define ARGSTACK(size) register volatile cl_object *_stack_top; \
141 cl_object _stack_bot[size+1]; \
142 _stack_top = _stack_bot-6 /* __GNUC__ */
143
144 #define ARGCALL(narg, fun) ({ register cl_object _res asm("%o0"); \
145 asm("mov %0,%%o0" :: "r" (narg) : "%o0"); \
146 asm("ld [%%sp+72],%%o1" ::: "%o1"); \
147 asm("ld [%%sp+76],%%o2" ::: "%o2"); \
148 asm("ld [%%sp+80],%%o3" ::: "%o3"); \
149 asm("ld [%%sp+84],%%o4" ::: "%o4"); \
150 asm("ld [%%sp+88],%%o5" ::: "%o5"); \
151 asm("call %0,0" : : "r" (fun) ); \
152 asm("nop"); _res;})
153
154 #endif
155
156 /*---------------------------------------------------------------------- */
157
158 #if defined(vax) && 0
159 #define PC_INDEX 0
160 #define TRANSFER(buf, addr) buf[PC_INDEX] = (int)addr+((((int *)addr)[0] >> 19) & 4)+4; \
161 ecl_longjmp(buf)
162 #define TRANSFER_CALL(fun) REG = (cl_object)fun; \
163 asm(" ashl $-19,(r11),r0"); \
164 asm(" bicl2 $-5,r0"); \
165 asm(" addl2 r11,r0"); \
166 asm(" addl2 $4,r0"); \
167 asm(" jmp (r0)")
168 #define CSTACK(size) register cl_object REG
169 #define CPUSH(val) (REG = (cl_object)(val), \
170 asm(" pushl r11"))
171 #define CPOP (asm(" movl (sp)+,r11"), REG)
172
173 /* Reverse arguments on the stack, push narg, and then call.
174 narg (r11), up (r9), dn (r8)
175 for (dn = sp, up = sp+narg-1; dn < up; ) {
176 tmp = *dn; *dn++ = *up; *up-- = tmp;
177 }
178 */
179 #define CCALL(narg, fun) (REG = (cl_object)(narg), \
180 asm(" movl sp,r8"), \
181 asm(" ashl $2,r11,r0"), \
182 asm(" addl3 r0,sp,r9"), \
183 asm(" subl2 $4,r9"), \
184 asm("1: cmpl r8,r9"), \
185 asm(" jgeq 2f"), \
186 asm(" movl (r8),r7"), \
187 asm(" movl (r9),(r8)+"), \
188 asm(" movl r7,(r9)"), \
189 asm(" subl2 $4,r9"), \
190 asm(" jbr 1b"), \
191 asm("2: pushl r11"), \
192 asm(" addl3 $1,r11,r0"), \
193 REG = (cl_object)(fun), \
194 asm(" calls r0,(r11)"), \
195 asm(" movl r0,r11"), (int)REG)
196 #endif
197
198 /*---------------------------------------------------------------------- */