blob: 479b950b65cae308e63eb9265a14ce1d8816a9ee [file] [log] [blame]
Ian Rogersbdb03912011-09-14 00:55:44 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "context_x86.h"
4
Ian Rogers67375ac2011-09-14 00:55:44 -07005#include "object.h"
Elliott Hughes85d15452011-09-16 17:33:01 -07006
Ian Rogersbdb03912011-09-14 00:55:44 -07007namespace art {
8namespace x86 {
9
Ian Rogers67375ac2011-09-14 00:55:44 -070010X86Context::X86Context() {
Ian Rogersad42e132011-09-17 20:23:33 -070011#ifndef NDEBUG
12 // Initialize registers with easy to spot debug values
Ian Rogers67375ac2011-09-14 00:55:44 -070013 for (int i=0; i < 8; i++) {
14 gprs_[i] = 0xEBAD6070+i;
15 }
Ian Rogersad42e132011-09-17 20:23:33 -070016 eip_ = 0xEBAD601F;
17#endif
Ian Rogers67375ac2011-09-14 00:55:44 -070018}
19
20void 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;
28 for(int i = 0; i < 8; i++) {
29 if (((core_spills >> i) & 1) != 0) {
30 gprs_[i] = fr.LoadCalleeSave(spill_count - j);
31 j++;
32 }
33 }
34 }
35}
36
Ian Rogersbdb03912011-09-14 00:55:44 -070037void X86Context::DoLongJump() {
Elliott Hughes85d15452011-09-16 17:33:01 -070038#if defined(__i386__)
Ian Rogersbdb03912011-09-14 00:55:44 -070039 // Load ESP and EIP
Ian Rogers67375ac2011-09-14 00:55:44 -070040 gprs_[ESP] -= 4; // push EIP for return
41 *((uintptr_t*)(gprs_[ESP])) = eip_;
42 asm volatile (
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 Rogersbdb03912011-09-14 00:55:44 -070058 :); // clobber
Elliott Hughes85d15452011-09-16 17:33:01 -070059#else
Ian Rogers67375ac2011-09-14 00:55:44 -070060 UNIMPLEMENTED(FATAL);
Elliott Hughes85d15452011-09-16 17:33:01 -070061#endif
Ian Rogersbdb03912011-09-14 00:55:44 -070062}
63
64} // namespace x86
65} // namespace art