cd0656387750ca3ea4bcf642c139c0e975de2eab
[sbcl.git] / src / runtime / x86-assem.S
1 /*
2  * very-low-level utilities for runtime support
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15 \f
16 #define LANGUAGE_ASSEMBLY
17 #include "validate.h"
18 #include "sbcl.h"
19
20 /* Minimize conditionalization for different OS naming schemes. */
21 #if defined __linux__  || defined __FreeBSD__ /* (but *not* OpenBSD) */
22 #define GNAME(var) var
23 #else
24 #define GNAME(var) _##var
25 #endif
26
27 /* Get the right type of alignment. Linux and FreeBSD (but not OpenBSD)
28  * want alignment in bytes. */
29 #if defined(__linux__) || defined(__FreeBSD__)
30 #define align_4byte     4
31 #define align_8byte     8
32 #define align_16byte    16
33 #else
34 #define align_4byte     2
35 #define align_8byte     3
36 #define align_16byte    4       
37 #endif                  
38
39         .text
40         .global GNAME(foreign_function_call_active)
41         
42 \f
43 /*
44  * A call to call_into_c preserves esi, edi, and ebp.   
45  * (The C function will preserve ebx, esi, edi, and ebp across its
46  * function call, but we trash ebx ourselves by using it to save the
47  * return Lisp address.)
48  *
49  * Return values are in eax and maybe edx for quads, or st(0) for
50  * floats.
51  *
52  * This should work for Lisp calls C calls Lisp calls C..
53  */
54         .text
55         .align  align_16byte,0x90
56         .global GNAME(call_into_c)
57         .type   GNAME(call_into_c),@function
58 GNAME(call_into_c):
59         movl    $1,GNAME(foreign_function_call_active)
60
61 /* Save the return Lisp address in ebx. */
62         popl    %ebx
63
64 /* Setup the NPX for C */
65         fstp    %st(0)
66         fstp    %st(0)
67         fstp    %st(0)
68         fstp    %st(0)
69         fstp    %st(0)
70         fstp    %st(0)
71         fstp    %st(0)
72         fstp    %st(0)
73
74         call    *%eax           # normal callout using Lisp stack
75
76         movl    %eax,%ecx       # remember integer return value
77
78 /* Check for a return FP value. */
79         fxam
80         fnstsw  %eax
81         andl    $0x4500,%eax
82         cmpl    $0x4100,%eax
83         jne     Lfp_rtn_value
84
85 /* The return value is in eax, or eax,edx? */
86 /* Set up the NPX stack for Lisp. */
87         fldz                    # Ensure no regs are empty.
88         fldz
89         fldz
90         fldz
91         fldz
92         fldz
93         fldz
94         fldz
95
96 /* Restore the return value. */
97         movl    %ecx,%eax       # maybe return value
98
99         movl    $0,GNAME(foreign_function_call_active)
100 /* Return. */
101         jmp     *%ebx
102
103 Lfp_rtn_value:
104 /* The return result is in st(0). */
105 /* Set up the NPX stack for Lisp, placing the result in st(0). */
106         fldz                    # Ensure no regs are empty.
107         fldz
108         fldz
109         fldz
110         fldz
111         fldz
112         fldz
113         fxch    %st(7)          # Move the result back to st(0).
114
115 /* We don't need to restore eax, because the result is in st(0). */
116
117         movl    $0,GNAME(foreign_function_call_active)
118 /* Return. */   
119         jmp     *%ebx
120
121         .size   GNAME(call_into_c), . - GNAME(call_into_c)
122
123 \f
124         .text   
125         .global GNAME(call_into_lisp)
126         .type  GNAME(call_into_lisp),@function
127                 
128 /* The C conventions require that ebx, esi, edi, and ebp be preserved
129  * across function calls. */
130 /* The *ALIEN-STACK* pointer is set up on the first call_into_lisp when
131  * the stack changes. */
132         
133         .align  align_16byte,0x90
134 GNAME(call_into_lisp):
135         pushl   %ebp            # Save old frame pointer.
136         movl    %esp,%ebp       # Establish new frame.
137
138 /* Save the NPX state */
139         fwait                   # Catch any pending NPX exceptions.
140         subl    $108,%esp       # Make room for the NPX state.
141         fnsave  (%esp)          # resets NPX
142
143         movl    (%esp),%eax     # Load NPX control word.
144         andl    $0xfffff3ff,%eax        # Set rounding mode to nearest.
145         orl     $0x00000300,%eax        # Set precision to 64 bits.
146         pushl   %eax
147         fldcw   (%esp)          # Recover modes.
148         popl    %eax
149
150         fldz                    # Ensure no FP regs are empty.
151         fldz
152         fldz
153         fldz
154         fldz
155         fldz
156         fldz
157         fldz
158         
159 /* Save C regs: ebx esi edi. */
160         pushl   %ebx
161         pushl   %esi
162         pushl   %edi
163         
164 /* Clear descriptor regs. */
165         xorl    %eax,%eax       # lexenv
166         xorl    %ebx,%ebx       # available
167         xorl    %ecx,%ecx       # arg count
168         xorl    %edx,%edx       # first arg
169         xorl    %edi,%edi       # second arg
170         xorl    %esi,%esi       # third arg
171
172 /* no longer in function call */
173         movl    %eax, GNAME(foreign_function_call_active)
174
175         movl    %esp,%ebx       # remember current stack
176         cmpl    $CONTROL_STACK_START,%esp
177         jbe     ChangeToLispStack
178         cmpl    $CONTROL_STACK_END,%esp
179         jbe     OnLispStack
180 ChangeToLispStack:
181         /* Setup the *alien-stack* pointer */
182         movl    %esp,ALIEN_STACK + SYMBOL_VALUE_OFFSET
183         movl    $CONTROL_STACK_END,%esp         # new stack
184 OnLispStack:
185         pushl   %ebx            # Save entry stack on (maybe) new stack.
186
187         /* Establish Lisp args. */
188         movl     8(%ebp),%eax   # lexenv?
189         movl    12(%ebp),%ebx   # address of arg vec
190         movl    16(%ebp),%ecx   # num args
191         shll    $2,%ecx         # Make num args into fixnum.
192         cmpl    $0,%ecx
193         je      Ldone
194         movl    (%ebx),%edx     # arg0
195         cmpl    $4,%ecx
196         je      Ldone
197         movl    4(%ebx),%edi    # arg1
198         cmpl    $8,%ecx
199         je      Ldone
200         movl    8(%ebx),%esi    # arg2
201 Ldone:  
202         /* Registers eax, ecx, edx, edi, and esi are now live. */
203
204         /* Alloc new frame. */
205         mov     %esp,%ebx       # The current sp marks start of new frame.
206         push    %ebp            # fp in save location S0
207         sub     $8,%esp         # Ensure 3 slots are allocated, one above.
208         mov     %ebx,%ebp       # Switch to new frame.
209
210         /* Indirect the closure. */
211         call    *CLOSURE_FUN_OFFSET(%eax)
212         
213         /* Multi-value return; blow off any extra values. */
214         mov     %ebx, %esp
215         /* single value return */
216
217 /* Restore the stack, in case there was a stack change. */
218         popl    %esp            # c-sp
219
220 /* Restore C regs: ebx esi edi. */
221         popl    %edi
222         popl    %esi
223         popl    %ebx
224
225 /* Restore the NPX state. */
226         frstor  (%esp)
227         addl    $108, %esp
228         
229         popl    %ebp            # c-sp
230         movl    %edx,%eax       # c-val
231         ret
232         .size   GNAME(call_into_lisp), . - GNAME(call_into_lisp)
233 \f
234 /* support for saving and restoring the NPX state from C */
235         .text
236         .global GNAME(fpu_save)
237         .type   GNAME(fpu_save),@function
238         .align  2,0x90
239 GNAME(fpu_save):
240         movl    4(%esp),%eax
241         fnsave  (%eax)          # Save the NPX state. (resets NPX)
242         ret
243         .size   GNAME(fpu_save),.-GNAME(fpu_save)
244
245         .global GNAME(fpu_restore)
246         .type   GNAME(fpu_restore),@function
247         .align  2,0x90
248 GNAME(fpu_restore):
249         movl    4(%esp),%eax
250         frstor  (%eax)          # Restore the NPX state.
251         ret
252         .size   GNAME(fpu_restore),.-GNAME(fpu_restore)
253 \f
254 /*
255  * the undefined-function trampoline
256  */
257         .text
258         .align  align_4byte,0x90
259         .global GNAME(undefined_tramp)
260         .type   GNAME(undefined_tramp),@function
261 GNAME(undefined_tramp):
262         int3
263         .byte   trap_Error
264         .byte   2
265 #ifdef LONG_FLOAT_WIDETAG
266         .byte   24
267 #else
268         .byte   23
269 #endif
270         .byte   sc_DescriptorReg # eax in the Descriptor-reg SC
271         ret
272         .size   GNAME(undefined_tramp), .-GNAME(undefined_tramp)
273
274 /*
275  * the closure trampoline
276  */
277         .text
278         .align  align_4byte,0x90
279         .global GNAME(closure_tramp)
280         .type   GNAME(closure_tramp),@function
281 GNAME(closure_tramp):
282         movl    FDEFN_FUN_OFFSET(%eax),%eax
283         /* FIXME: The '*' after "jmp" in the next line is from PVE's
284          * patch posted to the CMU CL mailing list Oct 6, 1999. It looks
285          * reasonable, and it certainly seems as though if CMU CL needs it,
286          * SBCL needs it too, but I haven't actually verified that it's
287          * right. It would be good to find a way to force the flow of
288          * control through here to test it. */
289         jmp     *CLOSURE_FUN_OFFSET(%eax)
290         .size   GNAME(closure_tramp), .-GNAME(closure_tramp)
291
292 /*
293  * fun-end breakpoint magic
294  */
295         .text
296         .global GNAME(fun_end_breakpoint_guts)
297         .align  align_4byte
298 GNAME(fun_end_breakpoint_guts):
299         /* Multiple Value return */
300         jmp     multiple_value_return
301         /* Single value return: The eventual return will now use the
302            multiple values return convention but with a return values
303            count of one. */
304         movl    %esp,%ebx       # Setup ebx - the ofp.
305         subl    $4,%esp         # Allocate one stack slot for the return value
306         movl    $4,%ecx         # Setup ecx for one return value.
307         movl    $NIL,%edi       # default second value
308         movl    $NIL,%esi       # default third value
309                 
310 multiple_value_return:
311         
312         .global GNAME(fun_end_breakpoint_trap)
313 GNAME(fun_end_breakpoint_trap):
314         int3
315         .byte   trap_FunEndBreakpoint
316         hlt                     # We should never return here.
317
318         .global GNAME(fun_end_breakpoint_end)
319 GNAME(fun_end_breakpoint_end):
320
321 \f
322         .global GNAME(do_pending_interrupt)
323         .type   GNAME(do_pending_interrupt),@function
324         .align  align_4byte,0x90
325 GNAME(do_pending_interrupt):
326         int3
327         .byte   trap_PendingInterrupt
328         ret
329         .size   GNAME(do_pending_interrupt),.-GNAME(do_pending_interrupt)
330 \f
331 #ifdef GENCGC
332 /* This is a fast bzero using the FPU. The first argument is the start
333  * address which needs to be aligned on an 8 byte boundary, the second
334  * argument is the number of bytes, which must be a nonzero multiple
335  * of 8 bytes. */
336         .text
337         .globl  GNAME(i586_bzero)
338         .type   GNAME(i586_bzero),@function
339         .align  align_4byte,0x90
340 GNAME(i586_bzero):
341         movl    4(%esp),%edx    # Load the start address.
342         movl    8(%esp),%eax    # Load the number of bytes.
343         fldz
344 l1:     fstl    0(%edx)
345         addl    $8,%edx
346         subl    $8,%eax
347         jnz     l1
348         fstp    %st(0)
349         ret
350         .size   GNAME(i586_bzero),.-GNAME(i586_bzero)
351 #endif  
352 \f
353
354 /*
355  * Allocate bytes and return the start of the allocated space
356  * in the specified destination register.
357  *
358  * In the general case the size will be in the destination register.
359  *
360  * All registers must be preserved except the destination.
361  * The C conventions will preserve ebx, esi, edi, and ebp.
362  * So only eax, ecx, and edx need special care here.
363  */
364         
365         .globl  GNAME(alloc_to_eax)
366         .type   GNAME(alloc_to_eax),@function
367         .align  align_4byte,0x90
368 GNAME(alloc_to_eax):
369         pushl   %ecx    # Save ecx and edx as C could destroy them.
370         pushl   %edx
371         pushl   %eax    # Push the size.
372         call    GNAME(alloc)
373         addl    $4,%esp # Pop the size arg.
374         popl    %edx    # Restore ecx and edx.
375         popl    %ecx
376         ret
377         .size   GNAME(alloc_to_eax),.-GNAME(alloc_to_eax)
378
379         .globl  GNAME(alloc_8_to_eax)
380         .type   GNAME(alloc_8_to_eax),@function
381         .align  align_4byte,0x90
382 GNAME(alloc_8_to_eax):
383         pushl   %ecx    # Save ecx and edx as C could destroy them.
384         pushl   %edx
385         pushl   $8      # Push the size.
386         call    GNAME(alloc)
387         addl    $4,%esp # Pop the size arg.
388         popl    %edx    # Restore ecx and edx.
389         popl    %ecx
390         ret
391         .size   GNAME(alloc_8_to_eax),.-GNAME(alloc_8_to_eax)
392
393         .globl  GNAME(alloc_8_to_eax)
394         .type   GNAME(alloc_8_to_eax),@function
395         .align  align_4byte,0x90
396
397         .globl  GNAME(alloc_16_to_eax)
398         .type   GNAME(alloc_16_to_eax),@function
399         .align  align_4byte,0x90
400 GNAME(alloc_16_to_eax):
401         pushl   %ecx    # Save ecx and edx as C could destroy them.
402         pushl   %edx
403         pushl   $16     # Push the size.
404         call    GNAME(alloc)
405         addl    $4,%esp # Pop the size arg.
406         popl    %edx    # Restore ecx and edx.
407         popl    %ecx
408         ret
409         .size   GNAME(alloc_16_to_eax),.-GNAME(alloc_16_to_eax)
410
411         .globl  GNAME(alloc_to_ecx)
412         .type   GNAME(alloc_to_ecx),@function
413         .align  align_4byte,0x90
414 GNAME(alloc_to_ecx):
415         pushl   %eax    # Save eax and edx as C could destroy them.
416         pushl   %edx
417         pushl   %ecx    # Push the size.
418         call    GNAME(alloc)
419         addl    $4,%esp # Pop the size arg.
420         movl    %eax,%ecx       # Set up the destination.
421         popl    %edx    # Restore eax and edx.
422         popl    %eax
423         ret
424         .size   GNAME(alloc_to_ecx),.-GNAME(alloc_to_ecx)
425
426         .globl  GNAME(alloc_8_to_ecx)
427         .type   GNAME(alloc_8_to_ecx),@function
428         .align  align_4byte,0x90
429 GNAME(alloc_8_to_ecx):
430         pushl   %eax    # Save eax and edx as C could destroy them.
431         pushl   %edx
432         pushl   $8      # Push the size.
433         call    GNAME(alloc)
434         addl    $4,%esp # Pop the size arg.
435         movl    %eax,%ecx       # Set up the destination.
436         popl    %edx    # Restore eax and edx.
437         popl    %eax
438         ret
439         .size   GNAME(alloc_8_to_ecx),.-GNAME(alloc_8_to_ecx)
440
441         .globl  GNAME(alloc_16_to_ecx)
442         .type   GNAME(alloc_16_to_ecx),@function
443         .align  align_4byte,0x90
444 GNAME(alloc_16_to_ecx):
445         pushl   %eax    # Save eax and edx as C could destroy them.
446         pushl   %edx
447         pushl   $16     # Push the size.
448         call    GNAME(alloc)
449         addl    $4,%esp # Pop the size arg.
450         movl    %eax,%ecx       # Set up the destination.
451         popl    %edx    # Restore eax and edx.
452         popl    %eax
453         ret
454         .size   GNAME(alloc_16_to_ecx),.-GNAME(alloc_16_to_ecx)
455
456
457         .globl  GNAME(alloc_to_edx)
458         .type   GNAME(alloc_to_edx),@function
459         .align  align_4byte,0x90
460 GNAME(alloc_to_edx):
461         pushl   %eax    # Save eax and ecx as C could destroy them.
462         pushl   %ecx
463         pushl   %edx    # Push the size.
464         call    GNAME(alloc)
465         addl    $4,%esp # Pop the size arg.
466         movl    %eax,%edx       # Set up the destination.
467         popl    %ecx    # Restore eax and ecx.
468         popl    %eax
469         ret
470         .size   GNAME(alloc_to_edx),.-GNAME(alloc_to_edx)
471
472         .globl  GNAME(alloc_8_to_edx)
473         .type   GNAME(alloc_8_to_edx),@function
474         .align  align_4byte,0x90
475 GNAME(alloc_8_to_edx):
476         pushl   %eax    # Save eax and ecx as C could destroy them.
477         pushl   %ecx
478         pushl   $8      # Push the size.
479         call    GNAME(alloc)
480         addl    $4,%esp # Pop the size arg.
481         movl    %eax,%edx       # Set up the destination.
482         popl    %ecx    # Restore eax and ecx.
483         popl    %eax
484         ret
485         .size   GNAME(alloc_8_to_edx),.-GNAME(alloc_8_to_edx)
486
487         .globl  GNAME(alloc_16_to_edx)
488         .type   GNAME(alloc_16_to_edx),@function
489         .align  align_4byte,0x90
490 GNAME(alloc_16_to_edx):
491         pushl   %eax    # Save eax and ecx as C could destroy them.
492         pushl   %ecx
493         pushl   $16     # Push the size.
494         call    GNAME(alloc)
495         addl    $4,%esp # Pop the size arg.
496         movl    %eax,%edx       # Set up the destination.
497         popl    %ecx    # Restore eax and ecx.
498         popl    %eax
499         ret
500         .size   GNAME(alloc_16_to_edx),.-GNAME(alloc_16_to_edx)
501
502
503
504         .globl  GNAME(alloc_to_ebx)
505         .type   GNAME(alloc_to_ebx),@function
506         .align  align_4byte,0x90
507 GNAME(alloc_to_ebx):
508         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
509         pushl   %ecx
510         pushl   %edx
511         pushl   %ebx    # Push the size.
512         call    GNAME(alloc)
513         addl    $4,%esp # Pop the size arg.
514         movl    %eax,%ebx       # Set up the destination.
515         popl    %edx    # Restore eax, ecx and edx.
516         popl    %ecx
517         popl    %eax
518         ret
519         .size   GNAME(alloc_to_ebx),.-GNAME(alloc_to_ebx)
520
521         .globl  GNAME(alloc_8_to_ebx)
522         .type   GNAME(alloc_8_to_ebx),@function
523         .align  align_4byte,0x90
524 GNAME(alloc_8_to_ebx):
525         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
526         pushl   %ecx
527         pushl   %edx
528         pushl   $8      # Push the size.
529         call    GNAME(alloc)
530         addl    $4,%esp # Pop the size arg.
531         movl    %eax,%ebx       # Set up the destination.
532         popl    %edx    # Restore eax, ecx and edx.
533         popl    %ecx
534         popl    %eax
535         ret
536         .size   GNAME(alloc_8_to_ebx),.-GNAME(alloc_8_to_ebx)
537
538         .globl  GNAME(alloc_16_to_ebx)
539         .type   GNAME(alloc_16_to_ebx),@function
540         .align  align_4byte,0x90
541 GNAME(alloc_16_to_ebx):
542         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
543         pushl   %ecx
544         pushl   %edx
545         pushl   $16     # Push the size
546         call    GNAME(alloc)
547         addl    $4,%esp # pop the size arg.
548         movl    %eax,%ebx       # setup the destination.
549         popl    %edx    # Restore eax, ecx and edx.
550         popl    %ecx
551         popl    %eax
552         ret
553         .size   GNAME(alloc_16_to_ebx),.-GNAME(alloc_16_to_ebx)
554
555
556
557         .globl  GNAME(alloc_to_esi)
558         .type   GNAME(alloc_to_esi),@function
559         .align  align_4byte,0x90
560 GNAME(alloc_to_esi):
561         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
562         pushl   %ecx
563         pushl   %edx
564         pushl   %esi    # Push the size
565         call    GNAME(alloc)
566         addl    $4,%esp # pop the size arg.
567         movl    %eax,%esi       # setup the destination.
568         popl    %edx    # Restore eax, ecx and edx.
569         popl    %ecx
570         popl    %eax
571         ret
572         .size   GNAME(alloc_to_esi),.-GNAME(alloc_to_esi)
573
574         .globl  GNAME(alloc_8_to_esi)
575         .type   GNAME(alloc_8_to_esi),@function
576         .align  align_4byte,0x90
577 GNAME(alloc_8_to_esi):
578         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
579         pushl   %ecx
580         pushl   %edx
581         pushl   $8      # Push the size
582         call    GNAME(alloc)
583         addl    $4,%esp # pop the size arg.
584         movl    %eax,%esi       # setup the destination.
585         popl    %edx    # Restore eax, ecx and edx.
586         popl    %ecx
587         popl    %eax
588         ret
589         .size   GNAME(alloc_8_to_esi),.-GNAME(alloc_8_to_esi)
590
591         .globl  GNAME(alloc_16_to_esi)
592         .type   GNAME(alloc_16_to_esi),@function
593         .align  align_4byte,0x90
594 GNAME(alloc_16_to_esi):
595         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
596         pushl   %ecx
597         pushl   %edx
598         pushl   $16     # Push the size
599         call    GNAME(alloc)
600         addl    $4,%esp # pop the size arg.
601         movl    %eax,%esi       # setup the destination.
602         popl    %edx    # Restore eax, ecx and edx.
603         popl    %ecx
604         popl    %eax
605         ret
606         .size   GNAME(alloc_16_to_esi),.-GNAME(alloc_16_to_esi)
607
608
609         .globl  GNAME(alloc_to_edi)
610         .type   GNAME(alloc_to_edi),@function
611         .align  align_4byte,0x90
612 GNAME(alloc_to_edi):
613         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
614         pushl   %ecx
615         pushl   %edx
616         pushl   %edi    # Push the size
617         call    GNAME(alloc)
618         addl    $4,%esp # pop the size arg.
619         movl    %eax,%edi       # setup the destination.
620         popl    %edx    # Restore eax, ecx and edx.
621         popl    %ecx
622         popl    %eax
623         ret
624         .size   GNAME(alloc_to_edi),.-GNAME(alloc_to_edi)
625
626         .globl  GNAME(alloc_8_to_edi)
627         .type   GNAME(alloc_8_to_edi),@function
628         .align  align_4byte,0x90
629 GNAME(alloc_8_to_edi):
630         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
631         pushl   %ecx
632         pushl   %edx
633         pushl   $8      # Push the size
634         call    GNAME(alloc)
635         addl    $4,%esp # pop the size arg.
636         movl    %eax,%edi       # setup the destination.
637         popl    %edx    # Restore eax, ecx and edx.
638         popl    %ecx
639         popl    %eax
640         ret
641         .size   GNAME(alloc_8_to_edi),.-GNAME(alloc_8_to_edi)
642
643         .globl  GNAME(alloc_16_to_edi)
644         .type   GNAME(alloc_16_to_edi),@function
645         .align  align_4byte,0x90
646 GNAME(alloc_16_to_edi):
647         pushl   %eax    # Save eax, ecx, and edx as C could destroy them.
648         pushl   %ecx
649         pushl   %edx
650         pushl   $16     # Push the size
651         call    GNAME(alloc)
652         addl    $4,%esp # pop the size arg.
653         movl    %eax,%edi       # setup the destination.
654         popl    %edx    # Restore eax, ecx and edx.
655         popl    %ecx
656         popl    %eax
657         ret
658         .size   GNAME(alloc_16_to_edi),.-GNAME(alloc_16_to_edi)
659                 
660
661 \f
662 #ifdef GENCGC
663
664 /* These routines are called from Lisp when an inline allocation 
665  * overflows. Every register except the result needs to be preserved.
666  * We depend on C to preserve ebx, esi, edi, and ebp.
667  * But where necessary must save eax, ecx, edx. */
668
669 /* This routine handles an overflow with eax=crfp+size. So the
670  * size=eax-crfp. */
671         .align  align_4byte
672         .globl  GNAME(alloc_overflow_eax)
673         .type   GNAME(alloc_overflow_eax),@function
674 GNAME(alloc_overflow_eax):
675         pushl   %ecx            # Save ecx
676         pushl   %edx            # Save edx
677         /* Calculate the size for the allocation. */
678         subl    GNAME(current_region_free_pointer),%eax
679         pushl   %eax            # Push the size
680         call    GNAME(alloc)
681         addl    $4,%esp # pop the size arg.
682         popl    %edx    # Restore edx.
683         popl    %ecx    # Restore ecx.
684         addl    $6,(%esp) # Adjust the return address to skip the next inst.
685         ret
686         .size    GNAME(alloc_overflow_eax),.-GNAME(alloc_overflow_eax)
687
688 /* This routine handles an overflow with ecx=crfp+size. So the
689  * size=ecx-crfp. */
690         .align  align_4byte
691         .globl  GNAME(alloc_overflow_ecx)
692         .type   GNAME(alloc_overflow_ecx),@function
693 GNAME(alloc_overflow_ecx):
694         pushl   %eax            # Save eax
695         pushl   %edx            # Save edx
696         /* Calculate the size for the allocation. */
697         subl    GNAME(current_region_free_pointer),%ecx
698         pushl   %ecx            # Push the size
699         call    GNAME(alloc)
700         addl    $4,%esp # pop the size arg.
701         movl    %eax,%ecx       # setup the destination.
702         popl    %edx    # Restore edx.
703         popl    %eax    # Restore eax.
704         addl    $6,(%esp) # Adjust the return address to skip the next inst.
705         ret
706         .size    GNAME(alloc_overflow_ecx),.-GNAME(alloc_overflow_ecx)
707
708 /* This routine handles an overflow with edx=crfp+size. So the
709  * size=edx-crfp. */
710         .align  align_4byte
711         .globl  GNAME(alloc_overflow_edx)
712         .type   GNAME(alloc_overflow_edx),@function
713 GNAME(alloc_overflow_edx):
714         pushl   %eax            # Save eax
715         pushl   %ecx            # Save ecx
716         /* Calculate the size for the allocation. */
717         subl    GNAME(current_region_free_pointer),%edx
718         pushl   %edx            # Push the size
719         call    GNAME(alloc)
720         addl    $4,%esp # pop the size arg.
721         movl    %eax,%edx       # setup the destination.
722         popl    %ecx    # Restore ecx.
723         popl    %eax    # Restore eax.
724         addl    $6,(%esp) # Adjust the return address to skip the next inst.
725         ret
726         .size    GNAME(alloc_overflow_edx),.-GNAME(alloc_overflow_edx)
727
728 /* This routine handles an overflow with ebx=crfp+size. So the
729  * size=ebx-crfp. */
730         .align  align_4byte
731         .globl  GNAME(alloc_overflow_ebx)
732         .type   GNAME(alloc_overflow_ebx),@function
733 GNAME(alloc_overflow_ebx):
734         pushl   %eax            # Save eax
735         pushl   %ecx            # Save ecx
736         pushl   %edx            # Save edx
737         /* Calculate the size for the allocation. */
738         subl    GNAME(current_region_free_pointer),%ebx
739         pushl   %ebx            # Push the size
740         call    GNAME(alloc)
741         addl    $4,%esp # pop the size arg.
742         movl    %eax,%ebx       # setup the destination.
743         popl    %edx    # Restore edx.
744         popl    %ecx    # Restore ecx.
745         popl    %eax    # Restore eax.
746         addl    $6,(%esp) # Adjust the return address to skip the next inst.
747         ret
748         .size    GNAME(alloc_overflow_ebx),.-GNAME(alloc_overflow_ebx)
749
750 /* This routine handles an overflow with esi=crfp+size. So the
751  * size=esi-crfp. */
752         .align  align_4byte
753         .globl  GNAME(alloc_overflow_esi)
754         .type   GNAME(alloc_overflow_esi),@function
755 GNAME(alloc_overflow_esi):
756         pushl   %eax            # Save eax
757         pushl   %ecx            # Save ecx
758         pushl   %edx            # Save edx
759         /* Calculate the size for the allocation. */
760         subl    GNAME(current_region_free_pointer),%esi
761         pushl   %esi            # Push the size
762         call    GNAME(alloc)
763         addl    $4,%esp # pop the size arg.
764         movl    %eax,%esi       # setup the destination.
765         popl    %edx    # Restore edx.
766         popl    %ecx    # Restore ecx.
767         popl    %eax    # Restore eax.
768         addl    $6,(%esp) # Adjust the return address to skip the next inst.
769         ret
770         .size    GNAME(alloc_overflow_esi),.-GNAME(alloc_overflow_esi)
771
772 /* This routine handles an overflow with edi=crfp+size. So the
773  * size=edi-crfp. */
774         .align  align_4byte
775         .globl  GNAME(alloc_overflow_edi)
776         .type   GNAME(alloc_overflow_edi),@function
777 GNAME(alloc_overflow_edi):
778         pushl   %eax            # Save eax
779         pushl   %ecx            # Save ecx
780         pushl   %edx            # Save edx
781         /* Calculate the size for the allocation. */
782         subl    GNAME(current_region_free_pointer),%edi
783         pushl   %edi            # Push the size
784         call    GNAME(alloc)
785         addl    $4,%esp # pop the size arg.
786         movl    %eax,%edi       # setup the destination.
787         popl    %edx    # Restore edx.
788         popl    %ecx    # Restore ecx.
789         popl    %eax    # Restore eax.
790         addl    $6,(%esp) # Adjust the return address to skip the next inst.
791         ret
792         .size    GNAME(alloc_overflow_edi),.-GNAME(alloc_overflow_edi)
793
794 #endif
795
796         .end