1 /* src/vm/jit/m68k/linux/md-os.c - linux specific functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: arch.h 5330 2006-09-05 18:43:12Z edwin $
35 #include "vm/exceptions.h"
36 #include "vm/jit/asmpart.h"
42 #include <sys/ucontext.h> /* has br0ken ucontext_t*/
45 * The glibc bundeled with my devels system ucontext.h differs with kernels ucontext.h. Not good.
46 * The following stuff is taken from 2.6.10 + freescale coldfire patches:
48 typedef struct actual_fpregset {
53 typedef struct actual_mcontext {
55 gregset_t gregs; /* 0...7 = %d0-%d7, 8...15 = %a0-%a7 */
56 actual_fpregset_t fpregs;
59 #define GREGS_ADRREG_OFF 8
61 typedef struct actual_ucontext {
62 unsigned long uc_flags;
63 struct actual_ucontext *uc_link;
65 struct actual_mcontext uc_mcontext;
66 unsigned long uc_filler[80];
67 sigset_t uc_sigmask; /* mask last for extensibility */
72 * linux specific initializations
78 act.sa_sigaction = md_signal_handler_sigill;
79 act.sa_flags = SA_NODEFER | SA_SIGINFO;
81 if (sigaction(SIGILL, &act, NULL) == -1) {
82 vm_abort("md_linux_init: Error registering signal handler");
86 /* md_signal_handler_sigsegv ******************************************
88 * Invoked when a Nullpointerexception occured, or when the cm
89 * crashes, hard to tell the difference.
90 **********************************************************************/
91 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, actual_ucontext_t *_uc)
95 uint32_t val, regval, off;
100 _mc = &_uc->uc_mcontext;
101 sp = _mc->gregs[R_SP];
102 xpc = _mc->gregs[R_PC];
103 opc = *(uint16_t*)xpc;
105 /* m68k uses a whole bunch of difficult to differ load instructions where null pointer check could occure */
106 /* the first two are 2*32bit sized */
109 if ((opc & ((2<<12) | (5<<3))) == ((2<<12) | (5<<3))) {
110 if (opc & (1<<6)) adrreg = true; /* M_XLD */
112 off = *(uint16_t*)(xpc+1);
113 } else if ((opc & ((2<<12) | (5<<6))) == ((2<<12) | (5<<6))) {
114 if (opc & (1<<3)) adrreg = true; /* M_XST */
115 val = (opc >> 9) & 0x0007;
116 off = *(uint16_t*)(xpc+1);
119 /*fprintf(stderr, "SEGV: short instructions %x\n", opc);
121 /* now check the 32 bit sized instructions */
122 if ((opc & (2<<3)) == (2<<3)) {
123 if (opc & (1<<6)) adrreg = true; /* M_L*X */
125 } else if ((opc & (2<<6)) == (2<<6)) {
126 if (opc & (1<<3)) adrreg = true; /* M_S*X */
127 val = (opc >> 9) & 0x0007;
129 vm_abort("md_signal_handler_sigsegv: unhandeled faulting opcode %x", opc);
133 /* val is now register number, adreg == true if it is an address regsiter */
134 regval = _mc->gregs[adrreg ? GREGS_ADRREG_OFF + val : val];
137 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", regval);
141 /*fprintf(stderr, "SEGV: sp=%x, xpc=%x, regval=%x\n", sp, xpc, regval);
143 e = exceptions_new_hardware_exception(0, sp, xpc, xpc, EXCEPTION_HARDWARE_NULLPOINTER, regval);
145 _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP1] = (ptrint) e;
146 _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP2_XPC] = (ptrint) xpc;
147 _mc->gregs[R_PC] = (ptrint) asm_handle_exception;
150 /* md_signal_handler_sigill *******************************************
152 * This handler is used to generate hardware exceptions.
153 * Type of exception derived from trap number.
154 * If an object is needed a tst instruction (2 byte long) has
155 * been created directly before the trap instruction (2 bytes long).
156 * the last 3 bit of this tst instruction contain the register number.
157 **********************************************************************/
158 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, actual_ucontext_t *_uc)
163 uint32_t val, regval;
164 java_objectheader *e;
167 xpc = siginfo->si_addr;
169 if (siginfo->si_code == ILL_ILLOPC) {
170 vm_abort("md_signal_handler_sigill: the illegal instruction @ 0x%x, aborting", xpc);
172 if (siginfo->si_code != ILL_ILLTRP) {
173 vm_abort("md_signal_handler_sigill: Caught something not a trap");
176 opc = *(uint16_t*)(xpc-2);
178 assert( (opc&0xfff0) == 0x4e40 );
179 type = opc & 0x000f; /* filter trap number */
181 _mc = &_uc->uc_mcontext;
182 sp = _mc->gregs[R_SP];
184 /* Figure out in which register the object causing the exception resides for appropiate exceptions
187 case EXCEPTION_HARDWARE_ARITHMETIC:
188 case EXCEPTION_HARDWARE_EXCEPTION:
191 case EXCEPTION_HARDWARE_CLASSCAST:
192 regval = *(uint16_t*)(xpc-4);
193 assert( (regval&0xfff0) == 0x4a00 );
194 /* was in a address register */
195 regval = _mc->gregs[ GREGS_ADRREG_OFF + (regval & 0x7) ];
197 case EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS:
198 regval = *(uint16_t*)(xpc-4);
199 assert( (regval&0xfff0) == 0x4a00 );
200 /* was a data register */
201 regval = _mc->gregs[regval & 0x7];
203 case M68K_EXCEPTION_HARDWARE_NULLPOINTER:
204 type = EXCEPTION_HARDWARE_NULLPOINTER;
210 /*fprintf(stderr, "NEW HWE: sp=%x, xpc=%x, tpye=%x, regval=%x\n", sp, xpc, type, regval);
212 e = exceptions_new_hardware_exception(0, sp, xpc, xpc, type, regval);
214 _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP1] = (ptrint) e;
215 _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP2_XPC] = (ptrint) xpc;
216 _mc->gregs[R_PC] = (ptrint) asm_handle_exception;
221 * These are local overrides for various environment variables in Emacs.
222 * Please do not remove this and leave it at the end of the file, where
223 * Emacs will automagically detect them.
224 * ---------------------------------------------------------------------
227 * indent-tabs-mode: t
231 * vim:noexpandtab:sw=4:ts=4: