* class.c (check_bitfield_decl): New function, split out from
[official-gcc.git] / boehm-gc / mach_dep.c
blob52f863467619385913d786b8daff604d4fe3700a
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
83 # ifdef VAX
84 /* VAX - generic code below does not work under 4.2 */
85 /* r1 through r5 are caller save, and therefore */
86 /* on the stack or dead. */
87 asm("pushl r11"); asm("calls $1,_GC_push_one");
88 asm("pushl r10"); asm("calls $1,_GC_push_one");
89 asm("pushl r9"); asm("calls $1,_GC_push_one");
90 asm("pushl r8"); asm("calls $1,_GC_push_one");
91 asm("pushl r7"); asm("calls $1,_GC_push_one");
92 asm("pushl r6"); asm("calls $1,_GC_push_one");
93 # endif
94 # if defined(M68K) && (defined(SUNOS4) || defined(NEXT))
95 /* M68K SUNOS - could be replaced by generic code */
96 /* a0, a1 and d1 are caller save */
97 /* and therefore are on stack or dead. */
99 asm("subqw #0x4,sp"); /* allocate word on top of stack */
101 asm("movl a2,sp@"); asm("jbsr _GC_push_one");
102 asm("movl a3,sp@"); asm("jbsr _GC_push_one");
103 asm("movl a4,sp@"); asm("jbsr _GC_push_one");
104 asm("movl a5,sp@"); asm("jbsr _GC_push_one");
105 /* Skip frame pointer and stack pointer */
106 asm("movl d1,sp@"); asm("jbsr _GC_push_one");
107 asm("movl d2,sp@"); asm("jbsr _GC_push_one");
108 asm("movl d3,sp@"); asm("jbsr _GC_push_one");
109 asm("movl d4,sp@"); asm("jbsr _GC_push_one");
110 asm("movl d5,sp@"); asm("jbsr _GC_push_one");
111 asm("movl d6,sp@"); asm("jbsr _GC_push_one");
112 asm("movl d7,sp@"); asm("jbsr _GC_push_one");
114 asm("addqw #0x4,sp"); /* put stack back where it was */
115 # endif
117 # if defined(M68K) && defined(HP)
118 /* M68K HP - could be replaced by generic code */
119 /* a0, a1 and d1 are caller save. */
121 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
123 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
124 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
125 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
126 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
127 /* Skip frame pointer and stack pointer */
128 asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one");
129 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
130 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
131 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
132 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
133 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
134 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
136 asm("addq.w &0x4,%sp"); /* put stack back where it was */
137 # endif /* M68K HP */
139 # if defined(M68K) && defined(AMIGA)
140 /* AMIGA - could be replaced by generic code */
141 /* a0, a1, d0 and d1 are caller save */
143 # ifdef __GNUC__
144 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
146 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
147 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
148 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
149 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
150 asm("mov.l %a6,(%sp)"); asm("jsr _GC_push_one");
151 /* Skip frame pointer and stack pointer */
152 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
153 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
154 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
155 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
156 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
157 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
159 asm("addq.w &0x4,%sp"); /* put stack back where it was */
160 # else /* !__GNUC__ */
161 GC_push_one(getreg(REG_A2));
162 GC_push_one(getreg(REG_A3));
163 GC_push_one(getreg(REG_A4));
164 GC_push_one(getreg(REG_A5));
165 GC_push_one(getreg(REG_A6));
166 /* Skip stack pointer */
167 GC_push_one(getreg(REG_D2));
168 GC_push_one(getreg(REG_D3));
169 GC_push_one(getreg(REG_D4));
170 GC_push_one(getreg(REG_D5));
171 GC_push_one(getreg(REG_D6));
172 GC_push_one(getreg(REG_D7));
173 # endif /* !__GNUC__ */
174 # endif /* AMIGA */
176 # if defined(M68K) && defined(MACOS)
177 # if defined(THINK_C)
178 # define PushMacReg(reg) \
179 move.l reg,(sp) \
180 jsr GC_push_one
181 asm {
182 sub.w #4,sp ; reserve space for one parameter.
183 PushMacReg(a2);
184 PushMacReg(a3);
185 PushMacReg(a4);
186 ; skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
187 PushMacReg(d2);
188 PushMacReg(d3);
189 PushMacReg(d4);
190 PushMacReg(d5);
191 PushMacReg(d6);
192 PushMacReg(d7);
193 add.w #4,sp ; fix stack.
195 # undef PushMacReg
196 # endif /* THINK_C */
197 # if defined(__MWERKS__)
198 PushMacRegisters();
199 # endif /* __MWERKS__ */
200 # endif /* MACOS */
202 # if defined(I386) &&!defined(OS2) &&!defined(SVR4) &&!defined(MSWIN32) \
203 && !defined(SCO) && !defined(SCO_ELF) \
204 && !(defined(LINUX) && defined(__ELF__)) \
205 && !(defined(__FreeBSD__) && defined(__ELF__)) \
206 && !defined(DOS4GW)
207 /* I386 code, generic code does not appear to work */
208 /* It does appear to work under OS2, and asms dont */
209 /* This is used for some 38g UNIX variants and for CYGWIN32 */
210 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
211 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
212 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
213 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
214 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
215 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
216 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
217 # endif
219 # if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \
220 || ( defined(I386) && defined(__FreeBSD__) && defined(__ELF__) )
222 /* This is modified for Linux with ELF (Note: _ELF_ only) */
223 /* This section handles FreeBSD with ELF. */
224 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
225 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
226 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
227 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
228 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
229 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
230 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
231 # endif
233 # if defined(I386) && defined(MSWIN32) && !defined(USE_GENERIC)
234 /* I386 code, Microsoft variant */
235 __asm push eax
236 __asm call GC_push_one
237 __asm add esp,4
238 __asm push ebx
239 __asm call GC_push_one
240 __asm add esp,4
241 __asm push ecx
242 __asm call GC_push_one
243 __asm add esp,4
244 __asm push edx
245 __asm call GC_push_one
246 __asm add esp,4
247 __asm push ebp
248 __asm call GC_push_one
249 __asm add esp,4
250 __asm push esi
251 __asm call GC_push_one
252 __asm add esp,4
253 __asm push edi
254 __asm call GC_push_one
255 __asm add esp,4
256 # endif
258 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
259 /* I386 code, SVR4 variant, generic code does not appear to work */
260 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
261 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
262 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
263 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
264 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
265 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
266 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
267 # endif
269 # ifdef NS32K
270 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
271 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
272 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
273 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
274 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
275 # endif
277 # if defined(SPARC) || defined(IA64)
279 word GC_save_regs_in_stack();
281 /* generic code will not work */
282 GC_save_regs_ret_val = GC_save_regs_in_stack();
284 # endif
286 # ifdef RT
287 GC_push_one(TMP_SP); /* GC_push_one from r11 */
289 asm("cas r11, r6, r0"); GC_push_one(TMP_SP); /* r6 */
290 asm("cas r11, r7, r0"); GC_push_one(TMP_SP); /* through */
291 asm("cas r11, r8, r0"); GC_push_one(TMP_SP); /* r10 */
292 asm("cas r11, r9, r0"); GC_push_one(TMP_SP);
293 asm("cas r11, r10, r0"); GC_push_one(TMP_SP);
295 asm("cas r11, r12, r0"); GC_push_one(TMP_SP); /* r12 */
296 asm("cas r11, r13, r0"); GC_push_one(TMP_SP); /* through */
297 asm("cas r11, r14, r0"); GC_push_one(TMP_SP); /* r15 */
298 asm("cas r11, r15, r0"); GC_push_one(TMP_SP);
299 # endif
301 # if defined(M68K) && defined(SYSV)
302 /* Once again similar to SUN and HP, though setjmp appears to work.
303 --Parag
305 # ifdef __GNUC__
306 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
308 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
309 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
310 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
311 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
312 /* Skip frame pointer and stack pointer */
313 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
314 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
315 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
316 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
317 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
318 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
319 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
321 asm("addqw #0x4,%sp"); /* put stack back where it was */
322 # else /* !__GNUC__*/
323 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
325 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
326 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
327 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
328 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
329 /* Skip frame pointer and stack pointer */
330 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
331 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
332 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
333 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
334 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
335 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
336 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
338 asm("addq.w &0x4,%sp"); /* put stack back where it was */
339 # endif /* !__GNUC__ */
340 # endif /* M68K/SYSV */
342 # if defined(PJ)
344 register int * sp asm ("optop");
345 extern int *__libc_stack_end;
347 GC_push_all_stack (sp, __libc_stack_end);
349 # endif
351 /* other machines... */
352 # if !(defined M68K) && !(defined VAX) && !(defined RT)
353 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
354 # if !defined(POWERPC) && !defined(UTS4) && !defined(IA64)
355 # if !defined(PJ)
356 --> bad news <--
357 # endif
358 # endif
359 # endif
360 # endif
362 #endif /* !USE_GENERIC_PUSH_REGS */
364 #if defined(USE_GENERIC_PUSH_REGS)
365 void GC_generic_push_regs(cold_gc_frame)
366 ptr_t cold_gc_frame;
368 /* Generic code */
369 /* The idea is due to Parag Patel at HP. */
370 /* We're not sure whether he would like */
371 /* to be he acknowledged for it or not. */
373 static jmp_buf regs;
374 register word * i = (word *) regs;
375 register ptr_t lim = (ptr_t)(regs) + (sizeof regs);
377 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
378 /* That tends to preserve garbage. Clear it. */
379 for (; (char *)i < lim; i++) {
380 *i = 0;
382 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4)
383 (void) setjmp(regs);
384 # else
385 (void) _setjmp(regs);
386 # endif
387 GC_push_current_stack(cold_gc_frame);
390 #endif /* USE_GENERIC_PUSH_REGS */
392 /* On register window machines, we need a way to force registers into */
393 /* the stack. Return sp. */
394 # ifdef SPARC
395 asm(" .seg \"text\"");
396 # ifdef SVR4
397 asm(" .globl GC_save_regs_in_stack");
398 asm("GC_save_regs_in_stack:");
399 asm(" .type GC_save_regs_in_stack,#function");
400 # else
401 asm(" .globl _GC_save_regs_in_stack");
402 asm("_GC_save_regs_in_stack:");
403 # endif
404 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
405 asm(" mov %sp,%o0");
406 asm(" retl");
407 asm(" nop");
408 # ifdef SVR4
409 asm(" .GC_save_regs_in_stack_end:");
410 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
411 # endif
412 # ifdef LINT
413 word GC_save_regs_in_stack() { return(0 /* sp really */);}
414 # endif
415 # endif
417 /* On IA64, we also need to flush register windows. But they end */
418 /* up on the other side of the stack segment. */
419 /* Returns the backing store pointer for the register stack. */
420 # ifdef IA64
421 asm(" .text");
422 asm(" .psr abi64");
423 asm(" .psr lsb");
424 asm(" .lsb");
425 asm("");
426 asm(" .text");
427 asm(" .align 16");
428 asm(" .global GC_save_regs_in_stack");
429 asm(" .proc GC_save_regs_in_stack");
430 asm("GC_save_regs_in_stack:");
431 asm(" .body");
432 asm(" flushrs");
433 asm(" ;;");
434 asm(" mov r8=ar.bsp");
435 asm(" br.ret.sptk.few rp");
436 asm(" .endp GC_save_regs_in_stack");
437 # endif
439 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
440 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
441 /* an assembly version that's more careful. Assumes limit is hotter */
442 /* than sp, and limit is 8 byte aligned. */
443 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
444 #ifndef SPARC
445 --> fix it
446 #endif
447 # ifdef SUNOS4
448 asm(".globl _GC_clear_stack_inner");
449 asm("_GC_clear_stack_inner:");
450 # else
451 asm(".globl GC_clear_stack_inner");
452 asm("GC_clear_stack_inner:");
453 asm(".type GC_save_regs_in_stack,#function");
454 # endif
455 asm("mov %sp,%o2"); /* Save sp */
456 asm("add %sp,-8,%o3"); /* p = sp-8 */
457 asm("clr %g1"); /* [g0,g1] = 0 */
458 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
459 /* so that traps still work. */
460 /* Includes some extra words */
461 /* so we can be sloppy below. */
462 asm("loop:");
463 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
464 asm("cmp %o3,%o1");
465 asm("bgu loop "); /* if (p > limit) goto loop */
466 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
467 asm("retl");
468 asm("mov %o2,%sp"); /* Restore sp., delay slot */
469 /* First argument = %o0 = return value */
470 # ifdef SVR4
471 asm(" .GC_clear_stack_inner_end:");
472 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
473 # endif
475 # ifdef LINT
476 /*ARGSUSED*/
477 ptr_t GC_clear_stack_inner(arg, limit)
478 ptr_t arg; word limit;
479 { return(arg); }
480 # endif
481 #endif