blob: 79a581d3a8e7b769e41bce5bda9df2e983458a29 [file] [log] [blame]
Shih-wei Liao31384c52011-09-06 15:27:45 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "assembler_arm.h"
4#include "jni_internal.h"
5#include "object.h"
6
7#define __ assembler->
8
9namespace art {
10namespace arm {
11
Shih-wei Liaoc486c112011-09-13 16:43:52 -070012typedef void (*ThrowAme)(Method*, Thread*);
13
Ian Rogersbdb03912011-09-14 00:55:44 -070014ByteArray* CreateAbstractMethodErrorStub() {
Shih-wei Liaoc486c112011-09-13 16:43:52 -070015 UniquePtr<ArmAssembler> assembler( static_cast<ArmAssembler*>(Assembler::Create(kArm)) );
16
Ian Rogersff1ed472011-09-20 13:46:24 -070017 // Save callee saves and ready frame for exception delivery
18 RegList save = (1 << R1) | (1 << R2) | (1 << R3) | (1 << R4) | (1 << R5) | (1 << R6) | (1 << R7) |
19 (1 << R8) | (1 << R9) | (1 << R10) | (1 << R11) | (1 << LR);
20 __ PushList(save);
21 __ IncreaseFrameSize(16); // 4 words of space, bottom word will hold callee save Method*
Shih-wei Liaoc486c112011-09-13 16:43:52 -070022
Ian Rogersff1ed472011-09-20 13:46:24 -070023 // R0 is the Method* already
24 __ mov(R1, ShifterOperand(R9)); // Pass Thread::Current() in R1
25 __ mov(R2, ShifterOperand(SP)); // Pass SP in R2
Ian Rogersbdb03912011-09-14 00:55:44 -070026 // Call to throw AbstractMethodError
27 __ LoadFromOffset(kLoadWord, R12, TR, OFFSETOF_MEMBER(Thread, pThrowAbstractMethodErrorFromCode));
Shih-wei Liaoc486c112011-09-13 16:43:52 -070028 // Leaf call to routine that never returns
29 __ mov(PC, ShifterOperand(R12));
30
31 __ bkpt(0);
32
33 assembler->EmitSlowPaths();
34
35 size_t cs = assembler->CodeSize();
36 ByteArray* abstract_stub = ByteArray::Alloc(cs);
37 CHECK(abstract_stub != NULL);
38 MemoryRegion code(abstract_stub->GetData(), abstract_stub->GetLength());
39 assembler->FinalizeInstructions(code);
40
41 return abstract_stub;
42}
43
Shih-wei Liao31384c52011-09-06 15:27:45 -070044ByteArray* CreateJniStub() {
45 UniquePtr<ArmAssembler> assembler( static_cast<ArmAssembler*>(Assembler::Create(kArm)) );
46
47 RegList save = (1 << R0) | (1 << R1) | (1 << R2) | (1 << R3) | (1 << LR);
48
49 // Build frame and save registers. Save 5 registers.
50 __ PushList(save);
51 // Ensure 16-byte alignment
52 __ AddConstant(SP, -12);
53
54 // Pass Thread::Current() in R0
55 __ mov(R0, ShifterOperand(R9));
56
57 // Call FindNativeMethod
Brian Carlstrom16192862011-09-12 17:50:06 -070058 __ LoadFromOffset(kLoadWord, R12, TR, OFFSETOF_MEMBER(Thread, pFindNativeMethod));
Shih-wei Liao31384c52011-09-06 15:27:45 -070059 __ blx(R12);
60
61 // Save result of FindNativeMethod in R12
62 __ mov(R12, ShifterOperand(R0));
63
64 // Restore registers (including outgoing arguments)
65 __ AddConstant(SP, 12);
66 __ PopList(save);
67
68 __ cmp(R12, ShifterOperand(0));
69
70 // If R12 != 0 tail call into native code
71 __ mov(PC, ShifterOperand(R12), NE);
72
73 // Return to caller to handle exception
74 __ mov(PC, ShifterOperand(LR));
75
76 assembler->EmitSlowPaths();
77
78 size_t cs = assembler->CodeSize();
79 ByteArray* jni_stub = ByteArray::Alloc(cs);
80 CHECK(jni_stub != NULL);
81 MemoryRegion code(jni_stub->GetData(), jni_stub->GetLength());
82 assembler->FinalizeInstructions(code);
83
84 return jni_stub;
85}
86
87} // namespace arm
88} // namespace art