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