1995-08-09 08:06:35 -07:00
|
|
|
#*********************************************************************#
|
|
|
|
# #
|
|
|
|
# Caml Special Light #
|
|
|
|
# #
|
|
|
|
# Xavier Leroy, projet Cristal, INRIA Rocquencourt #
|
|
|
|
# #
|
|
|
|
# Copyright 1995 Institut National de Recherche en Informatique et #
|
|
|
|
# Automatique. Distributed only by permission. #
|
|
|
|
# #
|
|
|
|
#*********************************************************************#
|
|
|
|
|
|
|
|
# $Id$ #
|
|
|
|
|
1995-07-02 09:42:16 -07:00
|
|
|
# Asm part of the runtime system, Intel 386 processor
|
|
|
|
|
|
|
|
.comm _young_start, 4
|
|
|
|
.comm _young_ptr, 4
|
|
|
|
.comm _gc_entry_regs, 4 * 7
|
|
|
|
.comm _caml_bottom_of_stack, 4
|
1995-07-10 02:48:27 -07:00
|
|
|
.comm _caml_top_of_stack, 4
|
1995-07-02 09:42:16 -07:00
|
|
|
.comm _caml_last_return_address, 4
|
|
|
|
.comm _remembered_ptr, 4
|
|
|
|
.comm _remembered_end, 4
|
|
|
|
.comm _caml_exception_pointer, 4
|
|
|
|
|
|
|
|
# Allocation
|
|
|
|
|
|
|
|
.text
|
|
|
|
.globl _caml_alloc1
|
|
|
|
.globl _caml_alloc2
|
|
|
|
.globl _caml_alloc3
|
|
|
|
.globl _caml_alloc
|
|
|
|
.globl _caml_call_gc
|
|
|
|
|
|
|
|
.align 4
|
|
|
|
_caml_alloc1:
|
|
|
|
movl _young_ptr, %eax
|
|
|
|
subl $8, %eax
|
|
|
|
movl %eax, _young_ptr
|
|
|
|
cmpl _young_start, %eax
|
|
|
|
jb L100
|
|
|
|
ret
|
|
|
|
L100: movl $8, %eax
|
1995-07-30 07:27:32 -07:00
|
|
|
jmp L105
|
1995-07-02 09:42:16 -07:00
|
|
|
|
|
|
|
.align 4
|
|
|
|
_caml_alloc2:
|
|
|
|
movl _young_ptr, %eax
|
|
|
|
subl $12, %eax
|
|
|
|
movl %eax, _young_ptr
|
|
|
|
cmpl _young_start, %eax
|
|
|
|
jb L101
|
|
|
|
ret
|
|
|
|
L101: movl $12, %eax
|
1995-07-30 07:27:32 -07:00
|
|
|
jmp L105
|
1995-07-02 09:42:16 -07:00
|
|
|
|
|
|
|
.align 4
|
|
|
|
_caml_alloc3:
|
|
|
|
movl _young_ptr, %eax
|
|
|
|
subl $16, %eax
|
|
|
|
movl %eax, _young_ptr
|
|
|
|
cmpl _young_start, %eax
|
|
|
|
jb L102
|
|
|
|
ret
|
|
|
|
L102: movl $16, %eax
|
1995-07-30 07:27:32 -07:00
|
|
|
jmp L105
|
1995-07-02 09:42:16 -07:00
|
|
|
|
|
|
|
.align 4
|
|
|
|
_caml_alloc:
|
|
|
|
pushl %eax
|
|
|
|
movl _young_ptr, %eax
|
|
|
|
subl (%esp), %eax
|
|
|
|
movl %eax, _young_ptr
|
|
|
|
cmpl _young_start, %eax
|
|
|
|
jb L103
|
|
|
|
addl $4, %esp
|
|
|
|
ret
|
|
|
|
L103: popl %eax
|
1995-07-30 07:27:32 -07:00
|
|
|
jmp L105
|
1995-07-02 09:42:16 -07:00
|
|
|
|
|
|
|
_caml_call_gc:
|
1995-07-30 07:27:32 -07:00
|
|
|
# Recover desired size and adjust return address
|
|
|
|
popl %eax
|
|
|
|
addl $2, %eax
|
|
|
|
pushl %eax
|
|
|
|
movzwl -2(%eax), %eax
|
|
|
|
L105:
|
1995-07-02 09:42:16 -07:00
|
|
|
# Record lowest stack address and return address
|
|
|
|
popl _caml_last_return_address
|
|
|
|
movl %esp, _caml_bottom_of_stack
|
|
|
|
# Save all regs used by the code generator
|
|
|
|
movl %ebx, _gc_entry_regs + 4
|
|
|
|
movl %ecx, _gc_entry_regs + 8
|
|
|
|
movl %edx, _gc_entry_regs + 12
|
|
|
|
movl %esi, _gc_entry_regs + 16
|
|
|
|
movl %edi, _gc_entry_regs + 20
|
|
|
|
movl %ebp, _gc_entry_regs + 24
|
1995-07-10 02:48:27 -07:00
|
|
|
# Save desired size
|
1995-07-02 09:42:16 -07:00
|
|
|
pushl %eax
|
|
|
|
# Call the garbage collector
|
1995-07-10 02:48:27 -07:00
|
|
|
call _minor_collection
|
1995-07-02 09:42:16 -07:00
|
|
|
# Restore all regs used by the code generator
|
|
|
|
movl _gc_entry_regs + 4, %ebx
|
|
|
|
movl _gc_entry_regs + 8, %ecx
|
|
|
|
movl _gc_entry_regs + 12, %edx
|
|
|
|
movl _gc_entry_regs + 16, %esi
|
|
|
|
movl _gc_entry_regs + 20, %edi
|
|
|
|
movl _gc_entry_regs + 24, %ebp
|
1995-07-10 02:48:27 -07:00
|
|
|
# Decrement young_ptr by desired size
|
|
|
|
popl %eax
|
|
|
|
subl %eax, _young_ptr
|
1995-07-02 09:42:16 -07:00
|
|
|
# Reload result of allocation in %eax
|
|
|
|
movl _young_ptr, %eax
|
|
|
|
# Return to caller
|
|
|
|
pushl _caml_last_return_address
|
|
|
|
ret
|
|
|
|
|
|
|
|
# Call a C function from Caml
|
|
|
|
|
|
|
|
.globl _caml_c_call
|
|
|
|
|
|
|
|
.align 4
|
|
|
|
_caml_c_call:
|
|
|
|
# Record lowest stack address and return address
|
1995-07-30 07:27:32 -07:00
|
|
|
movl (%esp), %edx
|
|
|
|
movl %edx, _caml_last_return_address
|
|
|
|
leal 4(%esp), %edx
|
|
|
|
movl %edx, _caml_bottom_of_stack
|
1995-10-15 11:54:33 -07:00
|
|
|
# Free the floating-point register stack
|
|
|
|
finit
|
1995-07-02 09:42:16 -07:00
|
|
|
# Call the function (address in %eax)
|
1995-07-30 07:27:32 -07:00
|
|
|
jmp *%eax
|
1995-07-02 09:42:16 -07:00
|
|
|
|
|
|
|
# Start the Caml program
|
|
|
|
|
|
|
|
.globl _caml_start_program
|
|
|
|
.align 4
|
|
|
|
_caml_start_program:
|
|
|
|
# Save callee-save registers
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ebp
|
|
|
|
# Build an exception handler
|
|
|
|
pushl $L104
|
1995-07-10 02:48:27 -07:00
|
|
|
pushl $0
|
1995-07-02 09:42:16 -07:00
|
|
|
movl %esp, _caml_exception_pointer
|
1995-07-10 02:48:27 -07:00
|
|
|
# Record highest stack address
|
|
|
|
movl %esp, _caml_top_of_stack
|
1995-07-02 09:42:16 -07:00
|
|
|
# Go for it
|
|
|
|
call _caml_program
|
|
|
|
# Pop handler
|
|
|
|
addl $8, %esp
|
|
|
|
# Zero return code
|
|
|
|
xorl %eax, %eax
|
|
|
|
L104:
|
|
|
|
# Restore registers and return
|
|
|
|
popl %ebp
|
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
# Raise an exception from C
|
|
|
|
|
|
|
|
.globl _raise_caml_exception
|
|
|
|
.align 4
|
|
|
|
_raise_caml_exception:
|
|
|
|
movl 4(%esp), %eax
|
|
|
|
movl _caml_exception_pointer, %esp
|
|
|
|
popl _caml_exception_pointer
|
1995-10-04 07:36:34 -07:00
|
|
|
ret
|