|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "jit/x86/Assembler-x86.h" |
|
8 |
|
9 #include "gc/Marking.h" |
|
10 |
|
11 using namespace js; |
|
12 using namespace js::jit; |
|
13 |
|
14 ABIArgGenerator::ABIArgGenerator() |
|
15 : stackOffset_(0), |
|
16 current_() |
|
17 {} |
|
18 |
|
19 ABIArg |
|
20 ABIArgGenerator::next(MIRType type) |
|
21 { |
|
22 current_ = ABIArg(stackOffset_); |
|
23 switch (type) { |
|
24 case MIRType_Int32: |
|
25 case MIRType_Pointer: |
|
26 stackOffset_ += sizeof(uint32_t); |
|
27 break; |
|
28 case MIRType_Float32: // Float32 moves are actually double moves |
|
29 case MIRType_Double: |
|
30 stackOffset_ += sizeof(uint64_t); |
|
31 break; |
|
32 default: |
|
33 MOZ_ASSUME_UNREACHABLE("Unexpected argument type"); |
|
34 } |
|
35 return current_; |
|
36 } |
|
37 |
|
38 const Register ABIArgGenerator::NonArgReturnVolatileReg0 = ecx; |
|
39 const Register ABIArgGenerator::NonArgReturnVolatileReg1 = edx; |
|
40 const Register ABIArgGenerator::NonVolatileReg = ebx; |
|
41 |
|
42 void |
|
43 Assembler::executableCopy(uint8_t *buffer) |
|
44 { |
|
45 AssemblerX86Shared::executableCopy(buffer); |
|
46 |
|
47 for (size_t i = 0; i < jumps_.length(); i++) { |
|
48 RelativePatch &rp = jumps_[i]; |
|
49 JSC::X86Assembler::setRel32(buffer + rp.offset, rp.target); |
|
50 } |
|
51 } |
|
52 |
|
53 class RelocationIterator |
|
54 { |
|
55 CompactBufferReader reader_; |
|
56 uint32_t offset_; |
|
57 |
|
58 public: |
|
59 RelocationIterator(CompactBufferReader &reader) |
|
60 : reader_(reader) |
|
61 { } |
|
62 |
|
63 bool read() { |
|
64 if (!reader_.more()) |
|
65 return false; |
|
66 offset_ = reader_.readUnsigned(); |
|
67 return true; |
|
68 } |
|
69 |
|
70 uint32_t offset() const { |
|
71 return offset_; |
|
72 } |
|
73 }; |
|
74 |
|
75 static inline JitCode * |
|
76 CodeFromJump(uint8_t *jump) |
|
77 { |
|
78 uint8_t *target = (uint8_t *)JSC::X86Assembler::getRel32Target(jump); |
|
79 return JitCode::FromExecutable(target); |
|
80 } |
|
81 |
|
82 void |
|
83 Assembler::TraceJumpRelocations(JSTracer *trc, JitCode *code, CompactBufferReader &reader) |
|
84 { |
|
85 RelocationIterator iter(reader); |
|
86 while (iter.read()) { |
|
87 JitCode *child = CodeFromJump(code->raw() + iter.offset()); |
|
88 MarkJitCodeUnbarriered(trc, &child, "rel32"); |
|
89 JS_ASSERT(child == CodeFromJump(code->raw() + iter.offset())); |
|
90 } |
|
91 } |
|
92 |