1 /*------------------------------------------------------------------*/
3 /* Name - exceptions-alpha.c */
5 /* Function - Exception support for Alpha. */
7 /* Name - Sergey Tikhonov (tsv@solvo.ru) */
9 /* Date - January, 2006 */
11 /* Derivation - From exceptions-amd64 & exceptions-ia64 */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
14 /* Zoltan Varga (vargaz@gmail.com) */
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 /*------------------------------------------------------------------*/
22 #define ALPHA_DEBUG(x) \
23 if (mini_alpha_verbose_level) \
24 g_debug ("ALPHA_DEBUG: %s is called.", x);
26 #define ALPHA_PRINT if (mini_alpha_verbose_level)
30 extern int mini_alpha_verbose_level;
32 /*========================= End of Defines =========================*/
35 /*------------------------------------------------------------------*/
37 /*------------------------------------------------------------------*/
45 #include <mono/arch/alpha/alpha-codegen.h>
46 #include <mono/metadata/appdomain.h>
47 #include <mono/metadata/tabledefs.h>
48 #include <mono/metadata/threads.h>
49 #include <mono/metadata/debug-helpers.h>
50 #include <mono/metadata/exception.h>
51 #include <mono/metadata/mono-debug.h>
54 #include "mini-alpha.h"
56 /*========================= End of Includes ========================*/
58 /*------------------------------------------------------------------*/
60 /* Name - mono_arch_get_call_filter */
62 /* Function - Return a pointer to a method which calls an */
63 /* exception filter. We also use this function to */
64 /* call finally handlers (we pass NULL as @exc */
65 /* object in this case). */
67 /*------------------------------------------------------------------*/
70 mono_arch_get_call_filter (void)
72 static gboolean inited = FALSE;
73 static unsigned int *start_code;
76 ALPHA_DEBUG("mono_arch_get_call_filter");
81 start_code = code = mono_global_codeman_reserve (128 * 4);
83 /* call_filter (MonoContext *ctx, unsigned long eip) */
86 alpha_ldah( code, alpha_gp, alpha_pv, 0 );
87 alpha_lda( code, alpha_gp, alpha_gp, 0 ); // ldgp gp, 0(pv)
89 /* store call convention parameters on stack */
90 alpha_lda(code, alpha_sp, alpha_sp, -(8*25)); // Save 22 regs + RA, FP
91 alpha_stq(code, alpha_ra, alpha_sp, 0);
92 alpha_stq(code, alpha_fp, alpha_sp, 8);
94 /* set the frame pointer */
95 alpha_mov1( code, alpha_sp, alpha_fp );
98 alpha_stq(code, alpha_r1, alpha_fp, (16+(8*0)));
99 alpha_stq(code, alpha_r2, alpha_fp, (16+(8*1)));
100 alpha_stq(code, alpha_r3, alpha_fp, (16+(8*2)));
101 alpha_stq(code, alpha_r4, alpha_fp, (16+(8*3)));
102 alpha_stq(code, alpha_r5, alpha_fp, (16+(8*4)));
103 alpha_stq(code, alpha_r6, alpha_fp, (16+(8*5)));
104 alpha_stq(code, alpha_r7, alpha_fp, (16+(8*6)));
105 alpha_stq(code, alpha_r8, alpha_fp, (16+(8*7)));
106 alpha_stq(code, alpha_r9, alpha_fp, (16+(8*8)));
107 alpha_stq(code, alpha_r10, alpha_fp, (16+(8*9)));
108 alpha_stq(code, alpha_r11, alpha_fp, (16+(8*10)));
109 alpha_stq(code, alpha_r12, alpha_fp, (16+(8*11)));
110 alpha_stq(code, alpha_r13, alpha_fp, (16+(8*12)));
111 alpha_stq(code, alpha_r14, alpha_fp, (16+(8*13)));
112 alpha_stq(code, alpha_r22, alpha_fp, (16+(8*14)));
113 alpha_stq(code, alpha_r23, alpha_fp, (16+(8*15)));
114 alpha_stq(code, alpha_r24, alpha_fp, (16+(8*16)));
115 alpha_stq(code, alpha_r25, alpha_fp, (16+(8*17)));
116 alpha_stq(code, alpha_r26, alpha_fp, (16+(8*18)));
117 alpha_stq(code, alpha_r27, alpha_fp, (16+(8*19)));
118 alpha_stq(code, alpha_r28, alpha_fp, (16+(8*20)));
119 alpha_stq(code, alpha_r29, alpha_fp, (16+(8*21)));
121 /* Load regs from ctx */
123 alpha_ldq(code, alpha_r1, alpha_a0,
124 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r1]));
125 alpha_ldq(code, alpha_r2, alpha_a0,
126 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r2]));
127 alpha_ldq(code, alpha_r3, alpha_a0,
128 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r3]));
129 alpha_ldq(code, alpha_r4, alpha_a0,
130 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r4]));
131 alpha_ldq(code, alpha_r5, alpha_a0,
132 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r5]));
133 alpha_ldq(code, alpha_r6, alpha_a0,
134 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r6]));
135 alpha_ldq(code, alpha_r7, alpha_a0,
136 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r7]));
137 alpha_ldq(code, alpha_r8, alpha_a0,
138 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r8]));
139 alpha_ldq(code, alpha_r9, alpha_a0,
140 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r9]));
141 alpha_ldq(code, alpha_r10, alpha_a0,
142 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r10]));
143 alpha_ldq(code, alpha_r11, alpha_a0,
144 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r11]));
145 alpha_ldq(code, alpha_r12, alpha_a0,
146 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r12]));
147 alpha_ldq(code, alpha_r13, alpha_a0,
148 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r13]));
149 alpha_ldq(code, alpha_r14, alpha_a0,
150 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r14]));
151 alpha_ldq(code, alpha_r15, alpha_a0,
152 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r15]));
153 alpha_ldq(code, alpha_r22, alpha_a0,
154 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r22]));
155 alpha_ldq(code, alpha_r23, alpha_a0,
156 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r23]));
157 alpha_ldq(code, alpha_r24, alpha_a0,
158 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r24]));
159 alpha_ldq(code, alpha_r25, alpha_a0,
160 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r25]));
161 alpha_ldq(code, alpha_r26, alpha_a0,
162 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r26]));
163 alpha_ldq(code, alpha_r27, alpha_a0,
164 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r27]));
165 alpha_ldq(code, alpha_r28, alpha_a0,
166 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r28]));
167 alpha_ldq(code, alpha_r29, alpha_a0,
168 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r29]));
170 alpha_mov1(code, alpha_a1, alpha_pv);
172 /* call the handler */
173 alpha_jsr(code, alpha_ra, alpha_pv, 0);
175 /* restore saved regs */
176 alpha_ldq(code, alpha_r1, alpha_sp, (16+(8*0)));
177 alpha_ldq(code, alpha_r2, alpha_sp, (16+(8*1)));
178 alpha_ldq(code, alpha_r3, alpha_sp, (16+(8*2)));
179 alpha_ldq(code, alpha_r4, alpha_sp, (16+(8*3)));
180 alpha_ldq(code, alpha_r5, alpha_sp, (16+(8*4)));
181 alpha_ldq(code, alpha_r6, alpha_sp, (16+(8*5)));
182 alpha_ldq(code, alpha_r7, alpha_sp, (16+(8*6)));
183 alpha_ldq(code, alpha_r8, alpha_sp, (16+(8*7)));
184 alpha_ldq(code, alpha_r9, alpha_sp, (16+(8*8)));
185 alpha_ldq(code, alpha_r10, alpha_sp, (16+(8*9)));
186 alpha_ldq(code, alpha_r11, alpha_sp, (16+(8*10)));
187 alpha_ldq(code, alpha_r12, alpha_sp, (16+(8*11)));
188 alpha_ldq(code, alpha_r13, alpha_sp, (16+(8*12)));
189 alpha_ldq(code, alpha_r14, alpha_sp, (16+(8*13)));
190 alpha_ldq(code, alpha_r22, alpha_sp, (16+(8*14)));
191 alpha_ldq(code, alpha_r23, alpha_sp, (16+(8*15)));
192 alpha_ldq(code, alpha_r24, alpha_sp, (16+(8*16)));
193 alpha_ldq(code, alpha_r25, alpha_sp, (16+(8*17)));
194 alpha_ldq(code, alpha_r26, alpha_sp, (16+(8*18)));
195 alpha_ldq(code, alpha_r27, alpha_sp, (16+(8*19)));
196 alpha_ldq(code, alpha_r28, alpha_sp, (16+(8*20)));
197 alpha_ldq(code, alpha_r29, alpha_sp, (16+(8*21)));
199 alpha_ldq(code, alpha_ra, alpha_sp, 0);
200 alpha_ldq(code, alpha_fp, alpha_sp, 8);
201 alpha_lda(code, alpha_sp, alpha_sp, (8*25)); // Save 22 regs + RA, FP
203 alpha_ret(code, alpha_ra, 1);
207 g_assert (( ((char *)code) - (char *)start_code) < 128 * 4);
212 /*========================= End of Function ========================*/
214 /*------------------------------------------------------------------*/
216 /* Name - arch_get_throw_exception */
218 /* Function - Return a function pointer which can be used to */
219 /* raise exceptions. The returned function has the */
220 /* following signature: */
221 /* void (*func) (MonoException *exc); */
223 /*------------------------------------------------------------------*/
225 static void throw_exception(MonoException *exc, unsigned long RA,
226 unsigned long *SP, unsigned long rethrow)
228 static void (*restore_context) (MonoContext *);
230 unsigned long *LSP = SP - 24;
232 //g_print("ALPHA: throw_exception - Exc: %p, RA: %0lX, SP: %p\n",
235 if (!restore_context)
236 restore_context = mono_arch_get_restore_context ();
238 // Save stored regs into context
239 ctx.uc_mcontext.sc_regs[alpha_r0] = LSP[0];
240 ctx.uc_mcontext.sc_regs[alpha_r1] = LSP[1];
241 ctx.uc_mcontext.sc_regs[alpha_r2] = LSP[2];
242 ctx.uc_mcontext.sc_regs[alpha_r3] = LSP[3];
243 ctx.uc_mcontext.sc_regs[alpha_r4] = LSP[4];
244 ctx.uc_mcontext.sc_regs[alpha_r5] = LSP[5];
245 ctx.uc_mcontext.sc_regs[alpha_r6] = LSP[6];
246 ctx.uc_mcontext.sc_regs[alpha_r7] = LSP[7];
247 ctx.uc_mcontext.sc_regs[alpha_r8] = LSP[8];
248 ctx.uc_mcontext.sc_regs[alpha_r9] = LSP[9];
249 ctx.uc_mcontext.sc_regs[alpha_r10] = LSP[10];
250 ctx.uc_mcontext.sc_regs[alpha_r11] = LSP[11];
251 ctx.uc_mcontext.sc_regs[alpha_r12] = LSP[12];
252 ctx.uc_mcontext.sc_regs[alpha_r13] = LSP[13];
253 ctx.uc_mcontext.sc_regs[alpha_r14] = LSP[14];
254 ctx.uc_mcontext.sc_regs[alpha_r15] = LSP[15];
255 ctx.uc_mcontext.sc_regs[alpha_r22] = LSP[16];
256 ctx.uc_mcontext.sc_regs[alpha_r23] = LSP[17];
257 ctx.uc_mcontext.sc_regs[alpha_r24] = LSP[18];
258 ctx.uc_mcontext.sc_regs[alpha_r25] = LSP[19];
259 ctx.uc_mcontext.sc_regs[alpha_r26] = LSP[20];
260 ctx.uc_mcontext.sc_regs[alpha_r27] = LSP[21];
261 ctx.uc_mcontext.sc_regs[alpha_r28] = LSP[22];
262 ctx.uc_mcontext.sc_regs[alpha_r29] = LSP[23];
264 ctx.uc_mcontext.sc_regs[alpha_r30] = (unsigned long)SP;
265 ctx.uc_mcontext.sc_pc = RA;
267 if (mono_object_isinst (exc, mono_defaults.exception_class))
269 MonoException *mono_ex = (MonoException*)exc;
271 mono_ex->stack_trace = NULL;
274 mono_handle_exception (&ctx, exc);
276 restore_context(&ctx);
278 g_assert_not_reached ();
282 ** This trampoline code is called from the code as action on
283 ** throw opcode. It should save all necessary regs somethere and
284 ** call the C function to do the rest.
285 ** For Alpha trampoline code should allocate space on stack and
286 ** save all registers into it. Then call "throw_exception"
287 ** function with "exc" info and saved registers. The "throw_exception"
288 ** should handle the rest. The "throw_exception" has signature
289 ** void (*throw_exception)(MonoException *, long PC, long SP)
290 ** The stack layout is:
291 ** R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14,
292 ** R15, R22, R23, R24, R25, R26, R27, R28, R29
298 get_throw_trampoline (gboolean rethrow)
303 start_code = mono_global_codeman_reserve (46*4);
305 code = (unsigned int *)start_code;
307 /* Exception is in a0 already */
308 alpha_mov1(code, alpha_ra, alpha_a1); // Return address
309 alpha_mov1(code, alpha_sp, alpha_a2); // Stack pointer
312 alpha_lda(code, alpha_a3, alpha_zero, 1);
314 alpha_mov1(code, alpha_zero, alpha_a3);
316 alpha_lda(code, alpha_sp, alpha_sp, -(24*8)); // Allocate stack for regs
318 alpha_stq(code, alpha_r0, alpha_sp, 0*8);
319 alpha_stq(code, alpha_r1, alpha_sp, 1*8);
320 alpha_stq(code, alpha_r2, alpha_sp, 2*8);
321 alpha_stq(code, alpha_r3, alpha_sp, 3*8);
322 alpha_stq(code, alpha_r4, alpha_sp, 4*8);
323 alpha_stq(code, alpha_r5, alpha_sp, 5*8);
324 alpha_stq(code, alpha_r6, alpha_sp, 6*8);
325 alpha_stq(code, alpha_r7, alpha_sp, 7*8);
326 alpha_stq(code, alpha_r8, alpha_sp, 8*8);
327 alpha_stq(code, alpha_r9, alpha_sp, 9*8);
328 alpha_stq(code, alpha_r10, alpha_sp, 10*8);
329 alpha_stq(code, alpha_r11, alpha_sp, 11*8);
330 alpha_stq(code, alpha_r12, alpha_sp, 12*8);
331 alpha_stq(code, alpha_r13, alpha_sp, 13*8);
332 alpha_stq(code, alpha_r14, alpha_sp, 14*8);
333 alpha_stq(code, alpha_r15, alpha_sp, 15*8);
334 alpha_stq(code, alpha_r22, alpha_sp, 16*8);
335 alpha_stq(code, alpha_r23, alpha_sp, 17*8);
336 alpha_stq(code, alpha_r24, alpha_sp, 18*8);
337 alpha_stq(code, alpha_r25, alpha_sp, 19*8);
338 alpha_stq(code, alpha_r26, alpha_sp, 20*8);
339 alpha_stq(code, alpha_r27, alpha_sp, 21*8);
340 alpha_stq(code, alpha_r28, alpha_sp, 22*8);
341 alpha_stq(code, alpha_r29, alpha_sp, 23*8);
343 alpha_mov1(code, alpha_zero, alpha_pv);
344 alpha_lda(code, alpha_r1, alpha_zero,
345 ((unsigned long)throw_exception)&0xFFFF);
346 alpha_lda(code, alpha_r2, alpha_zero,
347 (((unsigned long)throw_exception) >> 16)&0xFFFF);
348 alpha_lda(code, alpha_r3, alpha_zero,
349 (((unsigned long)throw_exception) >> 32)&0xFFFF);
350 alpha_lda(code, alpha_r4, alpha_zero,
351 (((unsigned long)throw_exception) >> 48)&0xFFFF);
352 alpha_zapnot_(code, alpha_r1, 0x3, alpha_r1);
353 alpha_bis(code, alpha_r1, alpha_pv, alpha_pv);
355 alpha_zapnot_(code, alpha_r2, 0x3, alpha_r2);
356 alpha_sll_(code, alpha_r2, 16, alpha_r2);
357 alpha_bis(code, alpha_r2, alpha_pv, alpha_pv);
359 alpha_zapnot_(code, alpha_r3, 0x3, alpha_r3);
360 alpha_sll_(code, alpha_r3, 32, alpha_r3);
361 alpha_bis(code, alpha_r3, alpha_pv, alpha_pv);
363 alpha_zapnot_(code, alpha_r4, 0x3, alpha_r4);
364 alpha_sll_(code, alpha_r4, 48, alpha_r4);
365 alpha_bis(code, alpha_r4, alpha_pv, alpha_pv); // pv - handle_exception addr
367 alpha_jmp(code, alpha_zero, alpha_pv, 0);
369 // alpha_break(code);
371 g_assert (( ((char *)code) - (char *)start_code) < 46 * 4);
377 * mono_arch_get_throw_exception:
379 * Returns a function pointer which can be used to raise
380 * exceptions. The returned function has the following
381 * signature: void (*func) (MonoException *exc);
385 mono_arch_get_throw_exception (void)
387 static guint8* start;
388 static gboolean inited = FALSE;
390 ALPHA_DEBUG("mono_arch_get_throw_exception");
395 start = get_throw_trampoline (FALSE);
401 /*========================= End of Function ========================*/
405 * mono_arch_get_throw_corlib_exception:
407 * Returns a function pointer which can be used to raise
408 * corlib exceptions. The returned function has the following
409 * signature: void (*func) (guint32 ex_token, guint32 offset);
410 * Here, offset is the offset which needs to be substracted from the caller IP
411 * to get the IP of the throw. Passing the offset has the advantage that it
412 * needs no relocations in the caller.
415 mono_arch_get_throw_corlib_exception (void)
417 static guint8* start;
418 static gboolean inited = FALSE;
422 ALPHA_DEBUG("mono_arch_get_throw_corlib_exception");
427 start = mono_global_codeman_reserve (512);
429 code = (unsigned int *)start;
431 // Expect exception token as parameter
432 // call mono_exception_from_token(void *, uint32 token)
433 // Get result and call "throw_ex" (got from mono_arch_get_throw_exception)
436 // The trampoline code will be called with PV set
437 // so expect correct ABI handling
439 //alpha_ldah(code, alpha_gp, alpha_pv, 0);
440 //alpha_lda(code, alpha_gp, alpha_gp, 0);
441 alpha_lda(code, alpha_sp, alpha_sp, -(8*4));
444 alpha_stq(code, alpha_gp, alpha_sp, 24);
446 /* store call convention parameters on stack */
447 alpha_stq( code, alpha_ra, alpha_sp, 0 ); // ra
448 alpha_stq( code, alpha_fp, alpha_sp, 8 ); // fp
450 /* set the frame pointer */
451 alpha_mov1(code, alpha_sp, alpha_fp );
453 // Store throw_ip offset
454 alpha_stq(code, alpha_a1, alpha_fp, 16);
456 // Prepare to call "mono_exception_from_token (MonoImage *image, guint32 token)"
457 // Move token to a1 reg
458 alpha_mov1(code, alpha_a0, alpha_a1);
460 alpha_mov1(code, alpha_zero, alpha_a0);
461 alpha_lda(code, alpha_r1, alpha_zero,
462 ((unsigned long)mono_defaults.exception_class->image)&0xFFFF);
463 alpha_lda(code, alpha_r2, alpha_zero,
464 (((unsigned long)mono_defaults.exception_class->image) >> 16)&0xFFFF);
465 alpha_lda(code, alpha_r3, alpha_zero,
466 (((unsigned long)mono_defaults.exception_class->image) >> 32)&0xFFFF);
467 alpha_lda(code, alpha_r4, alpha_zero,
468 (((unsigned long)mono_defaults.exception_class->image) >> 48)&0xFFFF);
469 alpha_zapnot_(code, alpha_r1, 0x3, alpha_r1);
470 alpha_bis(code, alpha_r1, alpha_a0, alpha_a0);
472 alpha_zapnot_(code, alpha_r2, 0x3, alpha_r2);
473 alpha_sll_(code, alpha_r2, 16, alpha_r2);
474 alpha_bis(code, alpha_r2, alpha_a0, alpha_a0);
476 alpha_zapnot_(code, alpha_r3, 0x3, alpha_r3);
477 alpha_sll_(code, alpha_r3, 32, alpha_r3);
478 alpha_bis(code, alpha_r3, alpha_a0, alpha_a0);
480 alpha_zapnot_(code, alpha_r4, 0x3, alpha_r4);
481 alpha_sll_(code, alpha_r4, 48, alpha_r4);
482 alpha_bis(code, alpha_r4, alpha_a0, alpha_a0); // a0 - mono_defaults.exception_class->image
484 alpha_mov1(code, alpha_zero, alpha_pv);
485 alpha_lda(code, alpha_r1, alpha_zero,
486 ((unsigned long)mono_exception_from_token)&0xFFFF);
487 alpha_lda(code, alpha_r2, alpha_zero,
488 (((unsigned long)mono_exception_from_token) >> 16)&0xFFFF);
489 alpha_lda(code, alpha_r3, alpha_zero,
490 (((unsigned long)mono_exception_from_token) >> 32)&0xFFFF);
491 alpha_lda(code, alpha_r4, alpha_zero,
492 (((unsigned long)mono_exception_from_token) >> 48)&0xFFFF);
493 alpha_zapnot_(code, alpha_r1, 0x3, alpha_r1);
494 alpha_bis(code, alpha_r1, alpha_pv, alpha_pv);
496 alpha_zapnot_(code, alpha_r2, 0x3, alpha_r2);
497 alpha_sll_(code, alpha_r2, 16, alpha_r2);
498 alpha_bis(code, alpha_r2, alpha_pv, alpha_pv);
500 alpha_zapnot_(code, alpha_r3, 0x3, alpha_r3);
501 alpha_sll_(code, alpha_r3, 32, alpha_r3);
502 alpha_bis(code, alpha_r3, alpha_pv, alpha_pv);
504 alpha_zapnot_(code, alpha_r4, 0x3, alpha_r4);
505 alpha_sll_(code, alpha_r4, 48, alpha_r4);
506 alpha_bis(code, alpha_r4, alpha_pv, alpha_pv); // pv - mono_exception_from_token addr
508 alpha_jsr(code, alpha_ra, alpha_pv, 0);
510 // R0 holds pointer to initialised exception object
512 throw_ex = (guint64)mono_arch_get_throw_exception ();
514 alpha_mov1(code, alpha_r0, alpha_a0);
516 // Calc return address
517 alpha_mov1(code, alpha_fp, alpha_sp);
518 alpha_ldq(code, alpha_ra, alpha_sp, 0);
519 alpha_ldq(code, alpha_fp, alpha_sp, 8);
520 alpha_ldq(code, alpha_a1, alpha_sp, 16);
521 alpha_addq(code, alpha_ra, alpha_a1, alpha_ra);
522 alpha_ldq(code, alpha_gp, alpha_sp, 24);
524 // Modify stack to point to exception caller
525 alpha_lda(code, alpha_sp, alpha_sp, (8*4));
527 alpha_mov1(code, alpha_zero, alpha_pv);
528 alpha_lda(code, alpha_r1, alpha_zero,
529 ((unsigned long)throw_ex)&0xFFFF);
530 alpha_lda(code, alpha_r2, alpha_zero,
531 (((unsigned long)throw_ex) >> 16)&0xFFFF);
532 alpha_lda(code, alpha_r3, alpha_zero,
533 (((unsigned long)throw_ex) >> 32)&0xFFFF);
534 alpha_lda(code, alpha_r4, alpha_zero,
535 (((unsigned long)throw_ex) >> 48)&0xFFFF);
536 alpha_zapnot_(code, alpha_r1, 0x3, alpha_r1);
537 alpha_bis(code, alpha_r1, alpha_pv, alpha_pv);
539 alpha_zapnot_(code, alpha_r2, 0x3, alpha_r2);
540 alpha_sll_(code, alpha_r2, 16, alpha_r2);
541 alpha_bis(code, alpha_r2, alpha_pv, alpha_pv);
543 alpha_zapnot_(code, alpha_r3, 0x3, alpha_r3);
544 alpha_sll_(code, alpha_r3, 32, alpha_r3);
545 alpha_bis(code, alpha_r3, alpha_pv, alpha_pv);
547 alpha_zapnot_(code, alpha_r4, 0x3, alpha_r4);
548 alpha_sll_(code, alpha_r4, 48, alpha_r4);
549 alpha_bis(code, alpha_r4, alpha_pv, alpha_pv); // pv - handle_exception addr
551 alpha_jmp(code, alpha_zero, alpha_pv, 0);
553 g_assert (((char *)code - (char *)start) < 512);
560 /*------------------------------------------------------------------*/
562 /* Name - mono_arch_handle_exception */
564 /* Function - Handle an exception raised by the JIT code. */
566 /* Parameters - ctx - Saved processor state */
567 /* obj - The exception object */
569 /*------------------------------------------------------------------*/
572 mono_arch_handle_exception (void *uc, gpointer obj)
574 ALPHA_DEBUG("mono_arch_handle_exception");
576 return mono_handle_exception (uc, obj);
579 /*========================= End of Function ========================*/
581 /*------------------------------------------------------------------*/
583 /* Name - mono_arch_get_restore_context */
585 /* Function - Return the address of the routine that will rest- */
586 /* ore the context. */
588 /*------------------------------------------------------------------*/
591 mono_arch_get_restore_context ()
593 static guint8 *start_code = NULL;
594 static gboolean inited = FALSE;
597 ALPHA_DEBUG("mono_arch_get_restore_context");
602 /* restore_contect (MonoContext *ctx) */
604 start_code = mono_global_codeman_reserve (30*4);
606 code = (unsigned int *)start_code;
608 alpha_ldq(code, alpha_r0, alpha_a0,
609 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r0]));
610 alpha_ldq(code, alpha_r1, alpha_a0,
611 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r1]));
612 alpha_ldq(code, alpha_r2, alpha_a0,
613 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r2]));
614 alpha_ldq(code, alpha_r3, alpha_a0,
615 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r3]));
616 alpha_ldq(code, alpha_r4, alpha_a0,
617 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r4]));
618 alpha_ldq(code, alpha_r5, alpha_a0,
619 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r5]));
620 alpha_ldq(code, alpha_r6, alpha_a0,
621 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r6]));
622 alpha_ldq(code, alpha_r7, alpha_a0,
623 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r7]));
624 alpha_ldq(code, alpha_r8, alpha_a0,
625 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r8]));
626 alpha_ldq(code, alpha_r9, alpha_a0,
627 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r9]));
628 alpha_ldq(code, alpha_r10, alpha_a0,
629 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r10]));
630 alpha_ldq(code, alpha_r11, alpha_a0,
631 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r11]));
632 alpha_ldq(code, alpha_r12, alpha_a0,
633 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r12]));
634 alpha_ldq(code, alpha_r13, alpha_a0,
635 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r13]));
636 alpha_ldq(code, alpha_r14, alpha_a0,
637 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r14]));
638 alpha_ldq(code, alpha_r15, alpha_a0,
639 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r15]));
640 alpha_ldq(code, alpha_r22, alpha_a0,
641 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r22]));
642 alpha_ldq(code, alpha_r23, alpha_a0,
643 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r23]));
644 alpha_ldq(code, alpha_r24, alpha_a0,
645 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r24]));
646 alpha_ldq(code, alpha_r25, alpha_a0,
647 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r25]));
648 alpha_ldq(code, alpha_r26, alpha_a0,
649 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r26]));
650 alpha_ldq(code, alpha_r27, alpha_a0,
651 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r27]));
652 alpha_ldq(code, alpha_r28, alpha_a0,
653 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r28]));
654 alpha_ldq(code, alpha_r29, alpha_a0,
655 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r29]));
656 alpha_ldq(code, alpha_r30, alpha_a0,
657 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_regs[alpha_r30]));
659 alpha_ldq(code, alpha_ra, alpha_a0,
660 G_STRUCT_OFFSET(MonoContext, uc_mcontext.sc_pc));
662 alpha_ret(code, alpha_ra, 1);
669 /*========================= End of Function ========================*/
671 /*------------------------------------------------------------------*/
673 /* Name - mono_arch_ip_from_context */
675 /* Function - Return the instruction pointer from the context. */
677 /* Parameters - sigctx - Saved processor state */
679 /*------------------------------------------------------------------*/
682 mono_arch_ip_from_context (void *sigctx)
685 ALPHA_DEBUG("mono_arch_ip_from_context");
687 ip = (gpointer) MONO_CONTEXT_GET_IP(((MonoContext *) sigctx));
689 printf("ip_from_context = %p\n", ip);
695 /*========================= End of Function ========================*/
697 /*------------------------------------------------------------------*/
699 /* Name - arch_get_rethrow_exception */
701 /* Function - Return a function pointer which can be used to */
702 /* raise exceptions. The returned function has the */
703 /* following signature: */
704 /* void (*func) (MonoException *exc); */
706 /*------------------------------------------------------------------*/
709 mono_arch_get_rethrow_exception (void)
711 static guint8 *start;
712 static int inited = 0;
714 ALPHA_DEBUG("mono_arch_get_rethrow_exception");
719 start = get_throw_trampoline (TRUE);
726 /*========================= End of Function ========================*/
728 /*------------------------------------------------------------------*/
730 /* Name - arch_get_throw_exception_by_name */
732 /* Function - Return a function pointer which can be used to */
733 /* raise corlib exceptions. The return function has */
734 /* the following signature: */
735 /* void (*func) (char *exc_name); */
737 /*------------------------------------------------------------------*/
740 mono_arch_get_throw_exception_by_name (void)
742 static guint8 *start;
743 static int inited = 0;
749 start = mono_global_codeman_reserve (SZ_THROW);
750 // get_throw_exception_generic (start, SZ_THROW, TRUE, FALSE);
753 code = (unsigned int *)start;
755 alpha_call_pal(code, 0x80);
759 /*========================= End of Function ========================*/
761 /*------------------------------------------------------------------*/
763 /* Name - mono_arch_find_jit_info */
765 /* Function - This function is used to gather informatoin from */
766 /* @ctx. It returns the MonoJitInfo of the corres- */
767 /* ponding function, unwinds one stack frame and */
768 /* stores the resulting context into @new_ctx. It */
769 /* also stores a string describing the stack location*/
770 /* into @trace (if not NULL), and modifies the @lmf */
771 /* if necessary. @native_offset returns the IP off- */
772 /* set from the start of the function or -1 if that */
773 /* information is not available. */
775 /*------------------------------------------------------------------*/
778 mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
779 MonoJitInfo *res, MonoJitInfo *prev_ji,
781 MonoContext *new_ctx, MonoLMF **lmf,
782 mgreg_t **save_locations,
787 gpointer ip = MONO_CONTEXT_GET_IP (ctx);
789 ALPHA_DEBUG("mono_arch_find_jit_info");
791 /* Avoid costly table lookup during stack overflow */
793 (ip > prev_ji->code_start &&
794 ((guint8*)ip < ((guint8*)prev_ji->code_start) + prev_ji->code_size)))
797 ji = mini_jit_info_table_find (domain, ip, NULL);
805 gboolean omit_fp = 0; //(ji->used_regs & (1 << 31)) > 0;
810 if (!ji->method->wrapper_type)
814 * Some managed methods like pinvoke wrappers might have save_lmf set.
815 * In this case, register save/restore code is not generated by the
816 * JIT, so we have to restore callee saved registers from the lmf.
819 if (ji->method->save_lmf)
822 * We only need to do this if the exception was raised in managed
823 * code, since otherwise the lmf was already popped of the stack.
825 if (*lmf && ((*lmf) != jit_tls->first_lmf) &&
826 (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->rsp))
828 new_ctx->uc_mcontext.sc_regs[alpha_fp] = (*lmf)->ebp;
829 new_ctx->uc_mcontext.sc_regs[alpha_sp] = (*lmf)->rsp;
830 new_ctx->uc_mcontext.sc_regs[alpha_gp] = (*lmf)->rgp;
833 new_ctx->rbp = (*lmf)->ebp;
834 new_ctx->rbx = (*lmf)->rbx;
835 new_ctx->rsp = (*lmf)->rsp;
836 new_ctx->r12 = (*lmf)->r12;
837 new_ctx->r13 = (*lmf)->r13;
838 new_ctx->r14 = (*lmf)->r14;
839 new_ctx->r15 = (*lmf)->r15;
845 offset = omit_fp ? 0 : 2;
847 /* restore caller saved registers */
848 for (i = 0; i < MONO_MAX_IREGS; i++)
849 if (ALPHA_IS_CALLEE_SAVED_REG(i) &&
850 (ji->used_regs & (1 << i)))
857 reg = *((guint64*)ctx->rsp + offset);
862 //reg = *((guint64 *)ctx->SC_EBP + offset);
887 g_assert_not_reached ();
893 if (*lmf && ((*lmf) != jit_tls->first_lmf) &&
894 (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->rsp)) {
895 /* remove any unused lmf */
896 *lmf = (*lmf)->previous_lmf;
903 new_ctx->rsp += (ji->used_regs >> 16) & (0x7fff);
904 new_ctx->SC_EIP = *((guint64 *)new_ctx->rsp) - 1;
905 /* Pop return address */
912 /* Pop FP and the RA */
913 /* Some how we should find size of frame. One way:
914 read 3rd instruction (alpha_lda(alpha_sp, alpha_sp, -stack_size ))
915 and extract "stack_size" from there
916 read 4th and 5th insts to get offsets to saved RA & FP
918 unsigned int *code = (unsigned int *)ji->code_start;
919 short stack_size = -((short)(code[2] & 0xFFFF));
920 short ra_off = code[3] & 0xFFFF;
921 short fp_off = code[4] & 0xFFFF;
923 /* Restore stack - value of FP reg + stack_size */
924 new_ctx->uc_mcontext.sc_regs[alpha_sp] =
925 ctx->uc_mcontext.sc_regs[alpha_r15] + stack_size;
927 /* we substract 1, so that the IP points into the call instruction */
928 /* restore PC - @FP + 0 */
929 new_ctx->uc_mcontext.sc_pc =
930 *((guint64 *)(ctx->uc_mcontext.sc_regs[alpha_r15] + ra_off));
932 /* Restore FP reg - @FP + 8 */
933 new_ctx->uc_mcontext.sc_regs[alpha_r15] =
934 *((guint64 *)(ctx->uc_mcontext.sc_regs[alpha_r15] + fp_off));
936 /* Restore GP - read two insts that restore GP from sc_pc and */
937 /* do the same. Use sc_pc as RA */
938 code = (unsigned int *)new_ctx->uc_mcontext.sc_pc;
939 if ((code[0] & 0xFFFF0000) == 0x27ba0000 && // ldah gp,high_off(ra)
940 (code[1] & 0xFFFF0000) == 0x23bd0000) // lda gp,low_off(gp)
942 short high_off = (short)(code[0] & 0xFFFF);
943 short low_off = (short)(code[1] & 0xFFFF);
945 long rgp = new_ctx->uc_mcontext.sc_pc +
946 (65536 * high_off) + low_off;
948 new_ctx->uc_mcontext.sc_regs[alpha_gp] = rgp;
953 /* Pop arguments off the stack */
954 // No poping args off stack on Alpha
955 // We use fixed place
957 MonoJitArgumentInfo *arg_info =
958 g_newa (MonoJitArgumentInfo,
959 mono_method_signature (ji->method)->param_count + 1);
961 guint32 stack_to_pop =
962 mono_arch_get_argument_info (mono_method_signature (ji->method),
963 mono_method_signature (ji->method)->param_count,
965 new_ctx->uc_mcontext.sc_regs[alpha_sp] += stack_to_pop;
972 // Unwind based on LMF info
976 if ((ji = mini_jit_info_table_find (domain, (gpointer)(*lmf)->eip, NULL))) {
978 memset (res, 0, MONO_SIZEOF_JIT_INFO);
979 res->method = (*lmf)->method;
982 new_ctx->uc_mcontext.sc_regs[alpha_fp] = (*lmf)->ebp;
983 new_ctx->uc_mcontext.sc_regs[alpha_sp] = (*lmf)->rsp;
984 new_ctx->uc_mcontext.sc_regs[alpha_gp] = (*lmf)->rgp;
985 new_ctx->uc_mcontext.sc_pc = (*lmf)->eip;
987 *lmf = (*lmf)->previous_lmf;
989 return ji ? ji : res;
995 /*========================= End of Function ========================*/