1996-02-21 02:49:46 -08:00
|
|
|
;*********************************************************************
|
|
|
|
;
|
1996-04-30 07:53:58 -07:00
|
|
|
; Objective Caml
|
1996-02-21 02:49:46 -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.
|
1996-02-21 02:49:46 -08:00
|
|
|
;
|
|
|
|
;*********************************************************************
|
|
|
|
|
|
|
|
; $Id$
|
|
|
|
|
|
|
|
; Asm part of the runtime system, Intel 386 processor, Intel syntax
|
|
|
|
|
|
|
|
.386
|
|
|
|
.MODEL FLAT
|
|
|
|
|
|
|
|
EXTERN _garbage_collection: PROC
|
|
|
|
EXTERN _mlraise: PROC
|
|
|
|
EXTERN _caml_apply2: PROC
|
|
|
|
EXTERN _caml_apply3: PROC
|
|
|
|
EXTERN _caml_program: PROC
|
|
|
|
EXTERN _young_limit: DWORD
|
|
|
|
EXTERN _young_ptr: DWORD
|
1997-03-23 05:52:45 -08:00
|
|
|
EXTERN _caml_bottom_of_stack: DWORD
|
|
|
|
EXTERN _caml_last_return_address: DWORD
|
1997-11-27 08:28:40 -08:00
|
|
|
EXTERN _caml_gc_regs: DWORD
|
1997-03-23 05:52:45 -08:00
|
|
|
EXTERN _caml_exception_pointer: DWORD
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
; Allocation
|
|
|
|
|
|
|
|
.CODE
|
|
|
|
PUBLIC _caml_alloc1
|
|
|
|
PUBLIC _caml_alloc2
|
|
|
|
PUBLIC _caml_alloc3
|
|
|
|
PUBLIC _caml_alloc
|
|
|
|
PUBLIC _caml_call_gc
|
|
|
|
|
1996-05-16 12:39:26 -07:00
|
|
|
_caml_call_gc:
|
|
|
|
; Record lowest stack address and return address
|
|
|
|
mov eax, [esp]
|
|
|
|
mov _caml_last_return_address, eax
|
|
|
|
lea eax, [esp+4]
|
|
|
|
mov _caml_bottom_of_stack, eax
|
|
|
|
; Save all regs used by the code generator
|
1997-11-27 08:28:40 -08:00
|
|
|
L105: push ebp
|
|
|
|
push edi
|
|
|
|
push esi
|
|
|
|
push edx
|
|
|
|
push ecx
|
|
|
|
push ebx
|
|
|
|
push eax
|
|
|
|
mov _caml_gc_regs, esp
|
1996-05-16 12:39:26 -07:00
|
|
|
; Call the garbage collector
|
|
|
|
call _garbage_collection
|
|
|
|
; Restore all regs used by the code generator
|
1997-11-27 08:28:40 -08:00
|
|
|
pop eax
|
|
|
|
pop ebx
|
|
|
|
pop ecx
|
|
|
|
pop edx
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebp
|
1996-05-16 12:39:26 -07:00
|
|
|
; Return to caller
|
|
|
|
ret
|
|
|
|
|
1996-02-21 02:49:46 -08:00
|
|
|
ALIGN 4
|
|
|
|
_caml_alloc1:
|
|
|
|
mov eax, _young_ptr
|
|
|
|
sub eax, 8
|
|
|
|
mov _young_ptr, eax
|
|
|
|
cmp eax, _young_limit
|
|
|
|
jb L100
|
|
|
|
ret
|
1996-05-16 12:39:26 -07:00
|
|
|
L100: mov eax, [esp]
|
|
|
|
mov _caml_last_return_address, eax
|
|
|
|
lea eax, [esp+4]
|
|
|
|
mov _caml_bottom_of_stack, eax
|
|
|
|
call L105
|
|
|
|
jmp _caml_alloc1
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
ALIGN 4
|
|
|
|
_caml_alloc2:
|
|
|
|
mov eax, _young_ptr
|
|
|
|
sub eax, 12
|
|
|
|
mov _young_ptr, eax
|
|
|
|
cmp eax, _young_limit
|
|
|
|
jb L101
|
|
|
|
ret
|
1996-05-16 12:39:26 -07:00
|
|
|
L101: mov eax, [esp]
|
|
|
|
mov _caml_last_return_address, eax
|
|
|
|
lea eax, [esp+4]
|
|
|
|
mov _caml_bottom_of_stack, eax
|
|
|
|
call L105
|
|
|
|
jmp _caml_alloc2
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
ALIGN 4
|
|
|
|
_caml_alloc3:
|
|
|
|
mov eax, _young_ptr
|
|
|
|
sub eax, 16
|
|
|
|
mov _young_ptr, eax
|
|
|
|
cmp eax, _young_limit
|
|
|
|
jb L102
|
|
|
|
ret
|
1996-05-16 12:39:26 -07:00
|
|
|
L102: mov eax, [esp]
|
|
|
|
mov _caml_last_return_address, eax
|
|
|
|
lea eax, [esp+4]
|
|
|
|
mov _caml_bottom_of_stack, eax
|
|
|
|
call L105
|
|
|
|
jmp _caml_alloc3
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
ALIGN 4
|
|
|
|
_caml_alloc:
|
1996-05-16 12:39:26 -07:00
|
|
|
sub eax, _young_ptr ; eax = size - young_ptr
|
|
|
|
neg eax ; eax = young_ptr - size
|
|
|
|
cmp eax, _young_limit
|
|
|
|
jb L103
|
|
|
|
mov _young_ptr, eax
|
|
|
|
ret
|
|
|
|
L103: sub eax, _young_ptr ; eax = - size
|
|
|
|
neg eax ; eax = size
|
|
|
|
push eax ; save desired size
|
1996-05-29 01:59:46 -07:00
|
|
|
sub _young_ptr, eax ; must update young_ptr
|
1996-05-16 12:39:26 -07:00
|
|
|
mov eax, [esp+4]
|
|
|
|
mov _caml_last_return_address, eax
|
|
|
|
lea eax, [esp+8]
|
|
|
|
mov _caml_bottom_of_stack, eax
|
|
|
|
call L105
|
|
|
|
pop eax ; recover desired size
|
|
|
|
jmp _caml_alloc
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
; Call a C function from Caml
|
|
|
|
|
|
|
|
PUBLIC _caml_c_call
|
|
|
|
ALIGN 4
|
|
|
|
_caml_c_call:
|
|
|
|
; Record lowest stack address and return address
|
|
|
|
mov edx, [esp]
|
|
|
|
mov _caml_last_return_address, edx
|
|
|
|
lea edx, [esp+4]
|
|
|
|
mov _caml_bottom_of_stack, edx
|
|
|
|
; Call the function (address in %eax)
|
|
|
|
jmp eax
|
|
|
|
|
|
|
|
; Start the Caml program
|
|
|
|
|
|
|
|
PUBLIC _caml_start_program
|
|
|
|
ALIGN 4
|
|
|
|
_caml_start_program:
|
|
|
|
; Save callee-save registers
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
push ebp
|
1997-03-17 02:17:32 -08:00
|
|
|
; Initial code pointer is caml_program
|
|
|
|
mov esi, offset _caml_program
|
1996-02-21 02:49:46 -08:00
|
|
|
|
1997-03-17 02:17:32 -08:00
|
|
|
; Code shared between caml_start_program and callback*
|
1996-02-21 02:49:46 -08:00
|
|
|
|
|
|
|
L106:
|
|
|
|
; Build a callback link
|
1997-12-01 05:04:05 -08:00
|
|
|
push _caml_gc_regs
|
1996-02-21 02:49:46 -08:00
|
|
|
push _caml_last_return_address
|
|
|
|
push _caml_bottom_of_stack
|
|
|
|
; Build an exception handler
|
|
|
|
push L108
|
|
|
|
push _caml_exception_pointer
|
|
|
|
mov _caml_exception_pointer, esp
|
|
|
|
; Call the Caml code
|
|
|
|
call esi
|
|
|
|
L107:
|
|
|
|
; Pop the exception handler
|
|
|
|
pop _caml_exception_pointer
|
|
|
|
pop esi ; dummy register
|
1999-02-14 08:48:25 -08:00
|
|
|
L109:
|
1996-02-21 02:49:46 -08:00
|
|
|
; Pop the callback link, restoring the global variables
|
|
|
|
; used by caml_c_call
|
|
|
|
pop _caml_bottom_of_stack
|
|
|
|
pop _caml_last_return_address
|
1997-12-01 05:04:05 -08:00
|
|
|
pop _caml_gc_regs
|
1996-02-21 02:49:46 -08:00
|
|
|
; Restore callee-save registers.
|
|
|
|
pop ebp
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
|
|
|
; Return to caller.
|
|
|
|
ret
|
|
|
|
L108:
|
|
|
|
; Exception handler
|
1999-02-14 08:48:25 -08:00
|
|
|
; Mark the bucket as an exception result and return it
|
|
|
|
or eax, 2
|
|
|
|
jmp L109
|
1996-02-21 02:49:46 -08:00
|
|
|
|
1997-03-17 02:17:32 -08:00
|
|
|
; Raise an exception from C
|
|
|
|
|
|
|
|
PUBLIC _raise_caml_exception
|
|
|
|
ALIGN 4
|
|
|
|
_raise_caml_exception:
|
|
|
|
mov eax, [esp+4]
|
|
|
|
mov esp, _caml_exception_pointer
|
|
|
|
pop _caml_exception_pointer
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Callback from C to Caml
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
PUBLIC _callback_exn
|
1997-03-17 02:17:32 -08:00
|
|
|
ALIGN 4
|
1999-02-14 08:48:25 -08:00
|
|
|
_callback_exn:
|
1997-03-17 02:17:32 -08:00
|
|
|
; Save callee-save registers
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
push ebp
|
|
|
|
; Initial loading of arguments
|
|
|
|
mov ebx, [esp+20] ; closure
|
|
|
|
mov eax, [esp+24] ; argument
|
|
|
|
mov esi, [ebx] ; code pointer
|
|
|
|
jmp L106
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
PUBLIC _callback2_exn
|
1996-02-21 02:49:46 -08:00
|
|
|
ALIGN 4
|
1999-02-14 08:48:25 -08:00
|
|
|
_callback2_exn:
|
1996-02-21 02:49:46 -08:00
|
|
|
; Save callee-save registers
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
push ebp
|
|
|
|
; Initial loading of arguments
|
|
|
|
mov ecx, [esp+20] ; closure
|
|
|
|
mov eax, [esp+24] ; first argument
|
|
|
|
mov ebx, [esp+28] ; second argument
|
|
|
|
mov esi, offset _caml_apply2 ; code pointer
|
|
|
|
jmp L106
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
PUBLIC _callback3_exn
|
1996-02-21 02:49:46 -08:00
|
|
|
ALIGN 4
|
1999-02-14 08:48:25 -08:00
|
|
|
_callback3_exn:
|
1996-02-21 02:49:46 -08:00
|
|
|
; Save callee-save registers
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
push ebp
|
|
|
|
; Initial loading of arguments
|
|
|
|
mov edx, [esp+20] ; closure
|
|
|
|
mov eax, [esp+24] ; first argument
|
|
|
|
mov ebx, [esp+28] ; second argument
|
|
|
|
mov ecx, [esp+32] ; third argument
|
|
|
|
mov esi, offset _caml_apply3 ; code pointer
|
|
|
|
jmp L106
|
|
|
|
|
|
|
|
.DATA
|
2002-02-08 08:55:44 -08:00
|
|
|
PUBLIC _system__frametable
|
|
|
|
_system__frametable LABEL DWORD
|
1996-02-21 02:49:46 -08:00
|
|
|
DWORD 1 ; one descriptor
|
|
|
|
DWORD L107 ; return address into callback
|
|
|
|
WORD -1 ; negative frame size => use callback link
|
|
|
|
WORD 0 ; no roots here
|
|
|
|
|
|
|
|
END
|