blob: c99c774984ed9ca36e8b5c64d042c8a73f60b585 [file] [log] [blame]
Ian Rogersbdb03912011-09-14 00:55:44 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "context_arm.h"
4
5#include "object.h"
6
7namespace art {
8namespace arm {
9
10ArmContext::ArmContext() {
Ian Rogers67375ac2011-09-14 00:55:44 -070011#ifndef NDEBUG
Ian Rogersad42e132011-09-17 20:23:33 -070012 // Initialize registers with easy to spot debug values
Ian Rogersbdb03912011-09-14 00:55:44 -070013 for (int i=0; i < 16; i++) {
Ian Rogers67375ac2011-09-14 00:55:44 -070014 gprs_[i] = 0xEBAD6070+i;
Ian Rogersbdb03912011-09-14 00:55:44 -070015 }
Ian Rogers15fdb8c2011-09-25 15:45:07 -070016 for (int i=0; i < 32; i++) {
17 fprs_[i] = 0xEBAD8070+i;
18 }
Ian Rogers67375ac2011-09-14 00:55:44 -070019#endif
Ian Rogersbdb03912011-09-14 00:55:44 -070020}
21
22void ArmContext::FillCalleeSaves(const Frame& fr) {
23 Method* method = fr.GetMethod();
24 uint32_t core_spills = method->GetCoreSpillMask();
Ian Rogers15fdb8c2011-09-25 15:45:07 -070025 uint32_t fp_core_spills = method->GetFpSpillMask();
Ian Rogersbdb03912011-09-14 00:55:44 -070026 size_t spill_count = __builtin_popcount(core_spills);
Ian Rogers15fdb8c2011-09-25 15:45:07 -070027 size_t fp_spill_count = __builtin_popcount(fp_core_spills);
Ian Rogersbdb03912011-09-14 00:55:44 -070028 if (spill_count > 0) {
29 // Lowest number spill is furthest away, walk registers and fill into context
30 int j = 1;
31 for(int i = 0; i < 16; i++) {
32 if (((core_spills >> i) & 1) != 0) {
33 gprs_[i] = fr.LoadCalleeSave(spill_count - j);
34 j++;
35 }
36 }
37 }
Ian Rogers15fdb8c2011-09-25 15:45:07 -070038 if (fp_spill_count > 0) {
39 // Lowest number spill is furthest away, walk registers and fill into context
40 int j = 1;
41 for(int i = 0; i < 32; i++) {
42 if (((fp_core_spills >> i) & 1) != 0) {
43 fprs_[i] = fr.LoadCalleeSave(spill_count + fp_spill_count - j);
44 j++;
45 }
46 }
47 }
Ian Rogersbdb03912011-09-14 00:55:44 -070048}
49
50void ArmContext::DoLongJump() {
Elliott Hughes85d15452011-09-16 17:33:01 -070051#if defined(__arm__)
Ian Rogers15fdb8c2011-09-25 15:45:07 -070052 // TODO: Load all GPRs, currently R0 to R3 aren't restored
53 asm volatile ( "vldm %2, {%%s0-%%s31}\n"
54 "mov %%r0, %0\n"
Ian Rogersbdb03912011-09-14 00:55:44 -070055 "mov %%r1, %1\n"
Ian Rogers15fdb8c2011-09-25 15:45:07 -070056 "ldm %%r0, {%%r4-%%r14}\n"
Ian Rogersbdb03912011-09-14 00:55:44 -070057 "mov %%pc,%%r1\n"
58 : // output
Ian Rogers15fdb8c2011-09-25 15:45:07 -070059 : "r"(&gprs_[4]), "r"(gprs_[R15]), "r"(&fprs_[S0]) // input
Ian Rogersbdb03912011-09-14 00:55:44 -070060 :); // clobber
Elliott Hughes85d15452011-09-16 17:33:01 -070061#else
62 UNIMPLEMENTED(FATAL);
63#endif
Ian Rogersbdb03912011-09-14 00:55:44 -070064}
65
66} // namespace arm
67} // namespace art