Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "context_x86.h" |
| 4 | |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 5 | #include "object.h" |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 6 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 7 | namespace art { |
| 8 | namespace x86 { |
| 9 | |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 10 | X86Context::X86Context() { |
| 11 | for (int i=0; i < 8; i++) { |
| 12 | gprs_[i] = 0xEBAD6070+i; |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | void X86Context::FillCalleeSaves(const Frame& fr) { |
| 17 | Method* method = fr.GetMethod(); |
| 18 | uint32_t core_spills = method->GetCoreSpillMask(); |
| 19 | size_t spill_count = __builtin_popcount(core_spills); |
| 20 | CHECK_EQ(method->GetFpSpillMask(), 0u); |
| 21 | if (spill_count > 0) { |
| 22 | // Lowest number spill is furthest away, walk registers and fill into context |
| 23 | int j = 1; |
| 24 | for(int i = 0; i < 8; i++) { |
| 25 | if (((core_spills >> i) & 1) != 0) { |
| 26 | gprs_[i] = fr.LoadCalleeSave(spill_count - j); |
| 27 | j++; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 33 | void X86Context::DoLongJump() { |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 34 | #if defined(__i386__) |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 35 | // Load ESP and EIP |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 36 | gprs_[ESP] -= 4; // push EIP for return |
| 37 | *((uintptr_t*)(gprs_[ESP])) = eip_; |
| 38 | asm volatile ( |
| 39 | "pushl %4\n\t" |
| 40 | "pushl %0\n\t" |
| 41 | "pushl %1\n\t" |
| 42 | "pushl %2\n\t" |
| 43 | "pushl %3\n\t" |
| 44 | "pushl %4\n\t" |
| 45 | "pushl %5\n\t" |
| 46 | "pushl %6\n\t" |
| 47 | "pushl %7\n\t" |
| 48 | "popal\n\t" |
| 49 | "popl %%esp\n\t" |
| 50 | "ret\n\t" |
| 51 | : //output |
| 52 | : "g"(gprs_[EAX]), "g"(gprs_[ECX]), "g"(gprs_[EDX]), "g"(gprs_[EBX]), |
| 53 | "g"(gprs_[ESP]), "g"(gprs_[EBP]), "g"(gprs_[ESI]), "g"(gprs_[EDI]) |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 54 | :); // clobber |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 55 | #else |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 56 | UNIMPLEMENTED(FATAL); |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 57 | #endif |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace x86 |
| 61 | } // namespace art |