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 typedef struct actual_ucontext {
60 unsigned long uc_flags;
61 struct actual_ucontext *uc_link;
63 struct actual_mcontext uc_mcontext;
64 unsigned long uc_filler[80];
65 sigset_t uc_sigmask; /* mask last for extensibility */
70 * linux specific initializations
76 act.sa_sigaction = md_signal_handler_sigill;
77 act.sa_flags = SA_NODEFER | SA_SIGINFO;
79 if (sigaction(SIGILL, &act, NULL) == -1) {
80 vm_abort("md_linux_init: Error registering signal handler");
84 /* md_signal_handler_sigsegv ******************************************
88 void md_signal_handler_sigsegv(/*int sig, siginfo_t *siginfo, void *_p*/)
94 * This handler is used to generate hardware exceptions.
95 * Type of exception derived from trap number.
96 * If an object is needed a tst instruction (2 byte long) has
97 * been created directly before the trap instruction (2 bytes long).
98 * the last 3 bit of this tst instruction contain the register number.
100 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, actual_ucontext_t *_uc)
105 uint32_t val, regval;
106 java_objectheader *e;
109 if (siginfo->si_code != ILL_ILLTRP) {
110 vm_abort("md_signal_handler_sigill: Caught something not a trap");
113 xpc = siginfo->si_addr;
114 opc = *(uint16_t*)(xpc-2);
117 vm_abort("md_signal_handler_sigill: the illegal instruction @ 0x%x, aborting", xpc);
120 assert( (opc&0xfff0) == 0x4e40 );
121 type = opc & 0x000f; /* filter trap number */
123 _mc = &_uc->uc_mcontext;
124 sp = _mc->gregs[R_SP];
126 /* Figure out in which register the object causing the exception resides for exceptions
130 case EXCEPTION_HARDWARE_CLASSCAST:
131 regval = *(uint16_t*)(xpc-4);
132 assert( (regval&0xfff0) == 0x4a00 );
133 /* was in a address register */
134 regval = _mc->gregs[ 8 + (regval & 0x7) ];
139 fprintf(stderr, "NEW HWE: sp=%x, xpc=%x, tpye=%x, regval=%x\n", sp, xpc, type, regval);
140 e = exceptions_new_hardware_exception(0, sp, xpc, xpc, type, regval);
142 _mc->gregs[REG_ATMP1] = (ptrint) e;
143 _mc->gregs[REG_ATMP2_XPC] = (ptrint) xpc;
144 _mc->gregs[R_PC] = (ptrint) asm_handle_exception;