blob: a35bfe2622f6dbe47bf555a24c0665e2bf22b01f [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);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070021 __ Emit(0xed2d0a20); // vpush {s0-s31}
Ian Rogersff1ed472011-09-20 13:46:24 -070022 __ IncreaseFrameSize(16); // 4 words of space, bottom word will hold callee save Method*
Shih-wei Liaoc486c112011-09-13 16:43:52 -070023
Ian Rogersff1ed472011-09-20 13:46:24 -070024 // R0 is the Method* already
25 __ mov(R1, ShifterOperand(R9)); // Pass Thread::Current() in R1
26 __ mov(R2, ShifterOperand(SP)); // Pass SP in R2
Ian Rogersbdb03912011-09-14 00:55:44 -070027 // Call to throw AbstractMethodError
28 __ LoadFromOffset(kLoadWord, R12, TR, OFFSETOF_MEMBER(Thread, pThrowAbstractMethodErrorFromCode));
Shih-wei Liaoc486c112011-09-13 16:43:52 -070029 // Leaf call to routine that never returns
30 __ mov(PC, ShifterOperand(R12));
31
32 __ bkpt(0);
33
34 assembler->EmitSlowPaths();
35
36 size_t cs = assembler->CodeSize();
37 ByteArray* abstract_stub = ByteArray::Alloc(cs);
38 CHECK(abstract_stub != NULL);
39 MemoryRegion code(abstract_stub->GetData(), abstract_stub->GetLength());
40 assembler->FinalizeInstructions(code);
41
42 return abstract_stub;
43}
44
Shih-wei Liao31384c52011-09-06 15:27:45 -070045ByteArray* CreateJniStub() {
46 UniquePtr<ArmAssembler> assembler( static_cast<ArmAssembler*>(Assembler::Create(kArm)) );
47
48 RegList save = (1 << R0) | (1 << R1) | (1 << R2) | (1 << R3) | (1 << LR);
49
50 // Build frame and save registers. Save 5 registers.
51 __ PushList(save);
52 // Ensure 16-byte alignment
53 __ AddConstant(SP, -12);
54
55 // Pass Thread::Current() in R0
56 __ mov(R0, ShifterOperand(R9));
57
58 // Call FindNativeMethod
Brian Carlstrom16192862011-09-12 17:50:06 -070059 __ LoadFromOffset(kLoadWord, R12, TR, OFFSETOF_MEMBER(Thread, pFindNativeMethod));
Shih-wei Liao31384c52011-09-06 15:27:45 -070060 __ blx(R12);
61
62 // Save result of FindNativeMethod in R12
63 __ mov(R12, ShifterOperand(R0));
64
65 // Restore registers (including outgoing arguments)
66 __ AddConstant(SP, 12);
67 __ PopList(save);
68
69 __ cmp(R12, ShifterOperand(0));
70
71 // If R12 != 0 tail call into native code
72 __ mov(PC, ShifterOperand(R12), NE);
73
74 // Return to caller to handle exception
75 __ mov(PC, ShifterOperand(LR));
76
77 assembler->EmitSlowPaths();
78
79 size_t cs = assembler->CodeSize();
80 ByteArray* jni_stub = ByteArray::Alloc(cs);
81 CHECK(jni_stub != NULL);
82 MemoryRegion code(jni_stub->GetData(), jni_stub->GetLength());
83 assembler->FinalizeInstructions(code);
84
85 return jni_stub;
86}
87
88} // namespace arm
89} // namespace art