* cpphash.c (save_expansion): Clear PREV_WHITE on tokens
[official-gcc.git] / boehm-gc / mach_dep.c
blob2936fd7f992fe65284a22d68626c3afc454c5488
1 /*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
14 /* Boehm, November 17, 1995 12:13 pm PST */
15 # include "gc_priv.h"
16 # include <stdio.h>
17 # include <setjmp.h>
18 # if defined(OS2) || defined(CX_UX)
19 # define _setjmp(b) setjmp(b)
20 # define _longjmp(b,v) longjmp(b,v)
21 # endif
22 # ifdef AMIGA
23 # ifndef __GNUC__
24 # include <dos/dos.h>
25 # else
26 # include <machine/reg.h>
27 # endif
28 # endif
30 #if defined(__MWERKS__) && !defined(POWERPC)
32 asm static void PushMacRegisters()
34 sub.w #4,sp // reserve space for one parameter.
35 move.l a2,(sp)
36 jsr GC_push_one
37 move.l a3,(sp)
38 jsr GC_push_one
39 move.l a4,(sp)
40 jsr GC_push_one
41 # if !__option(a6frames)
42 // <pcb> perhaps a6 should be pushed if stack frames are not being used.
43 move.l a6,(sp)
44 jsr GC_push_one
45 # endif
46 // skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
47 move.l d2,(sp)
48 jsr GC_push_one
49 move.l d3,(sp)
50 jsr GC_push_one
51 move.l d4,(sp)
52 jsr GC_push_one
53 move.l d5,(sp)
54 jsr GC_push_one
55 move.l d6,(sp)
56 jsr GC_push_one
57 move.l d7,(sp)
58 jsr GC_push_one
59 add.w #4,sp // fix stack.
60 rts
63 #endif /* __MWERKS__ */
65 # if defined(SPARC) || defined(IA64)
66 /* Value returned from register flushing routine; either sp (SPARC) */
67 /* or ar.bsp (IA64) */
68 word GC_save_regs_ret_val;
69 # endif
71 /* Routine to mark from registers that are preserved by the C compiler. */
72 /* This must be ported to every new architecture. There is a generic */
73 /* version at the end, that is likely, but not guaranteed to work */
74 /* on your architecture. Run the test_setjmp program to see whether */
75 /* there is any chance it will work. */
77 #ifndef USE_GENERIC_PUSH_REGS
78 void GC_push_regs()
80 # ifdef RT
81 register long TMP_SP; /* must be bound to r11 */
82 # endif
84 # if defined(MIPS) && defined(LINUX)
85 /* I'm not sure whether this has actually been tested. */
86 # define call_push(x) asm("move $4," x ";"); asm("jal GC_push_one")
87 call_push("$2");
88 call_push("$3");
89 call_push("$16");
90 call_push("$17");
91 call_push("$18");
92 call_push("$19");
93 call_push("$20");
94 call_push("$21");
95 call_push("$22");
96 call_push("$23");
97 call_push("$30");
98 # undef call_push
99 # endif /* MIPS && LINUX */
101 # ifdef VAX
102 /* VAX - generic code below does not work under 4.2 */
103 /* r1 through r5 are caller save, and therefore */
104 /* on the stack or dead. */
105 asm("pushl r11"); asm("calls $1,_GC_push_one");
106 asm("pushl r10"); asm("calls $1,_GC_push_one");
107 asm("pushl r9"); asm("calls $1,_GC_push_one");
108 asm("pushl r8"); asm("calls $1,_GC_push_one");
109 asm("pushl r7"); asm("calls $1,_GC_push_one");
110 asm("pushl r6"); asm("calls $1,_GC_push_one");
111 # endif
112 # if defined(M68K) && (defined(SUNOS4) || defined(NEXT))
113 /* M68K SUNOS - could be replaced by generic code */
114 /* a0, a1 and d1 are caller save */
115 /* and therefore are on stack or dead. */
117 asm("subqw #0x4,sp"); /* allocate word on top of stack */
119 asm("movl a2,sp@"); asm("jbsr _GC_push_one");
120 asm("movl a3,sp@"); asm("jbsr _GC_push_one");
121 asm("movl a4,sp@"); asm("jbsr _GC_push_one");
122 asm("movl a5,sp@"); asm("jbsr _GC_push_one");
123 /* Skip frame pointer and stack pointer */
124 asm("movl d1,sp@"); asm("jbsr _GC_push_one");
125 asm("movl d2,sp@"); asm("jbsr _GC_push_one");
126 asm("movl d3,sp@"); asm("jbsr _GC_push_one");
127 asm("movl d4,sp@"); asm("jbsr _GC_push_one");
128 asm("movl d5,sp@"); asm("jbsr _GC_push_one");
129 asm("movl d6,sp@"); asm("jbsr _GC_push_one");
130 asm("movl d7,sp@"); asm("jbsr _GC_push_one");
132 asm("addqw #0x4,sp"); /* put stack back where it was */
133 # endif
135 # if defined(M68K) && defined(HP)
136 /* M68K HP - could be replaced by generic code */
137 /* a0, a1 and d1 are caller save. */
139 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
141 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
142 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
143 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
144 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
145 /* Skip frame pointer and stack pointer */
146 asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one");
147 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
148 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
149 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
150 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
151 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
152 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
154 asm("addq.w &0x4,%sp"); /* put stack back where it was */
155 # endif /* M68K HP */
157 # if defined(M68K) && defined(AMIGA)
158 /* AMIGA - could be replaced by generic code */
159 /* a0, a1, d0 and d1 are caller save */
161 # ifdef __GNUC__
162 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
164 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
165 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
166 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
167 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
168 asm("mov.l %a6,(%sp)"); asm("jsr _GC_push_one");
169 /* Skip frame pointer and stack pointer */
170 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
171 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
172 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
173 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
174 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
175 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
177 asm("addq.w &0x4,%sp"); /* put stack back where it was */
178 # else /* !__GNUC__ */
179 GC_push_one(getreg(REG_A2));
180 GC_push_one(getreg(REG_A3));
181 GC_push_one(getreg(REG_A4));
182 GC_push_one(getreg(REG_A5));
183 GC_push_one(getreg(REG_A6));
184 /* Skip stack pointer */
185 GC_push_one(getreg(REG_D2));
186 GC_push_one(getreg(REG_D3));
187 GC_push_one(getreg(REG_D4));
188 GC_push_one(getreg(REG_D5));
189 GC_push_one(getreg(REG_D6));
190 GC_push_one(getreg(REG_D7));
191 # endif /* !__GNUC__ */
192 # endif /* AMIGA */
194 # if defined(M68K) && defined(MACOS)
195 # if defined(THINK_C)
196 # define PushMacReg(reg) \
197 move.l reg,(sp) \
198 jsr GC_push_one
199 asm {
200 sub.w #4,sp ; reserve space for one parameter.
201 PushMacReg(a2);
202 PushMacReg(a3);
203 PushMacReg(a4);
204 ; skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
205 PushMacReg(d2);
206 PushMacReg(d3);
207 PushMacReg(d4);
208 PushMacReg(d5);
209 PushMacReg(d6);
210 PushMacReg(d7);
211 add.w #4,sp ; fix stack.
213 # undef PushMacReg
214 # endif /* THINK_C */
215 # if defined(__MWERKS__)
216 PushMacRegisters();
217 # endif /* __MWERKS__ */
218 # endif /* MACOS */
220 # if defined(I386) &&!defined(OS2) &&!defined(SVR4) \
221 && (defined(__MINGW32__) || !defined(MSWIN32)) \
222 && !defined(SCO) && !defined(SCO_ELF) \
223 && !(defined(LINUX) && defined(__ELF__)) \
224 && !(defined(FREEBSD) && defined(__ELF__)) \
225 && !defined(DOS4GW)
226 /* I386 code, generic code does not appear to work */
227 /* It does appear to work under OS2, and asms dont */
228 /* This is used for some 38g UNIX variants and for CYGWIN32 */
229 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
230 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
231 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
232 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
233 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
234 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
235 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
236 # endif
238 # if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \
239 || ( defined(I386) && defined(FREEBSD) && defined(__ELF__) )
241 /* This is modified for Linux with ELF (Note: _ELF_ only) */
242 /* This section handles FreeBSD with ELF. */
243 /* Eax is caller-save and dead here. Other caller-save */
244 /* registers could also be skipped. We assume there are no */
245 /* pointers in MMX registers, etc. */
246 /* We combine instructions in a single asm to prevent gcc from */
247 /* inserting code in the middle. */
248 asm("pushl %ecx; call GC_push_one; addl $4,%esp");
249 asm("pushl %edx; call GC_push_one; addl $4,%esp");
250 asm("pushl %ebp; call GC_push_one; addl $4,%esp");
251 asm("pushl %esi; call GC_push_one; addl $4,%esp");
252 asm("pushl %edi; call GC_push_one; addl $4,%esp");
253 asm("pushl %ebx; call GC_push_one; addl $4,%esp");
254 # endif
256 # if defined(I386) && defined(MSWIN32) && !defined(__MINGW32__) \
257 && !defined(USE_GENERIC)
258 /* I386 code, Microsoft variant */
259 __asm push eax
260 __asm call GC_push_one
261 __asm add esp,4
262 __asm push ebx
263 __asm call GC_push_one
264 __asm add esp,4
265 __asm push ecx
266 __asm call GC_push_one
267 __asm add esp,4
268 __asm push edx
269 __asm call GC_push_one
270 __asm add esp,4
271 __asm push ebp
272 __asm call GC_push_one
273 __asm add esp,4
274 __asm push esi
275 __asm call GC_push_one
276 __asm add esp,4
277 __asm push edi
278 __asm call GC_push_one
279 __asm add esp,4
280 # endif
282 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
283 /* I386 code, SVR4 variant, generic code does not appear to work */
284 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
285 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
286 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
287 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
288 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
289 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
290 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
291 # endif
293 # ifdef NS32K
294 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
295 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
296 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
297 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
298 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
299 # endif
301 # if defined(SPARC)
303 word GC_save_regs_in_stack();
305 GC_save_regs_ret_val = GC_save_regs_in_stack();
307 # endif
309 # ifdef RT
310 GC_push_one(TMP_SP); /* GC_push_one from r11 */
312 asm("cas r11, r6, r0"); GC_push_one(TMP_SP); /* r6 */
313 asm("cas r11, r7, r0"); GC_push_one(TMP_SP); /* through */
314 asm("cas r11, r8, r0"); GC_push_one(TMP_SP); /* r10 */
315 asm("cas r11, r9, r0"); GC_push_one(TMP_SP);
316 asm("cas r11, r10, r0"); GC_push_one(TMP_SP);
318 asm("cas r11, r12, r0"); GC_push_one(TMP_SP); /* r12 */
319 asm("cas r11, r13, r0"); GC_push_one(TMP_SP); /* through */
320 asm("cas r11, r14, r0"); GC_push_one(TMP_SP); /* r15 */
321 asm("cas r11, r15, r0"); GC_push_one(TMP_SP);
322 # endif
324 # if defined(M68K) && defined(SYSV)
325 /* Once again similar to SUN and HP, though setjmp appears to work.
326 --Parag
328 # ifdef __GNUC__
329 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
331 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
332 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
333 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
334 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
335 /* Skip frame pointer and stack pointer */
336 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
337 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
338 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
339 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
340 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
341 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
342 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
344 asm("addqw #0x4,%sp"); /* put stack back where it was */
345 # else /* !__GNUC__*/
346 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
348 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
349 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
350 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
351 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
352 /* Skip frame pointer and stack pointer */
353 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
354 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
355 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
356 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
357 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
358 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
359 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
361 asm("addq.w &0x4,%sp"); /* put stack back where it was */
362 # endif /* !__GNUC__ */
363 # endif /* M68K/SYSV */
365 # if defined(PJ)
367 register int * sp asm ("optop");
368 extern int *__libc_stack_end;
370 GC_push_all_stack (sp, __libc_stack_end);
372 # endif
374 /* other machines... */
375 # if !(defined M68K) && !(defined VAX) && !(defined RT)
376 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
377 # if !defined(POWERPC) && !defined(UTS4)
378 # if !defined(PJ) && !(defined(MIPS) && defined(LINUX))
379 --> bad news <--
380 # endif
381 # endif
382 # endif
383 # endif
385 #endif /* !USE_GENERIC_PUSH_REGS */
387 #if defined(USE_GENERIC_PUSH_REGS)
388 void GC_generic_push_regs(cold_gc_frame)
389 ptr_t cold_gc_frame;
391 /* Generic code */
392 /* The idea is due to Parag Patel at HP. */
393 /* We're not sure whether he would like */
394 /* to be he acknowledged for it or not. */
396 static jmp_buf regs;
397 register word * i = (word *) regs;
398 register ptr_t lim = (ptr_t)(regs) + (sizeof regs);
400 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
401 /* That tends to preserve garbage. Clear it. */
402 for (; (char *)i < lim; i++) {
403 *i = 0;
405 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4) || defined(LINUX)
406 (void) setjmp(regs);
407 # else
408 (void) _setjmp(regs);
409 # endif
410 # if defined(SPARC) || defined(IA64)
411 /* On a register window machine, we need to save register */
412 /* contents on the stack for this to work. The setjmp */
413 /* is probably not needed on SPARC, since pointers are */
414 /* only stored in windowed or scratch registers. It is */
415 /* needed on IA64, since some non-windowed registers are */
416 /* preserved. */
418 word GC_save_regs_in_stack();
420 GC_save_regs_ret_val = GC_save_regs_in_stack();
422 # endif
423 GC_push_current_stack(cold_gc_frame);
426 #endif /* USE_GENERIC_PUSH_REGS */
428 /* On register window machines, we need a way to force registers into */
429 /* the stack. Return sp. */
430 # ifdef SPARC
431 asm(" .seg \"text\"");
432 # ifdef SVR4
433 asm(" .globl GC_save_regs_in_stack");
434 asm("GC_save_regs_in_stack:");
435 asm(" .type GC_save_regs_in_stack,#function");
436 # else
437 asm(" .globl _GC_save_regs_in_stack");
438 asm("_GC_save_regs_in_stack:");
439 # endif
440 # if defined(__arch64__) || defined(__sparcv9)
441 asm(" save %sp,-128,%sp");
442 asm(" flushw");
443 asm(" ret");
444 asm(" restore %sp,2047+128,%o0");
445 # else
446 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
447 asm(" retl");
448 asm(" mov %sp,%o0");
449 #endif
450 # ifdef SVR4
451 asm(" .GC_save_regs_in_stack_end:");
452 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
453 # endif
454 # ifdef LINT
455 word GC_save_regs_in_stack() { return(0 /* sp really */);}
456 # endif
457 # endif
459 /* On IA64, we also need to flush register windows. But they end */
460 /* up on the other side of the stack segment. */
461 /* Returns the backing store pointer for the register stack. */
462 # ifdef IA64
463 asm(" .text");
464 asm(" .psr abi64");
465 asm(" .psr lsb");
466 asm(" .lsb");
467 asm("");
468 asm(" .text");
469 asm(" .align 16");
470 asm(" .global GC_save_regs_in_stack");
471 asm(" .proc GC_save_regs_in_stack");
472 asm("GC_save_regs_in_stack:");
473 asm(" .body");
474 asm(" flushrs");
475 asm(" ;;");
476 asm(" mov r8=ar.bsp");
477 asm(" br.ret.sptk.few rp");
478 asm(" .endp GC_save_regs_in_stack");
479 # endif
481 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
482 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
483 /* an assembly version that's more careful. Assumes limit is hotter */
484 /* than sp, and limit is 8 byte aligned. */
485 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
486 #ifndef SPARC
487 --> fix it
488 #endif
489 # ifdef SUNOS4
490 asm(".globl _GC_clear_stack_inner");
491 asm("_GC_clear_stack_inner:");
492 # else
493 asm(".globl GC_clear_stack_inner");
494 asm("GC_clear_stack_inner:");
495 asm(".type GC_save_regs_in_stack,#function");
496 # endif
497 #if defined(__arch64__) || defined(__sparcv9)
498 asm("mov %sp,%o2"); /* Save sp */
499 asm("add %sp,2047-8,%o3"); /* p = sp+bias-8 */
500 asm("add %o1,-2047-192,%sp"); /* Move sp out of the way, */
501 /* so that traps still work. */
502 /* Includes some extra words */
503 /* so we can be sloppy below. */
504 asm("loop:");
505 asm("stx %g0,[%o3]"); /* *(long *)p = 0 */
506 asm("cmp %o3,%o1");
507 asm("bgu,pt %xcc, loop"); /* if (p > limit) goto loop */
508 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
509 asm("retl");
510 asm("mov %o2,%sp"); /* Restore sp., delay slot */
511 #else
512 asm("mov %sp,%o2"); /* Save sp */
513 asm("add %sp,-8,%o3"); /* p = sp-8 */
514 asm("clr %g1"); /* [g0,g1] = 0 */
515 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
516 /* so that traps still work. */
517 /* Includes some extra words */
518 /* so we can be sloppy below. */
519 asm("loop:");
520 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
521 asm("cmp %o3,%o1");
522 asm("bgu loop "); /* if (p > limit) goto loop */
523 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
524 asm("retl");
525 asm("mov %o2,%sp"); /* Restore sp., delay slot */
526 #endif
527 /* First argument = %o0 = return value */
528 # ifdef SVR4
529 asm(" .GC_clear_stack_inner_end:");
530 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
531 # endif
533 # ifdef LINT
534 /*ARGSUSED*/
535 ptr_t GC_clear_stack_inner(arg, limit)
536 ptr_t arg; word limit;
537 { return(arg); }
538 # endif
539 #endif