jamvm
changeset 377:ffc5bc36305e
Support x86_64 ABI without libffi.
| author | rlougher |
|---|---|
| date | Fri Feb 22 01:52:26 2008 +0000 (2008-02-22) |
| parents | 0ad5394e0896 |
| children | 3360fbae42a7 |
| files | src/os/bsd/x86_64/callNative.S |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/bsd/x86_64/callNative.S Fri Feb 22 01:52:26 2008 +0000 1.3 @@ -0,0 +1,245 @@ 1.4 +/* 1.5 + * Copyright (C) 2008 Robert Lougher <rob@lougher.org.uk>. 1.6 + * 1.7 + * This file is part of JamVM. 1.8 + * 1.9 + * This program is free software; you can redistribute it and/or 1.10 + * modify it under the terms of the GNU General Public License 1.11 + * as published by the Free Software Foundation; either version 2, 1.12 + * or (at your option) any later version. 1.13 + * 1.14 + * This program is distributed in the hope that it will be useful, 1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.17 + * GNU General Public License for more details. 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License 1.20 + * along with this program; if not, write to the Free Software 1.21 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 1.22 + */ 1.23 + 1.24 +#include "config.h" 1.25 + 1.26 +#ifndef USE_FFI 1.27 +.text 1.28 +.align 2 1.29 +.global callJNIMethod 1.30 +.type callJNIMethod,function 1.31 + 1.32 +/* 1.33 + * Arguments passed in: 1.34 + * 1.35 + * %rdi JNIEnv 1.36 + * %rsi class or NULL 1.37 + * %rdx sig 1.38 + * %rcx extra arg 1.39 + * %r8 ostack 1.40 + * %r9 function pntr 1.41 + */ 1.42 + 1.43 +callJNIMethod: 1.44 + pushq %rbp 1.45 + movq %rsp, %rbp 1.46 + 1.47 + pushq %r8 1.48 + pushq %r9 1.49 + pushq %rbx 1.50 + pushq %r12 1.51 + pushq %r14 1.52 + pushq %r15 1.53 + 1.54 + testq %rsi, %rsi 1.55 + jne alloc_space 1.56 + 1.57 + movq (%r8), %rsi 1.58 + addq $8, %r8 1.59 + 1.60 +alloc_space: 1.61 + subq %rcx, %rsp 1.62 + 1.63 +/* Setup argument registers: 1.64 + * rdx, rcx, r8, r9 1.65 + * xmm0 - xmm7 1.66 + * 1.67 + * local register usage: 1.68 + * r10 = int reg count 1.69 + * r11 = double handler 1.70 + * r12 = float handler 1.71 + * r14 = sig pntr 1.72 + * r15 = stack pntr 1.73 + * rbx = ostack pntr 1.74 + */ 1.75 + 1.76 + leaq double_regs-10(%rip), %r11 1.77 + leaq float_regs-10(%rip), %r12 1.78 + leaq 1(%rdx), %r14 1.79 + movq %rsp, %r15 1.80 + xorq %r10, %r10 1.81 + movq %r8, %rbx 1.82 + 1.83 +next: 1.84 + movzbq (%r14), %rax 1.85 + incq %r14 1.86 + 1.87 + cmpq $41, %rax /* ')' */ 1.88 + je done 1.89 + cmpq $68, %rax /* 'D' */ 1.90 + je double 1.91 + cmpq $70, %rax /* 'F' */ 1.92 + je float 1.93 + cmpq $74, %rax /* 'J' */ 1.94 + je long 1.95 + 1.96 +skip_brackets: 1.97 + cmpq $91, %rax /* '[' */ 1.98 + jne check_ref 1.99 + movzbq (%r14), %rax 1.100 + incq %r14 1.101 + jmp skip_brackets 1.102 + 1.103 +check_ref: 1.104 + cmpq $76, %rax /* 'L' */ 1.105 + jne int 1.106 + 1.107 +skip_ref: 1.108 + movzbq (%r14), %rax 1.109 + incq %r14 1.110 + cmpq $59, %rax /* ';' */ 1.111 + jne skip_ref 1.112 + 1.113 +int: 1.114 + movq (%rbx), %rax 1.115 + addq $8, %rbx 1.116 + 1.117 +check_regs: 1.118 + incq %r10 1.119 + cmpq $2, %r10 1.120 + jg check_4 1.121 + 1.122 + cmovneq %rax, %rdx 1.123 + cmoveq %rax, %rcx 1.124 + jmp next 1.125 + 1.126 +check_4: 1.127 + cmpq $4, %r10 1.128 + jg stack_push 1.129 + 1.130 + cmovneq %rax, %r8 1.131 + cmoveq %rax, %r9 1.132 + jmp next 1.133 + 1.134 +stack_push: 1.135 + movq %rax, (%r15) 1.136 + addq $8, %r15 1.137 + jmp next 1.138 + 1.139 +long: 1.140 + movq (%rbx), %rax 1.141 + addq $16, %rbx 1.142 + jmp check_regs 1.143 + 1.144 +double: 1.145 + addq $10, %r11 1.146 + addq $10, %r12 1.147 + addq $16, %rbx 1.148 + jmp *%r11 1.149 + 1.150 +double_regs: 1.151 + movsd -16(%rbx), %xmm0 1.152 + jmp next 1.153 + movsd -16(%rbx), %xmm1 1.154 + jmp next 1.155 + movsd -16(%rbx), %xmm2 1.156 + jmp next 1.157 + movsd -16(%rbx), %xmm3 1.158 + jmp next 1.159 + movsd -16(%rbx), %xmm4 1.160 + jmp next 1.161 + movsd -16(%rbx), %xmm5 1.162 + jmp next 1.163 + movsd -16(%rbx), %xmm6 1.164 + jmp next 1.165 + movsd -16(%rbx), %xmm7 1.166 + jmp next 1.167 + movq -16(%rbx), %rax 1.168 + subq $10, %r11 1.169 + subq $10, %r12 1.170 + jmp stack_push 1.171 + 1.172 +float: 1.173 + addq $10, %r11 1.174 + addq $10, %r12 1.175 + addq $8, %rbx 1.176 + jmp *%r12 1.177 + 1.178 +float_regs: 1.179 + movss -8(%rbx), %xmm0 1.180 + jmp next 1.181 + movss -8(%rbx), %xmm1 1.182 + jmp next 1.183 + movss -8(%rbx), %xmm2 1.184 + jmp next 1.185 + movss -8(%rbx), %xmm3 1.186 + jmp next 1.187 + movss -8(%rbx), %xmm4 1.188 + jmp next 1.189 + movss -8(%rbx), %xmm5 1.190 + jmp next 1.191 + movss -8(%rbx), %xmm6 1.192 + jmp next 1.193 + movss -8(%rbx), %xmm7 1.194 + jmp next 1.195 + movl -8(%rbx), %eax 1.196 + subq $10, %r11 1.197 + subq $10, %r12 1.198 + jmp stack_push 1.199 + 1.200 +done: 1.201 + /* Arguments all setup -- 1.202 + call the native method */ 1.203 + 1.204 + callq *-16(%rbp) 1.205 + 1.206 + /* Get back ostack for return value */ 1.207 + movq -8(%rbp), %rcx 1.208 + 1.209 + /* Handle return type */ 1.210 + 1.211 + movzbq (%r14), %rbx 1.212 + cmpq $86, %rbx /* 'V' */ 1.213 + je return 1.214 + cmpq $68, %rbx /* 'D' */ 1.215 + je double_ret 1.216 + cmpq $70, %rbx /* 'F' */ 1.217 + je float_ret 1.218 + 1.219 + movq %rax, (%rcx) 1.220 + 1.221 + cmpq $74, %rbx /* 'J' */ 1.222 + je double_inc 1.223 + 1.224 + addq $8, %rcx 1.225 + 1.226 +return: 1.227 + movq -24(%rbp), %rbx 1.228 + movq -32(%rbp), %r12 1.229 + movq -40(%rbp), %r14 1.230 + movq -48(%rbp), %r15 1.231 + 1.232 + movq %rbp, %rsp 1.233 + popq %rbp 1.234 + 1.235 + movq %rcx, %rax 1.236 + retq 1.237 + 1.238 +double_ret: 1.239 + movsd %xmm0, (%rcx) 1.240 +double_inc: 1.241 + addq $16, %rcx 1.242 + jmp return 1.243 + 1.244 +float_ret: 1.245 + movss %xmm0, (%rcx) 1.246 + addq $8, %rcx 1.247 + jmp return 1.248 +#endif
