blob: 04976a52fe28fcb96e6665d0652a8ce13e595bc8 [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() {
11 for (int i=0; i < 8; i++) {
12 gprs_[i] = 0xEBAD6070+i;
13 }
14}
15
16void 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 Rogersbdb03912011-09-14 00:55:44 -070033void X86Context::DoLongJump() {
Elliott Hughes85d15452011-09-16 17:33:01 -070034#if defined(__i386__)
Ian Rogersbdb03912011-09-14 00:55:44 -070035 // Load ESP and EIP
Ian Rogers67375ac2011-09-14 00:55:44 -070036 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 Rogersbdb03912011-09-14 00:55:44 -070054 :); // clobber
Elliott Hughes85d15452011-09-16 17:33:01 -070055#else
Ian Rogers67375ac2011-09-14 00:55:44 -070056 UNIMPLEMENTED(FATAL);
Elliott Hughes85d15452011-09-16 17:33:01 -070057#endif
Ian Rogersbdb03912011-09-14 00:55:44 -070058}
59
60} // namespace x86
61} // namespace art