Make exceptions thrown from bytecode back to native code work again
[cacao.git] / jit / i386 / methodtable.c
1 /* jit/i386/methodtable.c - builds a table of all methods
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authores: Christian Thalinger
29
30    $Id: methodtable.c 688 2003-12-04 23:50:25Z jowenn $
31
32 */
33
34
35 #include <stdio.h>
36 #include "methodtable.h"
37 #include "types.h"
38 #include "asmpart.h"
39 #include "toolbox/memory.h"
40
41
42 static mtentry *mtroot = NULL;
43
44
45 void addmethod(u1 *start, u1 *end)
46 {
47   /* boehm makes problems with jvm98 db */
48 #if 0
49     mtentry *mte = GCNEW(mtentry, 1);
50 #else
51     mtentry *mte = NEW(mtentry);
52 #endif
53
54     if (mtroot == NULL) {
55 #if 0
56         mtentry *tmp = GCNEW(mtentry, 1);
57 #else
58         mtentry *tmp = NEW(mtentry);
59 #endif
60                 tmp->start = (u1 *) asm_calljavamethod;
61                 tmp->end = (u1 *) asm_calljavafunction;    /* little hack, but should work */
62                 tmp->next = mtroot;
63                 mtroot = tmp;
64
65 #if 0
66         tmp = GCNEW(mtentry, 1);
67 #else
68         tmp = NEW(mtentry);
69 #endif
70                 tmp->start = (u1 *) asm_calljavafunction;
71                 tmp->end = (u1 *) asm_calljavafunction2;    /* little hack, but should work */
72                 tmp->next = mtroot;
73                 mtroot = tmp;
74
75 #if 0
76         tmp = GCNEW(mtentry, 1);
77 #else
78         tmp = NEW(mtentry);
79 #endif
80                 tmp->start = (u1 *) asm_calljavafunction2;
81                 tmp->end = (u1 *) asm_call_jit_compiler;    /* little hack, but should work */
82                 tmp->next = mtroot;
83                 mtroot = tmp;
84         }
85
86     mte->start = start;
87     mte->end = end;
88     mte->next = mtroot;
89     mtroot = mte;
90 }
91
92
93 u1 *findmethod(u1 *pos)
94 {
95     mtentry *mte = mtroot;
96
97     while (mte != NULL) {
98                 if (mte->start <= pos && pos <= mte->end) {
99                         return mte->start;
100
101                 } else {
102                         mte = mte->next;
103                 }
104     }
105
106     printf("can't find method with eip=%p\n", pos);
107     exit(-1);
108 }
109
110
111 /*
112  * These are local overrides for various environment variables in Emacs.
113  * Please do not remove this and leave it at the end of the file, where
114  * Emacs will automagically detect them.
115  * ---------------------------------------------------------------------
116  * Local variables:
117  * mode: c
118  * indent-tabs-mode: t
119  * c-basic-offset: 4
120  * tab-width: 4
121  * End:
122  */