1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
6 // are met:
7 //
8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // - Redistribution in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the
14 // distribution.
15 //
16 // - Neither the name of Sun Microsystems or the names of contributors may
17 // be used to endorse or promote products derived from this software without
18 // specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 // OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 // The original source code covered by the above license above has been modified
34 // significantly by Google Inc.
35 // Copyright 2014 the V8 project authors. All rights reserved.
36
37 #ifndef V8_S390_ASSEMBLER_S390_INL_H_
38 #define V8_S390_ASSEMBLER_S390_INL_H_
39
40 #include "src/s390/assembler-s390.h"
41
42 #include "src/assembler.h"
43 #include "src/debug/debug.h"
44
45 namespace v8 {
46 namespace internal {
47
SupportsCrankshaft()48 bool CpuFeatures::SupportsCrankshaft() { return true; }
49
SupportsSimd128()50 bool CpuFeatures::SupportsSimd128() { return false; }
51
apply(intptr_t delta)52 void RelocInfo::apply(intptr_t delta) {
53 // Absolute code pointer inside code object moves with the code object.
54 if (IsInternalReference(rmode_)) {
55 // Jump table entry
56 Address target = Memory::Address_at(pc_);
57 Memory::Address_at(pc_) = target + delta;
58 } else if (IsCodeTarget(rmode_)) {
59 SixByteInstr instr =
60 Instruction::InstructionBits(reinterpret_cast<const byte*>(pc_));
61 int32_t dis = static_cast<int32_t>(instr & 0xFFFFFFFF) * 2 // halfwords
62 - static_cast<int32_t>(delta);
63 instr >>= 32; // Clear the 4-byte displacement field.
64 instr <<= 32;
65 instr |= static_cast<uint32_t>(dis / 2);
66 Instruction::SetInstructionBits<SixByteInstr>(reinterpret_cast<byte*>(pc_),
67 instr);
68 } else {
69 // mov sequence
70 DCHECK(IsInternalReferenceEncoded(rmode_));
71 Address target = Assembler::target_address_at(pc_, host_);
72 Assembler::set_target_address_at(isolate_, pc_, host_, target + delta,
73 SKIP_ICACHE_FLUSH);
74 }
75 }
76
target_internal_reference()77 Address RelocInfo::target_internal_reference() {
78 if (IsInternalReference(rmode_)) {
79 // Jump table entry
80 return Memory::Address_at(pc_);
81 } else {
82 // mov sequence
83 DCHECK(IsInternalReferenceEncoded(rmode_));
84 return Assembler::target_address_at(pc_, host_);
85 }
86 }
87
target_internal_reference_address()88 Address RelocInfo::target_internal_reference_address() {
89 DCHECK(IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
90 return reinterpret_cast<Address>(pc_);
91 }
92
target_address()93 Address RelocInfo::target_address() {
94 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
95 return Assembler::target_address_at(pc_, host_);
96 }
97
target_address_address()98 Address RelocInfo::target_address_address() {
99 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) ||
100 rmode_ == EMBEDDED_OBJECT || rmode_ == EXTERNAL_REFERENCE);
101
102 // Read the address of the word containing the target_address in an
103 // instruction stream.
104 // The only architecture-independent user of this function is the serializer.
105 // The serializer uses it to find out how many raw bytes of instruction to
106 // output before the next target.
107 // For an instruction like LIS/ORI where the target bits are mixed into the
108 // instruction bits, the size of the target will be zero, indicating that the
109 // serializer should not step forward in memory after a target is resolved
110 // and written.
111 return reinterpret_cast<Address>(pc_);
112 }
113
constant_pool_entry_address()114 Address RelocInfo::constant_pool_entry_address() {
115 UNREACHABLE();
116 return NULL;
117 }
118
target_address_size()119 int RelocInfo::target_address_size() { return Assembler::kSpecialTargetSize; }
120
target_address_from_return_address(Address pc)121 Address Assembler::target_address_from_return_address(Address pc) {
122 // Returns the address of the call target from the return address that will
123 // be returned to after a call.
124 // Sequence is:
125 // BRASL r14, RI
126 return pc - kCallTargetAddressOffset;
127 }
128
return_address_from_call_start(Address pc)129 Address Assembler::return_address_from_call_start(Address pc) {
130 // Sequence is:
131 // BRASL r14, RI
132 return pc + kCallTargetAddressOffset;
133 }
134
code_target_object_handle_at(Address pc)135 Handle<Object> Assembler::code_target_object_handle_at(Address pc) {
136 SixByteInstr instr =
137 Instruction::InstructionBits(reinterpret_cast<const byte*>(pc));
138 int index = instr & 0xFFFFFFFF;
139 return code_targets_[index];
140 }
141
target_object()142 Object* RelocInfo::target_object() {
143 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
144 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
145 }
146
target_object_handle(Assembler * origin)147 Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
148 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
149 if (rmode_ == EMBEDDED_OBJECT) {
150 return Handle<Object>(
151 reinterpret_cast<Object**>(Assembler::target_address_at(pc_, host_)));
152 } else {
153 return origin->code_target_object_handle_at(pc_);
154 }
155 }
156
set_target_object(Object * target,WriteBarrierMode write_barrier_mode,ICacheFlushMode icache_flush_mode)157 void RelocInfo::set_target_object(Object* target,
158 WriteBarrierMode write_barrier_mode,
159 ICacheFlushMode icache_flush_mode) {
160 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
161 Assembler::set_target_address_at(isolate_, pc_, host_,
162 reinterpret_cast<Address>(target),
163 icache_flush_mode);
164 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL &&
165 target->IsHeapObject()) {
166 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
167 host(), this, HeapObject::cast(target));
168 host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
169 }
170 }
171
target_external_reference()172 Address RelocInfo::target_external_reference() {
173 DCHECK(rmode_ == EXTERNAL_REFERENCE);
174 return Assembler::target_address_at(pc_, host_);
175 }
176
target_runtime_entry(Assembler * origin)177 Address RelocInfo::target_runtime_entry(Assembler* origin) {
178 DCHECK(IsRuntimeEntry(rmode_));
179 return target_address();
180 }
181
set_target_runtime_entry(Address target,WriteBarrierMode write_barrier_mode,ICacheFlushMode icache_flush_mode)182 void RelocInfo::set_target_runtime_entry(Address target,
183 WriteBarrierMode write_barrier_mode,
184 ICacheFlushMode icache_flush_mode) {
185 DCHECK(IsRuntimeEntry(rmode_));
186 if (target_address() != target)
187 set_target_address(target, write_barrier_mode, icache_flush_mode);
188 }
189
target_cell_handle()190 Handle<Cell> RelocInfo::target_cell_handle() {
191 DCHECK(rmode_ == RelocInfo::CELL);
192 Address address = Memory::Address_at(pc_);
193 return Handle<Cell>(reinterpret_cast<Cell**>(address));
194 }
195
target_cell()196 Cell* RelocInfo::target_cell() {
197 DCHECK(rmode_ == RelocInfo::CELL);
198 return Cell::FromValueAddress(Memory::Address_at(pc_));
199 }
200
set_target_cell(Cell * cell,WriteBarrierMode write_barrier_mode,ICacheFlushMode icache_flush_mode)201 void RelocInfo::set_target_cell(Cell* cell, WriteBarrierMode write_barrier_mode,
202 ICacheFlushMode icache_flush_mode) {
203 DCHECK(rmode_ == RelocInfo::CELL);
204 Address address = cell->address() + Cell::kValueOffset;
205 Memory::Address_at(pc_) = address;
206 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
207 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
208 cell);
209 }
210 }
211
212 #if V8_TARGET_ARCH_S390X
213 // NOP(2byte) + PUSH + MOV + BASR =
214 // NOP + LAY + STG + IIHF + IILF + BASR
215 static const int kCodeAgingSequenceLength = 28;
216 static const int kCodeAgingTargetDelta = 14; // Jump past NOP + PUSH to IIHF
217 // LAY + 4 * STG + LA
218 static const int kNoCodeAgeSequenceLength = 34;
219 #else
220 #if (V8_HOST_ARCH_S390)
221 // NOP + NILH + LAY + ST + IILF + BASR
222 static const int kCodeAgingSequenceLength = 24;
223 static const int kCodeAgingTargetDelta = 16; // Jump past NOP to IILF
224 // NILH + LAY + 4 * ST + LA
225 static const int kNoCodeAgeSequenceLength = 30;
226 #else
227 // NOP + LAY + ST + IILF + BASR
228 static const int kCodeAgingSequenceLength = 20;
229 static const int kCodeAgingTargetDelta = 12; // Jump past NOP to IILF
230 // LAY + 4 * ST + LA
231 static const int kNoCodeAgeSequenceLength = 26;
232 #endif
233 #endif
234
code_age_stub_handle(Assembler * origin)235 Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
236 UNREACHABLE(); // This should never be reached on S390.
237 return Handle<Object>();
238 }
239
code_age_stub()240 Code* RelocInfo::code_age_stub() {
241 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
242 return Code::GetCodeFromTargetAddress(
243 Assembler::target_address_at(pc_ + kCodeAgingTargetDelta, host_));
244 }
245
set_code_age_stub(Code * stub,ICacheFlushMode icache_flush_mode)246 void RelocInfo::set_code_age_stub(Code* stub,
247 ICacheFlushMode icache_flush_mode) {
248 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
249 Assembler::set_target_address_at(isolate_, pc_ + kCodeAgingTargetDelta, host_,
250 stub->instruction_start(),
251 icache_flush_mode);
252 }
253
debug_call_address()254 Address RelocInfo::debug_call_address() {
255 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
256 return Assembler::target_address_at(pc_, host_);
257 }
258
set_debug_call_address(Address target)259 void RelocInfo::set_debug_call_address(Address target) {
260 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
261 Assembler::set_target_address_at(isolate_, pc_, host_, target);
262 if (host() != NULL) {
263 Object* target_code = Code::GetCodeFromTargetAddress(target);
264 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
265 host(), this, HeapObject::cast(target_code));
266 }
267 }
268
WipeOut()269 void RelocInfo::WipeOut() {
270 DCHECK(IsEmbeddedObject(rmode_) || IsCodeTarget(rmode_) ||
271 IsRuntimeEntry(rmode_) || IsExternalReference(rmode_) ||
272 IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
273 if (IsInternalReference(rmode_)) {
274 // Jump table entry
275 Memory::Address_at(pc_) = NULL;
276 } else if (IsInternalReferenceEncoded(rmode_)) {
277 // mov sequence
278 // Currently used only by deserializer, no need to flush.
279 Assembler::set_target_address_at(isolate_, pc_, host_, NULL,
280 SKIP_ICACHE_FLUSH);
281 } else {
282 Assembler::set_target_address_at(isolate_, pc_, host_, NULL);
283 }
284 }
285
286 template <typename ObjectVisitor>
Visit(Isolate * isolate,ObjectVisitor * visitor)287 void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
288 RelocInfo::Mode mode = rmode();
289 if (mode == RelocInfo::EMBEDDED_OBJECT) {
290 visitor->VisitEmbeddedPointer(this);
291 } else if (RelocInfo::IsCodeTarget(mode)) {
292 visitor->VisitCodeTarget(this);
293 } else if (mode == RelocInfo::CELL) {
294 visitor->VisitCell(this);
295 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
296 visitor->VisitExternalReference(this);
297 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
298 visitor->VisitInternalReference(this);
299 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
300 visitor->VisitCodeAgeSequence(this);
301 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
302 IsPatchedDebugBreakSlotSequence()) {
303 visitor->VisitDebugTarget(this);
304 } else if (IsRuntimeEntry(mode)) {
305 visitor->VisitRuntimeEntry(this);
306 }
307 }
308
309 template <typename StaticVisitor>
Visit(Heap * heap)310 void RelocInfo::Visit(Heap* heap) {
311 RelocInfo::Mode mode = rmode();
312 if (mode == RelocInfo::EMBEDDED_OBJECT) {
313 StaticVisitor::VisitEmbeddedPointer(heap, this);
314 } else if (RelocInfo::IsCodeTarget(mode)) {
315 StaticVisitor::VisitCodeTarget(heap, this);
316 } else if (mode == RelocInfo::CELL) {
317 StaticVisitor::VisitCell(heap, this);
318 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
319 StaticVisitor::VisitExternalReference(this);
320 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
321 StaticVisitor::VisitInternalReference(this);
322 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
323 StaticVisitor::VisitCodeAgeSequence(heap, this);
324 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
325 IsPatchedDebugBreakSlotSequence()) {
326 StaticVisitor::VisitDebugTarget(heap, this);
327 } else if (IsRuntimeEntry(mode)) {
328 StaticVisitor::VisitRuntimeEntry(this);
329 }
330 }
331
332 // Operand constructors
Operand(intptr_t immediate,RelocInfo::Mode rmode)333 Operand::Operand(intptr_t immediate, RelocInfo::Mode rmode) {
334 rm_ = no_reg;
335 imm_ = immediate;
336 rmode_ = rmode;
337 }
338
Operand(const ExternalReference & f)339 Operand::Operand(const ExternalReference& f) {
340 rm_ = no_reg;
341 imm_ = reinterpret_cast<intptr_t>(f.address());
342 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
343 }
344
Operand(Smi * value)345 Operand::Operand(Smi* value) {
346 rm_ = no_reg;
347 imm_ = reinterpret_cast<intptr_t>(value);
348 rmode_ = kRelocInfo_NONEPTR;
349 }
350
Operand(Register rm)351 Operand::Operand(Register rm) {
352 rm_ = rm;
353 rmode_ = kRelocInfo_NONEPTR; // S390 -why doesn't ARM do this?
354 }
355
CheckBuffer()356 void Assembler::CheckBuffer() {
357 if (buffer_space() <= kGap) {
358 GrowBuffer();
359 }
360 }
361
emit_code_target(Handle<Code> target,RelocInfo::Mode rmode,TypeFeedbackId ast_id)362 int32_t Assembler::emit_code_target(Handle<Code> target, RelocInfo::Mode rmode,
363 TypeFeedbackId ast_id) {
364 DCHECK(RelocInfo::IsCodeTarget(rmode));
365 if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) {
366 SetRecordedAstId(ast_id);
367 RecordRelocInfo(RelocInfo::CODE_TARGET_WITH_ID);
368 } else {
369 RecordRelocInfo(rmode);
370 }
371
372 int current = code_targets_.length();
373 if (current > 0 && code_targets_.last().is_identical_to(target)) {
374 // Optimization if we keep jumping to the same code target.
375 current--;
376 } else {
377 code_targets_.Add(target);
378 }
379 return current;
380 }
381
382 // Helper to emit the binary encoding of a 2 byte instruction
emit2bytes(uint16_t x)383 void Assembler::emit2bytes(uint16_t x) {
384 CheckBuffer();
385 #if V8_TARGET_LITTLE_ENDIAN
386 // We need to emit instructions in big endian format as disassembler /
387 // simulator require the first byte of the instruction in order to decode
388 // the instruction length. Swap the bytes.
389 x = ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8);
390 #endif
391 *reinterpret_cast<uint16_t*>(pc_) = x;
392 pc_ += 2;
393 }
394
395 // Helper to emit the binary encoding of a 4 byte instruction
emit4bytes(uint32_t x)396 void Assembler::emit4bytes(uint32_t x) {
397 CheckBuffer();
398 #if V8_TARGET_LITTLE_ENDIAN
399 // We need to emit instructions in big endian format as disassembler /
400 // simulator require the first byte of the instruction in order to decode
401 // the instruction length. Swap the bytes.
402 x = ((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) |
403 ((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24);
404 #endif
405 *reinterpret_cast<uint32_t*>(pc_) = x;
406 pc_ += 4;
407 }
408
409 // Helper to emit the binary encoding of a 6 byte instruction
emit6bytes(uint64_t x)410 void Assembler::emit6bytes(uint64_t x) {
411 CheckBuffer();
412 #if V8_TARGET_LITTLE_ENDIAN
413 // We need to emit instructions in big endian format as disassembler /
414 // simulator require the first byte of the instruction in order to decode
415 // the instruction length. Swap the bytes.
416 x = (static_cast<uint64_t>(x & 0xFF) << 40) |
417 (static_cast<uint64_t>((x >> 8) & 0xFF) << 32) |
418 (static_cast<uint64_t>((x >> 16) & 0xFF) << 24) |
419 (static_cast<uint64_t>((x >> 24) & 0xFF) << 16) |
420 (static_cast<uint64_t>((x >> 32) & 0xFF) << 8) |
421 (static_cast<uint64_t>((x >> 40) & 0xFF));
422 x |= (*reinterpret_cast<uint64_t*>(pc_) >> 48) << 48;
423 #else
424 // We need to pad two bytes of zeros in order to get the 6-bytes
425 // stored from low address.
426 x = x << 16;
427 x |= *reinterpret_cast<uint64_t*>(pc_) & 0xFFFF;
428 #endif
429 // It is safe to store 8-bytes, as CheckBuffer() guarantees we have kGap
430 // space left over.
431 *reinterpret_cast<uint64_t*>(pc_) = x;
432 pc_ += 6;
433 }
434
is_reg()435 bool Operand::is_reg() const { return rm_.is_valid(); }
436
437 // Fetch the 32bit value from the FIXED_SEQUENCE IIHF / IILF
target_address_at(Address pc,Address constant_pool)438 Address Assembler::target_address_at(Address pc, Address constant_pool) {
439 // S390 Instruction!
440 // We want to check for instructions generated by Asm::mov()
441 Opcode op1 = Instruction::S390OpcodeValue(reinterpret_cast<const byte*>(pc));
442 SixByteInstr instr_1 =
443 Instruction::InstructionBits(reinterpret_cast<const byte*>(pc));
444
445 if (BRASL == op1 || BRCL == op1) {
446 int32_t dis = static_cast<int32_t>(instr_1 & 0xFFFFFFFF) * 2;
447 return reinterpret_cast<Address>(reinterpret_cast<uint64_t>(pc) + dis);
448 }
449
450 #if V8_TARGET_ARCH_S390X
451 int instr1_length =
452 Instruction::InstructionLength(reinterpret_cast<const byte*>(pc));
453 Opcode op2 = Instruction::S390OpcodeValue(
454 reinterpret_cast<const byte*>(pc + instr1_length));
455 SixByteInstr instr_2 = Instruction::InstructionBits(
456 reinterpret_cast<const byte*>(pc + instr1_length));
457 // IIHF for hi_32, IILF for lo_32
458 if (IIHF == op1 && IILF == op2) {
459 return reinterpret_cast<Address>(((instr_1 & 0xFFFFFFFF) << 32) |
460 ((instr_2 & 0xFFFFFFFF)));
461 }
462 #else
463 // IILF loads 32-bits
464 if (IILF == op1 || CFI == op1) {
465 return reinterpret_cast<Address>((instr_1 & 0xFFFFFFFF));
466 }
467 #endif
468
469 UNIMPLEMENTED();
470 return (Address)0;
471 }
472
473 // This sets the branch destination (which gets loaded at the call address).
474 // This is for calls and branches within generated code. The serializer
475 // has already deserialized the mov instructions etc.
476 // There is a FIXED_SEQUENCE assumption here
deserialization_set_special_target_at(Isolate * isolate,Address instruction_payload,Code * code,Address target)477 void Assembler::deserialization_set_special_target_at(
478 Isolate* isolate, Address instruction_payload, Code* code, Address target) {
479 set_target_address_at(isolate, instruction_payload, code, target);
480 }
481
deserialization_set_target_internal_reference_at(Isolate * isolate,Address pc,Address target,RelocInfo::Mode mode)482 void Assembler::deserialization_set_target_internal_reference_at(
483 Isolate* isolate, Address pc, Address target, RelocInfo::Mode mode) {
484 if (RelocInfo::IsInternalReferenceEncoded(mode)) {
485 Code* code = NULL;
486 set_target_address_at(isolate, pc, code, target, SKIP_ICACHE_FLUSH);
487 } else {
488 Memory::Address_at(pc) = target;
489 }
490 }
491
492 // This code assumes the FIXED_SEQUENCE of IIHF/IILF
set_target_address_at(Isolate * isolate,Address pc,Address constant_pool,Address target,ICacheFlushMode icache_flush_mode)493 void Assembler::set_target_address_at(Isolate* isolate, Address pc,
494 Address constant_pool, Address target,
495 ICacheFlushMode icache_flush_mode) {
496 // Check for instructions generated by Asm::mov()
497 Opcode op1 = Instruction::S390OpcodeValue(reinterpret_cast<const byte*>(pc));
498 SixByteInstr instr_1 =
499 Instruction::InstructionBits(reinterpret_cast<const byte*>(pc));
500 bool patched = false;
501
502 if (BRASL == op1 || BRCL == op1) {
503 instr_1 >>= 32; // Zero out the lower 32-bits
504 instr_1 <<= 32;
505 int32_t halfwords = (target - pc) / 2; // number of halfwords
506 instr_1 |= static_cast<uint32_t>(halfwords);
507 Instruction::SetInstructionBits<SixByteInstr>(reinterpret_cast<byte*>(pc),
508 instr_1);
509 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
510 Assembler::FlushICache(isolate, pc, 6);
511 }
512 patched = true;
513 } else {
514 #if V8_TARGET_ARCH_S390X
515 int instr1_length =
516 Instruction::InstructionLength(reinterpret_cast<const byte*>(pc));
517 Opcode op2 = Instruction::S390OpcodeValue(
518 reinterpret_cast<const byte*>(pc + instr1_length));
519 SixByteInstr instr_2 = Instruction::InstructionBits(
520 reinterpret_cast<const byte*>(pc + instr1_length));
521 // IIHF for hi_32, IILF for lo_32
522 if (IIHF == op1 && IILF == op2) {
523 // IIHF
524 instr_1 >>= 32; // Zero out the lower 32-bits
525 instr_1 <<= 32;
526 instr_1 |= reinterpret_cast<uint64_t>(target) >> 32;
527
528 Instruction::SetInstructionBits<SixByteInstr>(reinterpret_cast<byte*>(pc),
529 instr_1);
530
531 // IILF
532 instr_2 >>= 32;
533 instr_2 <<= 32;
534 instr_2 |= reinterpret_cast<uint64_t>(target) & 0xFFFFFFFF;
535
536 Instruction::SetInstructionBits<SixByteInstr>(
537 reinterpret_cast<byte*>(pc + instr1_length), instr_2);
538 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
539 Assembler::FlushICache(isolate, pc, 12);
540 }
541 patched = true;
542 }
543 #else
544 // IILF loads 32-bits
545 if (IILF == op1 || CFI == op1) {
546 instr_1 >>= 32; // Zero out the lower 32-bits
547 instr_1 <<= 32;
548 instr_1 |= reinterpret_cast<uint32_t>(target);
549
550 Instruction::SetInstructionBits<SixByteInstr>(reinterpret_cast<byte*>(pc),
551 instr_1);
552 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
553 Assembler::FlushICache(isolate, pc, 6);
554 }
555 patched = true;
556 }
557 #endif
558 }
559 if (!patched) UNREACHABLE();
560 }
561
562 } // namespace internal
563 } // namespace v8
564
565 #endif // V8_S390_ASSEMBLER_S390_INL_H_
566