LIBJAVA PORT to DG/UX (QUESTIONS)
Takis Psarogiannakopoulos
takis@XFree86.org
Wed Sep 8 13:11:00 GMT 1999
Hello,
I am trying to create a port of libjava to DG/ux.
(Data General Unix).
I will send another mail about some other changes.
For the time I need some help with the file i386-signal.h:
i586-dg-dgux should use the include/i386-signal.h
I have make it i386-dgux-signal.h as the struct in
sys/signal.h is sigcontext and not sigcontext_struct.
In the DG/ux header sys/signal.h , sigcontext struct
is (unlike linux) as:
struct sigcontext {
int sc_onstack; /* sigstack state to restore */
int sc_mask; /* signal mask to restore */
int sc_sp; /* sp to restore */
int sc_pc; /* pc to retore */
int sc_ps; /* psl to restore */
int sc_eax; /* eax to restore */
int sc_edx; /* edx to restore */
};
** %par()
** This structure describes the information pushed onto a stack
** when a signal is delivered. This is used by the sigret()
** system call to restore state following execution of the signal
** handler.
**
>From the point of view of i386-signal.h ,obviously eip is in DG/ux
sc_pc. Aslo eax , edx are sc_eax, sc_edx.
But what about the ebp stuff? I have no linux machine around
to have a look in the sigcontext and see what ebp does.
Note: I just had a look in linux. ebp is in sigcontext struct.
I sucspect that we want to use ebp for something and we restore
it after.
Anyway I am not sure how we should modify the file i386-signal.h
for ix86 DG/ux. (for the ebp stuff).
Could the developer give me his opinion ?
Here is what I have done:
-------------------------------------------------------------------
// i386-dgux-signal.h - Catch runtime signals and turn them into
exceptions.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#ifndef JAVA_SIGNAL_H
#define JAVA_SIGNAL_H 1
#include <sys/signal.h>
#define HANDLE_SEGV 1
#define HANDLE_FPE 1
#define SIGNAL_HANDLER(_name) \
static void _name (int _dummy)
#define MAKE_THROW_FRAME \
do \
{ \
void **_p = (void **)&_dummy; \
struct sigcontext *_regs = (struct sigcontext *)++_p; \
\
register unsigned long _ebp = _regs->ebp; \
register unsigned char *_sc_pc = (unsigned char *)_regs->sc_pc; \
\
/* Advance the program counter so that it is after the start of the \
instruction: the x86 exception handler expects \
the PC to point to the instruction after a call. */ \
_sc_pc += 2; \
\
asm volatile ("mov %0, (%%ebp); mov %1, 4(%%ebp)" \
: : "r"(_ebp), "r"(_sc_pc)); \
} \
while (0)
#define HANDLE_DIVIDE_OVERFLOW \
do \
{ \
void **_p = (void **)&_dummy; \
struct sigcontext *_regs = (struct sigcontext *)++_p; \
\
register unsigned long *_ebp = (unsigned long *)_regs->ebp; \
register unsigned char *_sc_pc = (unsigned char *)_regs->sc_pc; \
\
/* According to the JVM spec, "if the dividend is the negative \
* integer of the smallest magnitude and the divisor is -1, then \
* overflow occurs and the result is equal to the dividend. Despite \
* the overflow, no exception occurs". \
\
* We handle this by inspecting the instruction which generated the \
* signal and advancing sc_pc to point to the following instruction. \
* As the instructions are variable length it is necessary to do a \
* little calculation to figure out where the following instruction \
* actually is. \
\
*/ \
if (_sc_pc[0] == 0xf7) \
{ \
unsigned char _modrm = _sc_pc[1]; \
\
if (_regs->sc_eax == 0x80000000 \
&& ((_modrm >> 3) & 7) == 7) /* Signed divide */ \
{ \
_regs->sc_edx = 0; /* the remainder is zero */ \
switch (_modrm >> 6) \
{ \
case 0: \
if ((_modrm & 7) == 5) \
_sc_pc += 4; \
break; \
case 1: \
_sc_pc += 1; \
break; \
case 2: \
_sc_pc += 4; \
break; \
case 3:
break; \
} \
_sc_pc += 2; \
_regs->sc_pc = (unsigned long)_sc_pc; \
return; \
} \
else if (((_modrm >> 3) & 7) == 6) /* Unsigned divide */ \
{ \
/* We assume that unsigned divisions are in library code, so \
* we throw one level down the stack, which was hopefully \
* the place that called the library routine. This will \
* break if the library is ever compiled with \
* -fomit-frame-pointer, but at least this way we've got a \
* good chance of finding the exception handler. */ \
\
_sc_pc = (unsigned char *)_ebp[1]; \
_ebp = (unsigned long *)_ebp[0]; \
} \
else
{ \
/* Advance the program counter so that it is after the start \
of the instruction: this is because the x86 exception \
handler expects the PC to point to the instruction after a \
call. */ \
_sc_pc += 2; \
} \
} \
\
asm volatile ("mov %0, (%%ebp); mov %1, 4(%%ebp)" \
: : "r"(_ebp), "r"(_sc_pc)); \
} \
while (0)
#define INIT_SEGV \
do \
{ \
nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_handler = catch_segv; \
sigemptyset (&act.sa_mask); \
act.sa_flags = 0; \
__sigaction (SIGSEGV, &act, NULL); \
} \
while (0)
#define INIT_FPE \
do \
{ \
arithexception = new java::lang::ArithmeticException \
(JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_handler = catch_fpe; \
sigemptyset (&act.sa_mask); \
act.sa_flags = 0; \
__sigaction (SIGFPE, &act, NULL); \
} \
while (0)
#endif /* JAVA_SIGNAL_H */
------------------------------------------------------------------
Regards,
More information about the Java
mailing list