Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Unified Diff: src/s390/simulator-s390.h

Issue 1725243004: S390: Initial impl of S390 asm, masm, code-stubs,... (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Updated BUILD.gn + cpu-s390.cc to addr @jochen's comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/s390/simulator-s390.h
diff --git a/src/ppc/simulator-ppc.h b/src/s390/simulator-s390.h
similarity index 73%
copy from src/ppc/simulator-ppc.h
copy to src/s390/simulator-s390.h
index a3b03dc5062880a5d75e30b60e29c01b989534d2..1da49ed279189436bd95824fccdd7260e6e719dd 100644
--- a/src/ppc/simulator-ppc.h
+++ b/src/s390/simulator-s390.h
@@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
-// Declares a Simulator for PPC instructions if we are not generating a native
-// PPC binary. This Simulator allows us to run and debug PPC code generation on
-// regular desktop machines.
+// Declares a Simulator for S390 instructions if we are not generating a native
+// S390 binary. This Simulator allows us to run and debug S390 code generation
+// on regular desktop machines.
// V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro,
// which will start execution in the Simulator or forwards to the real entry
-// on a PPC HW platform.
+// on a S390 hardware platform.
-#ifndef V8_PPC_SIMULATOR_PPC_H_
-#define V8_PPC_SIMULATOR_PPC_H_
+#ifndef V8_S390_SIMULATOR_S390_H_
+#define V8_S390_SIMULATOR_S390_H_
#include "src/allocation.h"
#if !defined(USE_SIMULATOR)
-// Running without a simulator on a native ppc platform.
+// Running without a simulator on a native s390 platform.
namespace v8 {
namespace internal {
@@ -25,9 +24,8 @@ namespace internal {
#define CALL_GENERATED_CODE(isolate, entry, p0, p1, p2, p3, p4) \
(entry(p0, p1, p2, p3, p4))
-typedef int (*ppc_regexp_matcher)(String*, int, const byte*, const byte*, int*,
- int, Address, int, void*, Isolate*);
-
+typedef int (*s390_regexp_matcher)(String*, int, const byte*, const byte*, int*,
+ int, Address, int, void*, Isolate*);
// Call the generated regexp code directly. The code at the entry address
// should act as a function matching the type ppc_regexp_matcher.
@@ -35,11 +33,11 @@ typedef int (*ppc_regexp_matcher)(String*, int, const byte*, const byte*, int*,
// the return address added by the ExitFrame in native calls.
#define CALL_GENERATED_REGEXP_CODE(isolate, entry, p0, p1, p2, p3, p4, p5, p6, \
p7, p8) \
- (FUNCTION_CAST<ppc_regexp_matcher>(entry)(p0, p1, p2, p3, p4, p5, p6, p7, \
- NULL, p8))
+ (FUNCTION_CAST<s390_regexp_matcher>(entry)(p0, p1, p2, p3, p4, p5, p6, p7, \
+ NULL, p8))
// The stack limit beyond which we will throw stack overflow errors in
-// generated code. Because generated code on ppc uses the C stack, we
+// generated code. Because generated code on s390 uses the C stack, we
// just use the C stack limit.
class SimulatorStack : public v8::internal::AllStatic {
public:
@@ -67,7 +65,7 @@ class SimulatorStack : public v8::internal::AllStatic {
#include "src/assembler.h"
#include "src/hashmap.h"
-#include "src/ppc/constants-ppc.h"
+#include "src/s390/constants-s390.h"
namespace v8 {
namespace internal {
@@ -98,45 +96,33 @@ class CachePage {
char validity_map_[kValidityMapSize]; // One byte per line.
};
-
class Simulator {
public:
- friend class PPCDebugger;
+ friend class S390Debugger;
enum Register {
no_reg = -1,
r0 = 0,
- sp,
- r2,
- r3,
- r4,
- r5,
- r6,
- r7,
- r8,
- r9,
- r10,
- r11,
- r12,
- r13,
- r14,
- r15,
- r16,
- r17,
- r18,
- r19,
- r20,
- r21,
- r22,
- r23,
- r24,
- r25,
- r26,
- r27,
- r28,
- r29,
- r30,
- fp,
- kNumGPRs = 32,
+ r1 = 1,
+ r2 = 2,
+ r3 = 3,
+ r4 = 4,
+ r5 = 5,
+ r6 = 6,
+ r7 = 7,
+ r8 = 8,
+ r9 = 9,
+ r10 = 10,
+ r11 = 11,
+ r12 = 12,
+ r13 = 13,
+ r14 = 14,
+ r15 = 15,
+ fp = r11,
+ ip = r12,
+ cp = r13,
+ ra = r14,
+ sp = r15, // name aliases
+ kNumGPRs = 16,
d0 = 0,
d1,
d2,
@@ -153,23 +139,7 @@ class Simulator {
d13,
d14,
d15,
- d16,
- d17,
- d18,
- d19,
- d20,
- d21,
- d22,
- d23,
- d24,
- d25,
- d26,
- d27,
- d28,
- d29,
- d30,
- d31,
- kNumFPRs = 32
+ kNumFPRs = 16
};
explicit Simulator(Isolate* isolate);
@@ -180,13 +150,21 @@ class Simulator {
static Simulator* current(v8::internal::Isolate* isolate);
// Accessors for register state.
- void set_register(int reg, intptr_t value);
- intptr_t get_register(int reg) const;
+ void set_register(int reg, uint64_t value);
+ uint64_t get_register(int reg) const;
+ template <typename T>
+ T get_low_register(int reg) const;
+ template <typename T>
+ T get_high_register(int reg) const;
+ void set_low_register(int reg, uint32_t value);
+ void set_high_register(int reg, uint32_t value);
+
double get_double_from_register_pair(int reg);
void set_d_register_from_double(int dreg, const double dbl) {
DCHECK(dreg >= 0 && dreg < kNumFPRs);
*bit_cast<double*>(&fp_registers_[dreg]) = dbl;
}
+
double get_double_from_d_register(int dreg) {
DCHECK(dreg >= 0 && dreg < kNumFPRs);
return *bit_cast<double*>(&fp_registers_[dreg]);
@@ -200,6 +178,22 @@ class Simulator {
return fp_registers_[dreg];
}
+ void set_d_register_from_float32(int dreg, const float f) {
+ DCHECK(dreg >= 0 && dreg < kNumFPRs);
+
+ int32_t f_int = *bit_cast<int32_t*>(&f);
+ int64_t finalval = static_cast<int64_t>(f_int) << 32;
+ set_d_register(dreg, finalval);
+ }
+
+ float get_float32_from_d_register(int dreg) {
+ DCHECK(dreg >= 0 && dreg < kNumFPRs);
+
+ int64_t regval = get_d_register(dreg) >> 32;
+ int32_t regval32 = static_cast<int32_t>(regval);
+ return *bit_cast<float*>(&regval32);
+ }
+
// Special case of set_register and get_register to access the raw PC value.
void set_pc(intptr_t value);
intptr_t get_pc() const;
@@ -211,7 +205,7 @@ class Simulator {
// Accessor to the internal simulator stack area.
uintptr_t StackLimit(uintptr_t c_limit) const;
- // Executes PPC instructions until the PC reaches end_sim_pc.
+ // Executes S390 instructions until the PC reaches end_sim_pc.
void Execute();
// Call on program start.
@@ -258,8 +252,6 @@ class Simulator {
end_sim_pc = -2
};
- enum BCType { BC_OFFSET, BC_LINK_REG, BC_CTR_REG };
-
// Unsupported instructions use Format to print an error and stop execution.
void Format(Instruction* instr, const char* format);
@@ -287,6 +279,10 @@ class Simulator {
inline void IncreaseStopCounter(uint32_t bkpt_code);
void PrintStopInfo(uint32_t code);
+ // Byte Reverse
+ inline int16_t ByteReverse(int16_t hword);
+ inline int32_t ByteReverse(int32_t word);
+
// Read and write memory.
inline uint8_t ReadBU(intptr_t addr);
inline int8_t ReadB(intptr_t addr);
@@ -304,30 +300,69 @@ class Simulator {
inline void WriteW(intptr_t addr, uint32_t value, Instruction* instr);
inline void WriteW(intptr_t addr, int32_t value, Instruction* instr);
- intptr_t* ReadDW(intptr_t addr);
- void WriteDW(intptr_t addr, int64_t value);
+ inline int64_t ReadDW(intptr_t addr);
+ inline double ReadDouble(intptr_t addr);
+ inline void WriteDW(intptr_t addr, int64_t value);
+ // S390
void Trace(Instruction* instr);
- void SetCR0(intptr_t result, bool setSO = false);
- void ExecuteBranchConditional(Instruction* instr, BCType type);
- void ExecuteExt1(Instruction* instr);
- bool ExecuteExt2_10bit(Instruction* instr);
- bool ExecuteExt2_9bit_part1(Instruction* instr);
- bool ExecuteExt2_9bit_part2(Instruction* instr);
- void ExecuteExt2_5bit(Instruction* instr);
- void ExecuteExt2(Instruction* instr);
- void ExecuteExt3(Instruction* instr);
- void ExecuteExt4(Instruction* instr);
-#if V8_TARGET_ARCH_PPC64
- void ExecuteExt5(Instruction* instr);
-#endif
- void ExecuteGeneric(Instruction* instr);
-
- void SetFPSCR(int bit) { fp_condition_reg_ |= (1 << (31 - bit)); }
- void ClearFPSCR(int bit) { fp_condition_reg_ &= ~(1 << (31 - bit)); }
+ bool DecodeTwoByte(Instruction* instr);
+ bool DecodeFourByte(Instruction* instr);
+ bool DecodeFourByteArithmetic(Instruction* instr);
+ bool DecodeFourByteFloatingPoint(Instruction* instr);
+ void DecodeFourByteFloatingPointIntConversion(Instruction* instr);
+ void DecodeFourByteFloatingPointRound(Instruction* instr);
+
+ bool DecodeSixByte(Instruction* instr);
+ bool DecodeSixByteArithmetic(Instruction* instr);
+ bool S390InstructionDecode(Instruction* instr);
+
+ template <typename T>
+ void SetS390ConditionCode(T lhs, T rhs) {
+ condition_reg_ = 0;
+ if (lhs == rhs) {
+ condition_reg_ |= CC_EQ;
+ } else if (lhs < rhs) {
+ condition_reg_ |= CC_LT;
+ } else if (lhs > rhs) {
+ condition_reg_ |= CC_GT;
+ }
+
+ // We get down here only for floating point
+ // comparisons and the values are unordered
+ // i.e. NaN
+ if (condition_reg_ == 0) condition_reg_ = unordered;
+ }
+
+ bool isNaN(double value) { return (value != value); }
+
+ // Set the condition code for bitwise operations
+ // CC0 is set if value == 0.
+ // CC1 is set if value != 0.
+ // CC2/CC3 are not set.
+ template <typename T>
+ void SetS390BitWiseConditionCode(T value) {
+ condition_reg_ = 0;
+
+ if (value == 0)
+ condition_reg_ |= CC_EQ;
+ else
+ condition_reg_ |= CC_LT;
+ }
+
+ void SetS390OverflowCode(bool isOF) {
+ if (isOF) condition_reg_ = CC_OF;
+ }
+
+ bool TestConditionCode(Condition mask) {
+ // Check for unconditional branch
+ if (mask == 0xf) return true;
+
+ return (condition_reg_ & mask) != 0;
+ }
// Executes one instruction.
- void ExecuteInstruction(Instruction* instr);
+ void ExecuteInstruction(Instruction* instr, bool auto_incr_pc = true);
// ICache.
static void CheckICache(v8::internal::HashMap* i_cache, Instruction* instr);
@@ -345,27 +380,24 @@ class Simulator {
void SetFpResult(const double& result);
void TrashCallerSaveRegisters();
- void CallInternal(byte* entry);
+ void CallInternal(byte* entry, int reg_arg_count = 3);
// Architecture state.
- // Saturating instructions require a Q flag to indicate saturation.
- // There is currently no way to read the CPSR directly, and thus read the Q
- // flag, so this is left unimplemented.
- intptr_t registers_[kNumGPRs];
+ // On z9 and higher and supported Linux on z Systems platforms, all registers
+ // are 64-bit, even in 31-bit mode.
+ uint64_t registers_[kNumGPRs];
+ int64_t fp_registers_[kNumFPRs];
+
+ // Condition Code register. In S390, the last 4 bits are used.
int32_t condition_reg_;
- int32_t fp_condition_reg_;
- intptr_t special_reg_lr_;
+ // Special register to track PC.
intptr_t special_reg_pc_;
- intptr_t special_reg_ctr_;
- int32_t special_reg_xer_;
-
- int64_t fp_registers_[kNumFPRs];
// Simulator support.
char* stack_;
static const size_t stack_protection_size_ = 256 * kPointerSize;
bool pc_modified_;
- int icount_;
+ int64_t icount_;
// Debugger input.
char* last_debugger_input_;
@@ -395,9 +427,9 @@ class Simulator {
char* desc;
};
StopCountAndDesc watched_stops_[kNumOfWatchedStops];
+ void DebugStart();
};
-
// When running with the simulator transition into simulated execution at this
// point.
#define CALL_GENERATED_CODE(isolate, entry, p0, p1, p2, p3, p4) \
@@ -412,7 +444,6 @@ class Simulator {
(intptr_t)p5, (intptr_t)p6, (intptr_t)p7, \
(intptr_t)NULL, (intptr_t)p8)
-
// The simulator has its own stack. Thus it has a different stack limit from
// the C-based native code. The JS-based limit normally points near the end of
// the simulator stack. When the C-based limit is exhausted we reflect that by
@@ -434,8 +465,9 @@ class SimulatorStack : public v8::internal::AllStatic {
Simulator::current(isolate)->PopAddress();
}
};
+
} // namespace internal
} // namespace v8
#endif // !defined(USE_SIMULATOR)
-#endif // V8_PPC_SIMULATOR_PPC_H_
+#endif // V8_S390_SIMULATOR_S390_H_

Powered by Google App Engine
This is Rietveld 408576698