1998-10-10 07:56:53 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1998 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. */
|
1998-10-10 07:56:53 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/* Asm part of the runtime system, ARM processor */
|
|
|
|
|
2000-04-05 11:30:22 -07:00
|
|
|
trap_ptr .req r11
|
|
|
|
alloc_ptr .req r8
|
|
|
|
alloc_limit .req r9
|
|
|
|
sp .req r13
|
|
|
|
lr .req r14
|
|
|
|
pc .req r15
|
1998-10-15 09:10:53 -07:00
|
|
|
|
1998-10-10 07:56:53 -07:00
|
|
|
.text
|
|
|
|
|
|
|
|
/* Allocation functions and GC interface */
|
|
|
|
|
|
|
|
.global caml_call_gc
|
|
|
|
caml_call_gc:
|
|
|
|
/* Record return address */
|
1998-10-15 09:10:53 -07:00
|
|
|
/* We can use r10 as a temp reg since it's not live here */
|
|
|
|
ldr r10, .Lcaml_last_return_address
|
|
|
|
str lr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Branch to shared GC code */
|
|
|
|
bl .Linvoke_gc
|
1998-10-15 09:10:53 -07:00
|
|
|
/* Restart allocation sequence (4 instructions before) */
|
|
|
|
sub lr, lr, #16
|
1998-10-10 07:56:53 -07:00
|
|
|
mov pc, lr
|
|
|
|
|
|
|
|
.global caml_alloc1
|
|
|
|
caml_alloc1:
|
2000-04-05 11:30:22 -07:00
|
|
|
ldr r10, [alloc_limit, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
sub alloc_ptr, alloc_ptr, #8
|
1998-10-15 09:10:53 -07:00
|
|
|
cmp alloc_ptr, r10
|
1998-10-10 07:56:53 -07:00
|
|
|
movcs pc, lr /* Return if alloc_ptr >= alloc_limit */
|
|
|
|
/* Record return address */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_last_return_address
|
|
|
|
str lr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Invoke GC */
|
|
|
|
bl .Linvoke_gc
|
|
|
|
/* Try again */
|
|
|
|
b caml_alloc1
|
|
|
|
|
|
|
|
.global caml_alloc2
|
|
|
|
caml_alloc2:
|
2000-04-05 11:30:22 -07:00
|
|
|
ldr r10, [alloc_limit, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
sub alloc_ptr, alloc_ptr, #12
|
1998-10-15 09:10:53 -07:00
|
|
|
cmp alloc_ptr, r10
|
1998-10-10 07:56:53 -07:00
|
|
|
movcs pc, lr /* Return if alloc_ptr >= alloc_limit */
|
|
|
|
/* Record return address */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_last_return_address
|
|
|
|
str lr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Invoke GC */
|
|
|
|
bl .Linvoke_gc
|
|
|
|
/* Try again */
|
|
|
|
b caml_alloc2
|
|
|
|
|
|
|
|
.global caml_alloc3
|
|
|
|
caml_alloc3:
|
2000-04-05 11:30:22 -07:00
|
|
|
ldr r10, [alloc_limit, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
sub alloc_ptr, alloc_ptr, #16
|
1998-10-15 09:10:53 -07:00
|
|
|
cmp alloc_ptr, r10
|
1998-10-10 07:56:53 -07:00
|
|
|
movcs pc, lr /* Return if alloc_ptr >= alloc_limit */
|
|
|
|
/* Record return address */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_last_return_address
|
|
|
|
str lr, [r10, #0]
|
|
|
|
/* Invoke GC */
|
|
|
|
bl .Linvoke_gc
|
|
|
|
/* Try again */
|
|
|
|
b caml_alloc3
|
|
|
|
|
|
|
|
.global caml_alloc
|
|
|
|
caml_alloc:
|
2000-04-05 11:30:22 -07:00
|
|
|
str r12, [sp, #-4]!
|
|
|
|
ldr r12, [alloc_limit, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
sub alloc_ptr, alloc_ptr, r10
|
|
|
|
cmp alloc_ptr, r12
|
2000-04-05 11:30:22 -07:00
|
|
|
ldr r12, [sp], #4
|
1998-10-15 09:10:53 -07:00
|
|
|
movcs pc, lr /* Return if alloc_ptr >= alloc_limit */
|
|
|
|
/* Record return address and desired size */
|
1998-10-10 07:56:53 -07:00
|
|
|
ldr alloc_limit, .Lcaml_last_return_address
|
|
|
|
str lr, [alloc_limit, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
str r10, .Lcaml_requested_size
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Invoke GC */
|
|
|
|
bl .Linvoke_gc
|
|
|
|
/* Try again */
|
2000-04-05 11:30:22 -07:00
|
|
|
ldr r10, .Lcaml_requested_size
|
1998-10-15 09:10:53 -07:00
|
|
|
b caml_alloc
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* Shared code to invoke the GC */
|
|
|
|
.Linvoke_gc:
|
|
|
|
/* Record lowest stack address */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_bottom_of_stack
|
|
|
|
str sp, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Save integer registers and return address on stack */
|
1998-10-15 09:10:53 -07:00
|
|
|
stmfd sp!, {r0,r1,r2,r3,r4,r5,r6,r7,r10,r12,lr}
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Store pointer to saved integer registers in caml_gc_regs */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_gc_regs
|
|
|
|
str sp, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Save non-callee-save float registers */
|
1998-10-15 09:10:53 -07:00
|
|
|
stfd f0, [sp, #-8]!
|
|
|
|
stfd f1, [sp, #-8]!
|
|
|
|
stfd f2, [sp, #-8]!
|
|
|
|
stfd f3, [sp, #-8]!
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Save current allocation pointer for debugging purposes */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lyoung_ptr
|
|
|
|
str alloc_ptr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Save trap pointer in case an exception is raised during GC */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_exception_pointer
|
|
|
|
str trap_ptr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Call the garbage collector */
|
|
|
|
bl garbage_collection
|
2000-04-05 11:30:22 -07:00
|
|
|
/* Restore the registers from the stack */
|
1998-10-10 07:56:53 -07:00
|
|
|
ldfd f4, [sp], #8
|
|
|
|
ldfd f5, [sp], #8
|
|
|
|
ldfd f6, [sp], #8
|
|
|
|
ldfd f7, [sp], #8
|
1998-10-15 09:10:53 -07:00
|
|
|
ldmfd sp!, {r0,r1,r2,r3,r4,r5,r6,r7,r10,r12}
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Reload return address */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_last_return_address
|
|
|
|
ldr lr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Say that we are back into Caml code */
|
|
|
|
mov alloc_ptr, #0
|
1998-10-15 09:10:53 -07:00
|
|
|
str alloc_ptr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Reload new allocation pointer and allocation limit */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lyoung_ptr
|
|
|
|
ldr alloc_ptr, [r10, #0]
|
1998-10-10 07:56:53 -07:00
|
|
|
ldr alloc_limit, .Lyoung_limit
|
|
|
|
/* Return to caller */
|
1998-10-15 09:10:53 -07:00
|
|
|
ldmfd sp!, {pc}
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* Call a C function from Caml */
|
1998-10-15 09:10:53 -07:00
|
|
|
/* Function to call is in r10 */
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
.global caml_c_call
|
|
|
|
caml_c_call:
|
|
|
|
/* Preserve return address in callee-save register r4 */
|
|
|
|
mov r4, lr
|
|
|
|
/* Record lowest stack address and return address */
|
|
|
|
ldr r5, .Lcaml_last_return_address
|
|
|
|
ldr r6, .Lcaml_bottom_of_stack
|
|
|
|
str lr, [r5, #0]
|
|
|
|
str sp, [r6, #0]
|
|
|
|
/* Make the exception handler and alloc ptr available to the C code */
|
|
|
|
ldr r6, .Lyoung_ptr
|
|
|
|
ldr r7, .Lcaml_exception_pointer
|
|
|
|
str alloc_ptr, [r6, #0]
|
|
|
|
str trap_ptr, [r7, #0]
|
|
|
|
/* Call the function */
|
|
|
|
mov lr, pc
|
1998-10-15 09:10:53 -07:00
|
|
|
mov pc, r10
|
|
|
|
/* Reload alloc ptr */
|
1998-10-10 07:56:53 -07:00
|
|
|
ldr alloc_ptr, [r6, #0] /* r6 still points to young_ptr */
|
|
|
|
/* Say that we are back into Caml code */
|
1998-10-15 09:10:53 -07:00
|
|
|
mov r6, #0
|
|
|
|
str r6, [r5, #0] /* r5 still points to caml_last_return_address */
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Return */
|
|
|
|
mov pc, r4
|
|
|
|
|
|
|
|
/* Start the Caml program */
|
|
|
|
|
|
|
|
.global caml_start_program
|
|
|
|
caml_start_program:
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr r10, .Lcaml_program
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* Code shared with callback* */
|
1998-10-15 09:10:53 -07:00
|
|
|
/* Address of Caml code to call is in r10 */
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Arguments to the Caml code are in r0...r3 */
|
|
|
|
|
|
|
|
.Ljump_to_caml:
|
|
|
|
/* Save return address and callee-save registers */
|
1998-10-15 09:10:53 -07:00
|
|
|
stmfd sp!, {r4,r5,r6,r7,r8,r9,r11,lr}
|
1998-10-10 07:56:53 -07:00
|
|
|
stfd f7, [sp, #-8]!
|
|
|
|
stfd f6, [sp, #-8]!
|
|
|
|
stfd f5, [sp, #-8]!
|
|
|
|
stfd f4, [sp, #-8]!
|
|
|
|
/* Setup a callback link on the stack */
|
|
|
|
sub sp, sp, #4*3
|
|
|
|
ldr r4, .Lcaml_bottom_of_stack
|
|
|
|
ldr r4, [r4, #0]
|
|
|
|
str r4, [sp, #0]
|
|
|
|
ldr r4, .Lcaml_last_return_address
|
|
|
|
ldr r4, [r4, #0]
|
|
|
|
str r4, [sp, #4]
|
|
|
|
ldr r4, .Lcaml_gc_regs
|
|
|
|
ldr r4, [r4, #0]
|
|
|
|
str r4, [sp, #8]
|
|
|
|
/* Setup a trap frame to catch exceptions escaping the Caml code */
|
|
|
|
sub sp, sp, #4*2
|
|
|
|
ldr r4, .Lcaml_exception_pointer
|
|
|
|
ldr r4, [r4, #0]
|
|
|
|
str r4, [sp, #0]
|
|
|
|
ldr r4, .LLtrap_handler
|
|
|
|
str r4, [sp, #4]
|
2000-04-05 11:30:22 -07:00
|
|
|
mov trap_ptr, sp
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Reload allocation pointers */
|
|
|
|
ldr r4, .Lyoung_ptr
|
|
|
|
ldr alloc_ptr, [r4, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr alloc_limit, .Lyoung_limit
|
1998-10-10 07:56:53 -07:00
|
|
|
/* We are back into Caml code */
|
|
|
|
ldr r4, .Lcaml_last_return_address
|
|
|
|
mov r5, #0
|
|
|
|
str r5, [r4, #0]
|
|
|
|
/* Call the Caml code */
|
|
|
|
mov lr, pc
|
1998-10-15 09:10:53 -07:00
|
|
|
mov pc, r10
|
1998-10-10 07:56:53 -07:00
|
|
|
.Lcaml_retaddr:
|
|
|
|
/* Pop the trap frame, restoring caml_exception_pointer */
|
|
|
|
ldr r4, .Lcaml_exception_pointer
|
|
|
|
ldr r5, [sp, #0]
|
|
|
|
str r5, [r4, #0]
|
|
|
|
add sp, sp, #2 * 4
|
|
|
|
/* Pop the callback link, restoring the global variables */
|
1999-02-14 08:48:25 -08:00
|
|
|
.Lreturn_result:
|
1998-10-10 07:56:53 -07:00
|
|
|
ldr r4, .Lcaml_bottom_of_stack
|
|
|
|
ldr r5, [sp, #0]
|
|
|
|
str r5, [r4, #0]
|
|
|
|
ldr r4, .Lcaml_last_return_address
|
|
|
|
ldr r5, [sp, #4]
|
|
|
|
str r5, [r4, #0]
|
|
|
|
ldr r4, .Lcaml_gc_regs
|
|
|
|
ldr r5, [sp, #8]
|
|
|
|
str r5, [r4, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
add sp, sp, #4*3
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Update allocation pointer */
|
|
|
|
ldr r4, .Lyoung_ptr
|
|
|
|
str alloc_ptr, [r4, #0]
|
|
|
|
/* Reload callee-save registers and return */
|
|
|
|
ldfd f4, [sp], #8
|
|
|
|
ldfd f5, [sp], #8
|
|
|
|
ldfd f6, [sp], #8
|
|
|
|
ldfd f7, [sp], #8
|
1998-10-15 09:10:53 -07:00
|
|
|
ldmfd sp!, {r4,r5,r6,r7,r8,r9,r11,pc}
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* The trap handler */
|
|
|
|
.Ltrap_handler:
|
1999-11-18 06:42:01 -08:00
|
|
|
/* Save exception pointer */
|
|
|
|
ldr r4, .Lcaml_exception_pointer
|
|
|
|
str trap_ptr, [r4, #0]
|
1999-02-14 08:48:25 -08:00
|
|
|
/* Encode exception bucket as an exception result */
|
|
|
|
orr r0, r0, #2
|
|
|
|
/* Return it */
|
|
|
|
b .Lreturn_result
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* Raise an exception from C */
|
|
|
|
|
|
|
|
.global raise_caml_exception
|
|
|
|
raise_caml_exception:
|
|
|
|
/* Reload Caml allocation pointers */
|
|
|
|
ldr r1, .Lyoung_ptr
|
|
|
|
ldr alloc_ptr, [r1, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
ldr alloc_limit, .Lyoung_limit
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Say we're back into Caml */
|
|
|
|
ldr r1, .Lcaml_last_return_address
|
|
|
|
mov r2, #0
|
|
|
|
str r2, [r1, #0]
|
|
|
|
/* Cut stack at current trap handler */
|
|
|
|
ldr r1, .Lcaml_exception_pointer
|
|
|
|
ldr sp, [r1, #0]
|
1998-10-15 09:10:53 -07:00
|
|
|
/* Pop previous handler and addr of trap, and jump to it */
|
2000-04-05 11:30:22 -07:00
|
|
|
ldmfd sp!, {trap_ptr, pc}
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* Callback from C to Caml */
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.global callback_exn
|
|
|
|
callback_exn:
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Initial shuffling of arguments (r0 = closure, r1 = first arg) */
|
1998-10-15 09:10:53 -07:00
|
|
|
mov r10, r0
|
|
|
|
mov r0, r1 /* r0 = first arg */
|
|
|
|
mov r1, r10 /* r1 = closure environment */
|
|
|
|
ldr r10, [r10, #0] /* code pointer */
|
1998-10-10 07:56:53 -07:00
|
|
|
b .Ljump_to_caml
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.global callback2_exn
|
|
|
|
callback2_exn:
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Initial shuffling of arguments (r0 = closure, r1 = arg1, r2 = arg2) */
|
1998-10-15 09:10:53 -07:00
|
|
|
mov r10, r0
|
|
|
|
mov r0, r1 /* r0 = first arg */
|
|
|
|
mov r1, r2 /* r1 = second arg */
|
|
|
|
mov r2, r10 /* r2 = closure environment */
|
|
|
|
ldr r10, .Lcaml_apply2
|
1998-10-10 07:56:53 -07:00
|
|
|
b .Ljump_to_caml
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
.global callback3_exn
|
|
|
|
callback3_exn:
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Initial shuffling of arguments */
|
|
|
|
/* (r0 = closure, r1 = arg1, r2 = arg2, r3 = arg3) */
|
1998-10-15 09:10:53 -07:00
|
|
|
mov r10, r0
|
1998-10-10 07:56:53 -07:00
|
|
|
mov r0, r1 /* r0 = first arg */
|
|
|
|
mov r1, r2 /* r1 = second arg */
|
1998-10-15 09:10:53 -07:00
|
|
|
mov r2, r3 /* r2 = third arg */
|
|
|
|
mov r3, r10 /* r3 = closure environment */
|
|
|
|
ldr r10, .Lcaml_apply3
|
1998-10-10 07:56:53 -07:00
|
|
|
b .Ljump_to_caml
|
|
|
|
|
1998-11-11 07:35:48 -08:00
|
|
|
.global caml_array_bound_error
|
1999-02-01 06:14:24 -08:00
|
|
|
caml_array_bound_error:
|
1998-11-11 07:35:48 -08:00
|
|
|
/* Load address of array_bound_error in r10 */
|
|
|
|
ldr r10, .Larray_bound_error
|
|
|
|
/* Call that function */
|
|
|
|
b caml_c_call
|
|
|
|
|
1998-10-10 07:56:53 -07:00
|
|
|
/* Global references */
|
|
|
|
|
|
|
|
.Lcaml_last_return_address: .word caml_last_return_address
|
|
|
|
.Lcaml_bottom_of_stack: .word caml_bottom_of_stack
|
|
|
|
.Lcaml_gc_regs: .word caml_gc_regs
|
|
|
|
.Lyoung_ptr: .word young_ptr
|
|
|
|
.Lyoung_limit: .word young_limit
|
|
|
|
.Lcaml_exception_pointer: .word caml_exception_pointer
|
|
|
|
.Lcaml_program: .word caml_program
|
|
|
|
.LLtrap_handler: .word .Ltrap_handler
|
|
|
|
.Lcaml_apply2: .word caml_apply2
|
|
|
|
.Lcaml_apply3: .word caml_apply3
|
2000-04-05 11:30:22 -07:00
|
|
|
.Lcaml_requested_size: .word 0
|
1998-11-11 07:35:48 -08:00
|
|
|
.Larray_bound_error: .word array_bound_error
|
1998-10-10 07:56:53 -07:00
|
|
|
|
|
|
|
/* GC roots for callback */
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
2002-02-08 08:55:44 -08:00
|
|
|
.global system__frametable
|
|
|
|
system__frametable:
|
1998-10-10 07:56:53 -07:00
|
|
|
.word 1 /* one descriptor */
|
|
|
|
.word .Lcaml_retaddr /* return address into callback */
|
|
|
|
.short -1 /* negative frame size => use callback link */
|
|
|
|
.short 0 /* no roots */
|
|
|
|
.align 2
|