#include "vm/jit/i386/codegen.h"
#include "vm/jit/i386/md.h"
-#include "threads/threads-common.h"
+#include "threads/thread.hpp"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#include "vm/jit/builtin.hpp"
#include "vm/global.h"
-#include "vm/signallocal.h"
-#include "vm/stringlocal.h"
+#include "vm/signallocal.hpp"
#include "vm/jit/asmpart.h"
#include "vm/jit/executionstate.h"
-#include "vm/jit/stacktrace.h"
+#include "vm/jit/stacktrace.hpp"
+#include "vm/jit/trap.h"
#include "vm/jit/i386/codegen.h"
u1 *sp;
u1 *ra;
u1 *xpc;
- u1 opc;
- u1 mod;
- u1 rm;
- int d;
- int32_t disp;
+ u1 opc;
+ u1 mod;
+ u1 rm;
+ int d;
+ int32_t disp;
intptr_t val;
- int type;
- void *p;
- java_object_t *o;
+ int type;
+ void *p;
_uc = (ucontext_t *) _p;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
- pv = NULL; /* is resolved during stackframeinfo creation */
- sp = (u1 *) _ss->esp;
- xpc = (u1 *) _ss->eip;
- ra = xpc; /* return address is equal to XPC */
+ pv = NULL; /* is resolved during stackframeinfo creation */
+ sp = (u1 *) _ss->__esp;
+ xpc = (u1 *) _ss->__eip;
+ ra = xpc; /* return address is equal to XPC */
- /* get exception-throwing instruction */
+ /* get exception-throwing instruction */
- opc = M_ALD_MEM_GET_OPC(xpc);
- mod = M_ALD_MEM_GET_MOD(xpc);
- rm = M_ALD_MEM_GET_RM(xpc);
+ opc = M_ALD_MEM_GET_OPC(xpc);
+ mod = M_ALD_MEM_GET_MOD(xpc);
+ rm = M_ALD_MEM_GET_RM(xpc);
- /* for values see emit_mov_mem_reg and emit_mem */
+ /* for values see emit_mov_mem_reg and emit_mem */
- if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
- /* this was a hardware-exception */
+ if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
+ /* this was a hardware-exception */
- d = M_ALD_MEM_GET_REG(xpc);
- disp = M_ALD_MEM_GET_DISP(xpc);
+ d = M_ALD_MEM_GET_REG(xpc);
+ disp = M_ALD_MEM_GET_DISP(xpc);
- /* we use the exception type as load displacement */
+ /* we use the exception type as load displacement */
- type = disp;
+ type = disp;
- val = (d == 0) ? _ss->eax :
- ((d == 1) ? _ss->ecx :
- ((d == 2) ? _ss->edx :
- ((d == 3) ? _ss->ebx :
- ((d == 4) ? _ss->esp :
- ((d == 5) ? _ss->ebp :
- ((d == 6) ? _ss->esi : _ss->edi))))));
+ val = (d == 0) ? _ss->__eax :
+ ((d == 1) ? _ss->__ecx :
+ ((d == 2) ? _ss->__edx :
+ ((d == 3) ? _ss->__ebx :
+ ((d == 4) ? _ss->__esp :
+ ((d == 5) ? _ss->__ebp :
+ ((d == 6) ? _ss->__esi : _ss->__edi))))));
- if (type == EXCEPTION_HARDWARE_COMPILER) {
+ if (type == TRAP_COMPILER) {
/* The PV from the compiler stub is equal to the XPC. */
pv = xpc;
xpc = ra - 2;
}
- }
- else {
- /* this was a normal NPE */
+ }
+ else {
+ /* this was a normal NPE */
- type = EXCEPTION_HARDWARE_NULLPOINTER;
- }
+ type = TRAP_NullPointerException;
+ }
- /* Handle the type. */
+ /* Handle the trap. */
- p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+ p = trap_handle(type, val, pv, sp, ra, xpc, _p);
/* Set registers. */
- if (type == EXCEPTION_HARDWARE_COMPILER) {
- if (p == NULL) {
- o = builtin_retrieve_exception();
-
- _ss->esp = (uintptr_t) sp; /* Remove RA from stack. */
-
- _ss->eax = (uintptr_t) o;
- _ss->ecx = (uintptr_t) xpc; /* REG_ITMP2_XPC */
- _ss->eip = (uintptr_t) asm_handle_exception;
- }
- else {
- _ss->eip = (uintptr_t) p;
+ if (type == TRAP_COMPILER) {
+ if (p == NULL) {
+ _ss->__esp = (uintptr_t) sp; /* Remove RA from stack. */
}
}
- else {
- _ss->eax = (intptr_t) p;
- _ss->ecx = (intptr_t) xpc;
- _ss->eip = (intptr_t) asm_handle_exception;
- }
}
{
ucontext_t *_uc;
mcontext_t _mc;
- u1 *pv;
+ u1 *pv;
i386_thread_state_t *_ss;
u1 *sp;
u1 *ra;
u1 *xpc;
- int type;
- intptr_t val;
- void *p;
+ int type;
+ intptr_t val;
_uc = (ucontext_t *) _p;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
- pv = NULL; /* is resolved during stackframeinfo creation */
- sp = (u1 *) _ss->esp;
- xpc = (u1 *) _ss->eip;
+ pv = NULL; /* is resolved during stackframeinfo creation */
+ sp = (u1 *) _ss->__esp;
+ xpc = (u1 *) _ss->__eip;
ra = xpc; /* return address is equal to xpc */
- /* this is an ArithmeticException */
+ /* This is an ArithmeticException */
- type = EXCEPTION_HARDWARE_ARITHMETIC;
- val = 0;
-
- /* Handle the type. */
+ type = TRAP_ArithmeticException;
+ val = 0;
- p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+ /* Handle the trap. */
- _ss->eax = (intptr_t) p;
- _ss->ecx = (intptr_t) xpc;
- _ss->eip = (intptr_t) asm_handle_exception;
+ trap_handle(type, val, pv, sp, ra, xpc, _p);
}
_uc = (ucontext_t *) _p;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
- pc = (u1 *) _ss->eip;
+ pc = (u1 *) _ss->__eip;
t->pc = pc;
}
u1 *xpc;
int type;
intptr_t val;
- void *p;
_uc = (ucontext_t *) _p;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
pv = NULL; /* is resolved during stackframeinfo creation */
- sp = (u1 *) _ss->esp;
- xpc = (u1 *) _ss->eip;
+ sp = (u1 *) _ss->__esp;
+ xpc = (u1 *) _ss->__eip;
ra = xpc; /* return address is equal to xpc */
- /* this is an ArithmeticException */
-
- type = EXCEPTION_HARDWARE_PATCHER;
+ type = TRAP_PATCHER;
val = 0;
- /* generate appropriate exception */
+ /* Handle the trap. */
- p = signal_handle(type, val, pv, sp, ra, xpc, _p);
-
- /* set registers (only if exception object ready) */
-
- if (p != NULL) {
- _ss->eax = (intptr_t) p;
- _ss->ecx = (intptr_t) xpc;
- _ss->eip = (intptr_t) asm_handle_exception;
- }
+ trap_handle(type, val, pv, sp, ra, xpc, _p);
}
/* md_executionstate_read ******************************************************
_uc = (ucontext_t *) context;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
/* read special registers */
- es->pc = (u1 *) _ss->eip;
- es->sp = (u1 *) _ss->esp;
+ es->pc = (u1 *) _ss->__eip;
+ es->sp = (u1 *) _ss->__esp;
es->pv = NULL; /* pv must be looked up via AVL tree */
/* read integer registers */
for (i = 0; i < INT_REG_CNT; i++)
- es->intregs[i] = (i == 0) ? _ss->eax :
- ((i == 1) ? _ss->ecx :
- ((i == 2) ? _ss->edx :
- ((i == 3) ? _ss->ebx :
- ((i == 4) ? _ss->esp :
- ((i == 5) ? _ss->ebp :
- ((i == 6) ? _ss->esi : _ss->edi))))));
+ es->intregs[i] = (i == 0) ? _ss->__eax :
+ ((i == 1) ? _ss->__ecx :
+ ((i == 2) ? _ss->__edx :
+ ((i == 3) ? _ss->__ebx :
+ ((i == 4) ? _ss->__esp :
+ ((i == 5) ? _ss->__ebp :
+ ((i == 6) ? _ss->__esi : _ss->__edi))))));
/* read float registers */
for (i = 0; i < FLT_REG_CNT; i++)
_uc = (ucontext_t *) context;
_mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
+ _ss = &_mc->__ss;
/* write integer registers */
for (i = 0; i < INT_REG_CNT; i++)
- *((i == 0) ? &_ss->eax :
- ((i == 1) ? &_ss->ecx :
- ((i == 2) ? &_ss->edx :
- ((i == 3) ? &_ss->ebx :
- ((i == 4) ? &_ss->esp :
- ((i == 5) ? &_ss->ebp :
- ((i == 6) ? &_ss->esi : &_ss->edi))))))) = es->intregs[i];
+ *((i == 0) ? &_ss->__eax :
+ ((i == 1) ? &_ss->__ecx :
+ ((i == 2) ? &_ss->__edx :
+ ((i == 3) ? &_ss->__ebx :
+ ((i == 4) ? &_ss->__esp :
+ ((i == 5) ? &_ss->__ebp :
+ ((i == 6) ? &_ss->__esi : &_ss->__edi))))))) = es->intregs[i];
/* write special registers */
- _ss->eip = (ptrint) es->pc;
- _ss->esp = (ptrint) es->sp;
-}
-
-
-/* md_critical_section_restart *************************************************
-
- Search the critical sections tree for a matching section and set
- the PC to the restart point, if necessary.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS)
-void thread_restartcriticalsection(ucontext_t *_uc)
-{
- mcontext_t _mc;
- i386_thread_state_t *_ss;
- u1 *pc;
- void *rpc;
-
- _mc = _uc->uc_mcontext;
- _ss = &_mc->ss;
-
- pc = (u1 *) _ss->eip;
-
- rpc = critical_find_restart_point(pc);
-
- if (rpc != NULL)
- _ss->eip = (ptrint) rpc;
+ _ss->__eip = (ptrint) es->pc;
+ _ss->__esp = (ptrint) es->sp;
}
-#endif
/*