1995-10-31 01:27:04 -08:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-10-31 01:27:04 -08:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-10-31 01:27:04 -08:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/* Asm part of the runtime system, Intel 386 processor */
|
|
|
|
/* Must be preprocessed by cpp */
|
|
|
|
|
1999-10-14 06:35:23 -07:00
|
|
|
/* Linux/BSD with ELF binaries and Solaris do not prefix identifiers with _.
|
|
|
|
Linux/BSD with a.out binaries and NextStep do. */
|
1995-10-31 01:27:04 -08:00
|
|
|
|
1998-12-07 04:55:25 -08:00
|
|
|
#if defined(SYS_solaris)
|
|
|
|
#define CONCAT(a,b) a/**/b
|
|
|
|
#else
|
|
|
|
#define CONCAT(a,b) a##b
|
|
|
|
#endif
|
|
|
|
|
1999-10-14 06:35:23 -07:00
|
|
|
#if defined(SYS_linux_elf) || defined(SYS_bsd_elf) \
|
|
|
|
|| defined(SYS_solaris) || defined(SYS_beos)
|
1995-10-31 01:27:04 -08:00
|
|
|
#define G(x) x
|
1998-12-07 04:55:25 -08:00
|
|
|
#define LBL(x) CONCAT(.L,x)
|
1995-10-31 01:27:04 -08:00
|
|
|
#else
|
1998-12-07 04:55:25 -08:00
|
|
|
#define G(x) CONCAT(_,x)
|
|
|
|
#define LBL(x) CONCAT(L,x)
|
2000-08-10 02:58:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(SYS_linux_elf) || defined(SYS_bsd_elf) \
|
|
|
|
|| defined(SYS_solaris) || defined(SYS_beos) || defined(SYS_cygwin)
|
|
|
|
#define FUNCTION_ALIGN 4
|
|
|
|
#else
|
1996-06-25 02:28:17 -07:00
|
|
|
#define FUNCTION_ALIGN 2
|
1995-10-31 01:27:04 -08:00
|
|
|
#endif
|
|
|
|
|
2000-02-29 08:15:59 -08:00
|
|
|
#if defined(PROFILING)
|
|
|
|
#if defined(SYS_linux_elf)
|
1998-08-06 06:27:38 -07:00
|
|
|
#define PROFILE_CAML \
|
1998-10-01 05:21:22 -07:00
|
|
|
pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \
|
1998-08-06 06:27:38 -07:00
|
|
|
call mcount; \
|
1998-10-01 05:21:22 -07:00
|
|
|
popl %edx; popl %ecx; popl %eax; popl %ebp
|
1998-08-06 06:27:38 -07:00
|
|
|
#define PROFILE_C \
|
|
|
|
pushl %ebp; movl %esp, %ebp; call mcount; popl %ebp
|
2000-02-29 08:15:59 -08:00
|
|
|
#elif defined(SYS_bsd_elf)
|
|
|
|
#define PROFILE_CAML \
|
|
|
|
pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \
|
|
|
|
call .mcount; \
|
|
|
|
popl %edx; popl %ecx; popl %eax; popl %ebp
|
|
|
|
#define PROFILE_C \
|
|
|
|
pushl %ebp; movl %esp, %ebp; call .mcount; popl %ebp
|
|
|
|
#endif
|
1998-08-06 06:27:38 -07:00
|
|
|
#else
|
|
|
|
#define PROFILE_CAML
|
|
|
|
#define PROFILE_C
|
|
|
|
#endif
|
|
|
|
|
1995-10-31 01:27:04 -08:00
|
|
|
/* Allocation */
|
|
|
|
|
|
|
|
.text
|
1997-05-19 08:42:21 -07:00
|
|
|
.globl G(caml_call_gc)
|
1995-10-31 01:27:04 -08:00
|
|
|
.globl G(caml_alloc1)
|
|
|
|
.globl G(caml_alloc2)
|
|
|
|
.globl G(caml_alloc3)
|
|
|
|
.globl G(caml_alloc)
|
1996-05-14 09:51:42 -07:00
|
|
|
|
|
|
|
G(caml_call_gc):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1997-11-27 08:28:40 -08:00
|
|
|
/* Record lowest stack address and return address */
|
|
|
|
movl 0(%esp), %eax
|
|
|
|
movl %eax, G(caml_last_return_address)
|
|
|
|
leal 4(%esp), %eax
|
|
|
|
movl %eax, G(caml_bottom_of_stack)
|
|
|
|
/* Build array of registers, save it into caml_gc_regs */
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(105):
|
|
|
|
pushl %ebp
|
1997-11-21 05:46:23 -08:00
|
|
|
pushl %edi
|
|
|
|
pushl %esi
|
|
|
|
pushl %edx
|
|
|
|
pushl %ecx
|
|
|
|
pushl %ebx
|
|
|
|
pushl %eax
|
1997-11-27 08:28:40 -08:00
|
|
|
movl %esp, G(caml_gc_regs)
|
1996-05-14 09:51:42 -07:00
|
|
|
/* Call the garbage collector */
|
|
|
|
call G(garbage_collection)
|
|
|
|
/* Restore all regs used by the code generator */
|
1997-11-21 05:46:23 -08:00
|
|
|
popl %eax
|
|
|
|
popl %ebx
|
|
|
|
popl %ecx
|
|
|
|
popl %edx
|
|
|
|
popl %esi
|
|
|
|
popl %edi
|
|
|
|
popl %ebp
|
1996-05-14 09:51:42 -07:00
|
|
|
/* Return to caller */
|
|
|
|
ret
|
1995-10-31 01:27:04 -08:00
|
|
|
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_alloc1):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1995-10-31 01:27:04 -08:00
|
|
|
movl G(young_ptr), %eax
|
|
|
|
subl $8, %eax
|
|
|
|
movl %eax, G(young_ptr)
|
1995-12-21 03:01:45 -08:00
|
|
|
cmpl G(young_limit), %eax
|
1998-12-03 09:28:53 -08:00
|
|
|
jb LBL(100)
|
1995-10-31 01:27:04 -08:00
|
|
|
ret
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(100):
|
|
|
|
movl 0(%esp), %eax
|
1997-11-27 08:28:40 -08:00
|
|
|
movl %eax, G(caml_last_return_address)
|
|
|
|
leal 4(%esp), %eax
|
|
|
|
movl %eax, G(caml_bottom_of_stack)
|
1998-12-03 09:28:53 -08:00
|
|
|
call LBL(105)
|
1996-05-16 07:19:17 -07:00
|
|
|
jmp G(caml_alloc1)
|
1995-10-31 01:27:04 -08:00
|
|
|
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_alloc2):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1995-10-31 01:27:04 -08:00
|
|
|
movl G(young_ptr), %eax
|
|
|
|
subl $12, %eax
|
|
|
|
movl %eax, G(young_ptr)
|
1995-12-21 03:01:45 -08:00
|
|
|
cmpl G(young_limit), %eax
|
1998-12-03 09:28:53 -08:00
|
|
|
jb LBL(101)
|
1995-10-31 01:27:04 -08:00
|
|
|
ret
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(101):
|
|
|
|
movl 0(%esp), %eax
|
1997-11-27 08:28:40 -08:00
|
|
|
movl %eax, G(caml_last_return_address)
|
|
|
|
leal 4(%esp), %eax
|
|
|
|
movl %eax, G(caml_bottom_of_stack)
|
1998-12-03 09:28:53 -08:00
|
|
|
call LBL(105)
|
1996-05-16 07:19:17 -07:00
|
|
|
jmp G(caml_alloc2)
|
1995-10-31 01:27:04 -08:00
|
|
|
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_alloc3):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1995-10-31 01:27:04 -08:00
|
|
|
movl G(young_ptr), %eax
|
|
|
|
subl $16, %eax
|
|
|
|
movl %eax, G(young_ptr)
|
1995-12-21 03:01:45 -08:00
|
|
|
cmpl G(young_limit), %eax
|
1998-12-03 09:28:53 -08:00
|
|
|
jb LBL(102)
|
1995-10-31 01:27:04 -08:00
|
|
|
ret
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(102):
|
|
|
|
movl 0(%esp), %eax
|
1997-11-27 08:28:40 -08:00
|
|
|
movl %eax, G(caml_last_return_address)
|
|
|
|
leal 4(%esp), %eax
|
|
|
|
movl %eax, G(caml_bottom_of_stack)
|
1998-12-03 09:28:53 -08:00
|
|
|
call LBL(105)
|
1996-05-16 07:19:17 -07:00
|
|
|
jmp G(caml_alloc3)
|
1995-10-31 01:27:04 -08:00
|
|
|
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_alloc):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1997-05-19 08:42:21 -07:00
|
|
|
subl G(young_ptr), %eax /* eax = size - young_ptr */
|
1996-05-14 09:51:42 -07:00
|
|
|
negl %eax /* eax = young_ptr - size */
|
1995-12-21 03:01:45 -08:00
|
|
|
cmpl G(young_limit), %eax
|
1998-12-03 09:28:53 -08:00
|
|
|
jb LBL(103)
|
1996-05-14 09:51:42 -07:00
|
|
|
movl %eax, G(young_ptr)
|
1995-10-31 01:27:04 -08:00
|
|
|
ret
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(103):
|
|
|
|
subl G(young_ptr), %eax /* eax = - size */
|
1996-05-14 09:51:42 -07:00
|
|
|
negl %eax /* eax = size */
|
1997-11-27 08:28:40 -08:00
|
|
|
pushl %eax /* save desired size */
|
|
|
|
subl %eax, G(young_ptr) /* must update young_ptr */
|
|
|
|
movl 4(%esp), %eax
|
|
|
|
movl %eax, G(caml_last_return_address)
|
|
|
|
leal 8(%esp), %eax
|
|
|
|
movl %eax, G(caml_bottom_of_stack)
|
1998-12-03 09:28:53 -08:00
|
|
|
call LBL(105)
|
1997-11-27 08:28:40 -08:00
|
|
|
popl %eax /* recover desired size */
|
1996-05-16 07:19:17 -07:00
|
|
|
jmp G(caml_alloc)
|
1995-10-31 01:27:04 -08:00
|
|
|
|
|
|
|
/* Call a C function from Caml */
|
|
|
|
|
|
|
|
.globl G(caml_c_call)
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_c_call):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_CAML
|
1997-11-27 08:28:40 -08:00
|
|
|
/* Record lowest stack address and return address */
|
|
|
|
movl (%esp), %edx
|
|
|
|
movl %edx, G(caml_last_return_address)
|
|
|
|
leal 4(%esp), %edx
|
|
|
|
movl %edx, G(caml_bottom_of_stack)
|
1995-12-10 01:33:09 -08:00
|
|
|
/* Call the function (address in %eax) */
|
1995-11-25 07:37:33 -08:00
|
|
|
jmp *%eax
|
1995-10-31 01:27:04 -08:00
|
|
|
|
|
|
|
/* Start the Caml program */
|
|
|
|
|
|
|
|
.globl G(caml_start_program)
|
1995-11-05 09:32:12 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1995-10-31 01:27:04 -08:00
|
|
|
G(caml_start_program):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_C
|
1995-10-31 01:27:04 -08:00
|
|
|
/* Save callee-save registers */
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ebp
|
1997-03-17 02:17:32 -08:00
|
|
|
/* Initial entry point is caml_program */
|
|
|
|
movl $ G(caml_program), %esi
|
|
|
|
/* Common code for caml_start_program and callback* */
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(106):
|
1996-01-07 08:58:44 -08:00
|
|
|
/* Build a callback link */
|
1997-11-27 08:28:40 -08:00
|
|
|
pushl G(caml_gc_regs)
|
|
|
|
pushl G(caml_last_return_address)
|
|
|
|
pushl G(caml_bottom_of_stack)
|
1995-12-20 05:27:16 -08:00
|
|
|
/* Build an exception handler */
|
1998-12-03 09:28:53 -08:00
|
|
|
pushl $ LBL(108)
|
1995-12-20 05:27:16 -08:00
|
|
|
pushl G(caml_exception_pointer)
|
|
|
|
movl %esp, G(caml_exception_pointer)
|
|
|
|
/* Call the Caml code */
|
|
|
|
call *%esi
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(107):
|
1996-01-07 08:58:44 -08:00
|
|
|
/* Pop the exception handler */
|
|
|
|
popl G(caml_exception_pointer)
|
|
|
|
popl %esi /* dummy register */
|
1999-02-14 08:48:25 -08:00
|
|
|
LBL(109):
|
1997-11-27 08:28:40 -08:00
|
|
|
/* Pop the callback link, restoring the global variables */
|
|
|
|
popl G(caml_bottom_of_stack)
|
|
|
|
popl G(caml_last_return_address)
|
|
|
|
popl G(caml_gc_regs)
|
1996-05-16 12:39:26 -07:00
|
|
|
/* Restore callee-save registers. */
|
1995-12-20 05:27:16 -08:00
|
|
|
popl %ebp
|
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
|
|
|
/* Return to caller. */
|
|
|
|
ret
|
1998-12-03 09:28:53 -08:00
|
|
|
LBL(108):
|
1996-01-07 08:58:44 -08:00
|
|
|
/* Exception handler*/
|
1999-02-14 08:48:25 -08:00
|
|
|
/* Mark the bucket as an exception result and return it */
|
|
|
|
orl $2, %eax
|
|
|
|
jmp LBL(109)
|
1995-12-20 05:27:16 -08:00
|
|
|
|
1997-03-17 02:17:32 -08:00
|
|
|
/* Raise an exception from C */
|
|
|
|
|
|
|
|
.globl G(raise_caml_exception)
|
|
|
|
.align FUNCTION_ALIGN
|
|
|
|
G(raise_caml_exception):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_C
|
1997-03-17 02:17:32 -08:00
|
|
|
movl 4(%esp), %eax
|
|
|
|
movl G(caml_exception_pointer), %esp
|
|
|
|
popl G(caml_exception_pointer)
|
|
|
|
ret
|
|
|
|
|
|
|
|
/* Callback from C to Caml */
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.globl G(callback_exn)
|
1997-03-17 02:17:32 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1999-02-14 08:48:25 -08:00
|
|
|
G(callback_exn):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_C
|
1997-03-17 02:17:32 -08:00
|
|
|
/* Save callee-save registers */
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ebp
|
|
|
|
/* Initial loading of arguments */
|
|
|
|
movl 20(%esp), %ebx /* closure */
|
|
|
|
movl 24(%esp), %eax /* argument */
|
|
|
|
movl 0(%ebx), %esi /* code pointer */
|
1998-12-03 09:28:53 -08:00
|
|
|
jmp LBL(106)
|
1997-03-17 02:17:32 -08:00
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.globl G(callback2_exn)
|
1995-12-20 05:27:16 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1999-02-14 08:48:25 -08:00
|
|
|
G(callback2_exn):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_C
|
1995-12-20 05:27:16 -08:00
|
|
|
/* Save callee-save registers */
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ebp
|
|
|
|
/* Initial loading of arguments */
|
|
|
|
movl 20(%esp), %ecx /* closure */
|
|
|
|
movl 24(%esp), %eax /* first argument */
|
|
|
|
movl 28(%esp), %ebx /* second argument */
|
|
|
|
movl $ G(caml_apply2), %esi /* code pointer */
|
1998-12-03 09:28:53 -08:00
|
|
|
jmp LBL(106)
|
1995-12-20 05:27:16 -08:00
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.globl G(callback3_exn)
|
1995-12-20 05:27:16 -08:00
|
|
|
.align FUNCTION_ALIGN
|
1999-02-14 08:48:25 -08:00
|
|
|
G(callback3_exn):
|
1998-08-06 06:27:38 -07:00
|
|
|
PROFILE_C
|
1995-12-20 05:27:16 -08:00
|
|
|
/* Save callee-save registers */
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ebp
|
|
|
|
/* Initial loading of arguments */
|
|
|
|
movl 20(%esp), %edx /* closure */
|
|
|
|
movl 24(%esp), %eax /* first argument */
|
|
|
|
movl 28(%esp), %ebx /* second argument */
|
|
|
|
movl 32(%esp), %ecx /* third argument */
|
|
|
|
movl $ G(caml_apply3), %esi /* code pointer */
|
1998-12-03 09:28:53 -08:00
|
|
|
jmp LBL(106)
|
|
|
|
|
|
|
|
.globl G(caml_array_bound_error)
|
|
|
|
.align FUNCTION_ALIGN
|
|
|
|
G(caml_array_bound_error):
|
|
|
|
/* Empty the floating-point stack */
|
|
|
|
ffree %st(0)
|
|
|
|
ffree %st(1)
|
|
|
|
ffree %st(2)
|
|
|
|
ffree %st(3)
|
|
|
|
ffree %st(4)
|
|
|
|
ffree %st(5)
|
|
|
|
ffree %st(6)
|
|
|
|
ffree %st(7)
|
|
|
|
/* Branch to array_bound_error */
|
|
|
|
jmp G(array_bound_error)
|
1995-12-20 05:27:16 -08:00
|
|
|
|
|
|
|
.data
|
|
|
|
.globl G(system_frametable)
|
|
|
|
G(system_frametable):
|
|
|
|
.long 1 /* one descriptor */
|
1998-12-03 09:28:53 -08:00
|
|
|
.long LBL(107) /* return address into callback */
|
1996-09-18 05:43:46 -07:00
|
|
|
#ifndef SYS_solaris
|
1995-12-20 05:27:16 -08:00
|
|
|
.word -1 /* negative frame size => use callback link */
|
|
|
|
.word 0 /* no roots here */
|
1996-09-18 05:43:46 -07:00
|
|
|
#else
|
|
|
|
.value -1 /* negative frame size => use callback link */
|
|
|
|
.value 0 /* no roots here */
|
|
|
|
#endif
|