1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
12 /***********************************************************************/
16 /* Asm part of the runtime system, Mips processor, IRIX n32 conventions */
26 /* Reserve stack space for registers and saved $gp */
27 /* 32 * 8 = 0x100 for float regs
28 22 * 4 = 0x58 for integer regs
29 8 = 0x8 for saved $gp ====> 0x160 total */
32 .cpsetup $25, 0x158, caml_call_gc
33 /* Record return address */
34 sw $
31, caml_last_return_address
35 /* Record lowest stack address */
37 sw $
24, caml_bottom_of_stack
38 /* Save pointer to register array */
41 /* Save current allocation pointer for debugging purposes */
42 sw $
22, caml_young_ptr
43 /* Save the exception handler (if e.g. a sighandler raises) */
44 sw $
30, caml_exception_pointer
45 /* Save all regs used by the code generator on the stack */
98 /* Call the garbage collector */
99 jal caml_garbage_collection
100 /* Restore all regs used by the code generator */
132 l.d $
f10, 10 * 8($sp
)
133 l.d $
f11, 11 * 8($sp
)
134 l.d $
f12, 12 * 8($sp
)
135 l.d $
f13, 13 * 8($sp
)
136 l.d $
f14, 14 * 8($sp
)
137 l.d $
f15, 15 * 8($sp
)
138 l.d $
f16, 16 * 8($sp
)
139 l.d $
f17, 17 * 8($sp
)
140 l.d $
f18, 18 * 8($sp
)
141 l.d $
f19, 19 * 8($sp
)
142 l.d $
f20, 20 * 8($sp
)
143 l.d $
f21, 21 * 8($sp
)
144 l.d $
f22, 22 * 8($sp
)
145 l.d $
f23, 23 * 8($sp
)
146 l.d $
f24, 24 * 8($sp
)
147 l.d $
f25, 25 * 8($sp
)
148 l.d $
f26, 26 * 8($sp
)
149 l.d $
f27, 27 * 8($sp
)
150 l.d $
f28, 28 * 8($sp
)
151 l.d $
f29, 29 * 8($sp
)
152 l.d $
f30, 30 * 8($sp
)
153 l.d $
f31, 31 * 8($sp
)
154 /* Reload new allocation pointer and allocation limit */
155 lw $
22, caml_young_ptr
156 lw $
23, caml_young_limit
157 /* Reload return address */
158 lw $
31, caml_last_return_address
159 /* Say that we are back into Caml code */
160 sw $
0, caml_last_return_address
161 /* Adjust return address to restart the allocation sequence */
170 /* Call a C function from Caml */
176 /* Function to call is in $24 */
177 /* Set up $gp, saving caller's $gp in callee-save register $19 */
178 .cpsetup $25, $19, caml_c_call
179 /* Preload addresses of interesting global variables
180 in callee-save registers */
181 la $
16, caml_last_return_address
182 la $
17, caml_young_ptr
183 /* Save return address, bottom of stack, alloc ptr, exn ptr */
184 sw $
31, 0($
16) /* caml_last_return_address */
185 sw $sp
, caml_bottom_of_stack
186 sw $
22, 0($
17) /* caml_young_ptr */
187 sw $
30, caml_exception_pointer
188 /* Call C function */
191 /* Reload return address, alloc ptr, alloc limit */
192 lw $
31, 0($
16) /* caml_last_return_address */
193 lw $
22, 0($
17) /* caml_young_ptr */
194 lw $
23, caml_young_limit
/* caml_young_limit */
195 /* Zero caml_last_return_address, indicating we're back in Caml code */
196 sw $
0, 0($
16) /* caml_last_return_address */
197 /* Restore $gp and return */
202 /* Start the Caml program */
204 .globl caml_start_program
205 .globl stray_exn_handler
206 .ent caml_start_program
208 /* Reserve space for callee-save registers */
211 .cpsetup $25, 0x80, caml_start_program
212 /* Load in $24 the code address to call */
214 /* Code shared with caml_callback* */
216 /* Save return address */
218 /* Save all callee-save registers */
234 /* Set up a callback link on the stack. */
236 lw $
2, caml_bottom_of_stack
238 lw $
3, caml_last_return_address
242 /* Set up a trap frame to catch exceptions escaping the Caml code */
244 lw $
30, caml_exception_pointer
250 /* Reload allocation pointers */
251 lw $
22, caml_young_ptr
252 lw $
23, caml_young_limit
253 /* Say that we are back into Caml code */
254 sw $
0, caml_last_return_address
255 /* Call the Caml code */
259 /* Pop the trap frame, restoring caml_exception_pointer */
261 sw $
24, caml_exception_pointer
264 /* Pop the callback link, restoring the global variables */
266 sw $
24, caml_bottom_of_stack
268 sw $
25, caml_last_return_address
272 /* Update allocation pointer */
273 sw $
22, caml_young_ptr
274 /* Reload callee-save registers and return */
295 /* The trap handler: encode exception bucket as an exception result
298 sw $
30, caml_exception_pointer
302 .end caml_start_program
304 /* Raise an exception from C */
306 .globl caml_raise_exception
307 .ent caml_raise_exception
308 caml_raise_exception
:
309 /* Setup $gp, discarding caller's $gp (we won't return) */
310 .cpsetup $25, $24, caml_raise_exception
311 /* Branch to exn handler */
313 lw $
22, caml_young_ptr
314 lw $
23, caml_young_limit
315 lw $sp
, caml_exception_pointer
322 .end caml_raise_exception
324 /* Callback from C to Caml */
326 .globl caml_callback_exn
327 .ent caml_callback_exn
330 .cpsetup $25, 0x80, caml_callback_exn
331 /* Initial shuffling of arguments */
332 move $
9, $
4 /* closure */
333 move $
8, $
5 /* argument */
334 lw $
24, 0($
4) /* code pointer */
336 .end caml_callback_exn
338 .globl caml_callback2_exn
339 .ent caml_callback2_exn
342 .cpsetup $25, 0x80, caml_callback2_exn
343 /* Initial shuffling of arguments */
344 move $
10, $
4 /* closure */
345 move $
8, $
5 /* first argument */
346 move $
9, $
6 /* second argument */
347 la $
24, caml_apply2
/* code pointer */
350 .end caml_callback2_exn
352 .globl caml_callback3_exn
353 .ent caml_callback3_exn
356 .cpsetup $25, 0x80, caml_callback3_exn
357 /* Initial shuffling of arguments */
358 move $
11, $
4 /* closure */
359 move $
8, $
5 /* first argument */
360 move $
9, $
6 /* second argument */
361 move $
10, $
7 /* third argument */
362 la $
24, caml_apply3
/* code pointer */
365 .end caml_callback3_exn
367 /* Glue code to call [caml_array_bound_error] */
369 .globl caml_ml_array_bound_error
370 .ent caml_ml_array_bound_error
372 caml_ml_array_bound_error
:
373 /* Setup $gp, discarding caller's $gp (we won't return) */
374 .cpsetup $25, $24, caml_ml_array_bound_error
375 la $
24, caml_array_bound_error
376 jal caml_c_call
/* never returns */
378 .end caml_ml_array_bound_error
381 .globl caml_system__frametable
382 caml_system__frametable
:
383 .word 1 /* one descriptor */
384 .word $104 /* return address into callback */
385 .half -1 /* negative frame size => use callback link */
386 .half 0 /* no roots here */