2012-08-02 18:15:15 +00:00
|
|
|
/* arm.S: JNI gluecode for ARM
|
2011-07-13 14:25:21 +00:00
|
|
|
Copyright (c) 2008-2011, Avian Contributors
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2012-07-31 16:36:01 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
.text
|
|
|
|
|
2011-08-11 01:21:48 +00:00
|
|
|
#define LOCAL(x) .L##x
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
# define GLOBAL(x) _##x
|
|
|
|
#else
|
|
|
|
# define GLOBAL(x) x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.globl GLOBAL(vmNativeCall)
|
2012-01-19 23:40:50 +00:00
|
|
|
.align 2
|
2011-08-11 01:21:48 +00:00
|
|
|
GLOBAL(vmNativeCall):
|
2009-08-06 17:52:36 +00:00
|
|
|
/*
|
|
|
|
arguments:
|
|
|
|
r0 -> r4 : function
|
|
|
|
r1 -> r5 : stackTotal
|
|
|
|
r2 : memoryTable
|
|
|
|
r3 : memoryCount
|
|
|
|
[sp, #0] -> r6 : gprTable
|
2012-07-31 16:36:01 +00:00
|
|
|
[sp, #4] -> r7 : vfpTable
|
|
|
|
[sp, #8] -> r8 : returnType
|
2009-08-06 17:52:36 +00:00
|
|
|
*/
|
|
|
|
mov ip, sp // save stack frame
|
2012-07-31 16:36:01 +00:00
|
|
|
stmfd sp!, {r4-r8, lr} // save clobbered non-volatile regs
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
// mv args into non-volatile regs
|
|
|
|
mov r4, r0
|
|
|
|
mov r5, r1
|
|
|
|
ldr r6, [ip]
|
2012-07-31 16:36:01 +00:00
|
|
|
ldr r7, [ip, #4]
|
|
|
|
ldr r8, [ip, #8]
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
// setup stack arguments if necessary
|
|
|
|
sub sp, sp, r5 // allocate stack
|
|
|
|
mov ip, sp
|
2011-08-11 01:21:48 +00:00
|
|
|
LOCAL(loop):
|
2009-08-06 17:52:36 +00:00
|
|
|
tst r3, r3
|
|
|
|
ldrne r0, [r2], #4
|
|
|
|
strne r0, [ip], #4
|
|
|
|
subne r3, r3, #4
|
2011-08-11 01:21:48 +00:00
|
|
|
bne LOCAL(loop)
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
// setup argument registers if necessary
|
|
|
|
tst r6, r6
|
2012-10-03 23:01:00 +00:00
|
|
|
#if (defined __APPLE__) && (defined __clang_major__) && (__clang_major__ >= 4)
|
2012-10-03 19:36:51 +00:00
|
|
|
ldmiane r6, {r0-r3}
|
|
|
|
#else
|
2009-08-06 17:52:36 +00:00
|
|
|
ldmneia r6, {r0-r3}
|
2012-10-03 19:36:51 +00:00
|
|
|
#endif
|
2012-10-01 11:39:18 +00:00
|
|
|
#if defined(__ARM_PCS_VFP)
|
2012-07-31 16:36:01 +00:00
|
|
|
// and VFP registers
|
2012-08-01 19:59:34 +00:00
|
|
|
vldmia r7, {d0-d7}
|
2012-07-31 16:36:01 +00:00
|
|
|
#endif
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2012-09-25 13:54:32 +00:00
|
|
|
#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
|
|
|
|
mov lr, pc
|
|
|
|
bx r4
|
|
|
|
#else
|
2009-08-06 17:52:36 +00:00
|
|
|
blx r4 // call function
|
2012-09-25 13:54:32 +00:00
|
|
|
#endif
|
2009-08-06 17:52:36 +00:00
|
|
|
add sp, sp, r5 // deallocate stack
|
|
|
|
|
2012-10-01 11:39:18 +00:00
|
|
|
#if defined(__ARM_PCS_VFP)
|
2012-07-31 16:36:01 +00:00
|
|
|
cmp r8,#FLOAT_TYPE
|
|
|
|
bne LOCAL(double)
|
|
|
|
fmrs r0,s0
|
|
|
|
b LOCAL(exit)
|
|
|
|
|
|
|
|
LOCAL(double):
|
|
|
|
cmp r8,#DOUBLE_TYPE
|
|
|
|
bne LOCAL(exit)
|
|
|
|
fmrrd r0,r1,d0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LOCAL(exit):
|
|
|
|
ldmfd sp!, {r4-r8, pc} // restore non-volatile regs and return
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2011-08-11 01:21:48 +00:00
|
|
|
.globl GLOBAL(vmJump)
|
2012-01-19 23:40:50 +00:00
|
|
|
.align 2
|
2011-08-11 01:21:48 +00:00
|
|
|
GLOBAL(vmJump):
|
2010-08-28 00:52:33 +00:00
|
|
|
mov lr, r0
|
|
|
|
ldr r0, [sp]
|
|
|
|
ldr r1, [sp, #4]
|
2009-08-06 17:52:36 +00:00
|
|
|
mov sp, r2
|
2010-08-28 00:52:33 +00:00
|
|
|
mov r8, r3
|
2010-07-12 20:18:36 +00:00
|
|
|
bx lr
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
|
|
|
|
#define CHECKPOINT_THREAD 4
|
|
|
|
#define CHECKPOINT_STACK 24
|
|
|
|
|
2011-08-11 01:21:48 +00:00
|
|
|
.globl GLOBAL(vmRun)
|
2012-01-19 23:40:50 +00:00
|
|
|
.align 2
|
2011-08-11 01:21:48 +00:00
|
|
|
GLOBAL(vmRun):
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
// r0: function
|
|
|
|
// r1: arguments
|
|
|
|
// r2: checkpoint
|
|
|
|
stmfd sp!, {r4-r11, lr}
|
2011-02-20 02:48:56 +00:00
|
|
|
// align stack
|
|
|
|
sub sp, sp, #12
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
|
|
|
|
str sp, [r2, #CHECKPOINT_STACK]
|
|
|
|
|
|
|
|
mov r12, r0
|
|
|
|
ldr r0, [r2, #CHECKPOINT_THREAD]
|
|
|
|
|
2012-09-25 13:54:32 +00:00
|
|
|
#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
|
|
|
|
mov lr, pc
|
|
|
|
bx r12
|
|
|
|
#else
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
blx r12
|
2012-09-25 13:54:32 +00:00
|
|
|
#endif
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
|
2011-08-11 01:21:48 +00:00
|
|
|
.globl GLOBAL(vmRun_returnAddress)
|
2012-01-19 23:40:50 +00:00
|
|
|
.align 2
|
2011-08-11 01:21:48 +00:00
|
|
|
GLOBAL(vmRun_returnAddress):
|
2011-02-20 02:48:56 +00:00
|
|
|
add sp, sp, #12
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
ldmfd sp!, {r4-r11, lr}
|
|
|
|
bx lr
|