| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 registers_[ra] = bad_ra; | 918 registers_[ra] = bad_ra; |
| 919 InitializeCoverage(); | 919 InitializeCoverage(); |
| 920 for (int i = 0; i < kNumExceptions; i++) { | 920 for (int i = 0; i < kNumExceptions; i++) { |
| 921 exceptions[i] = 0; | 921 exceptions[i] = 0; |
| 922 } | 922 } |
| 923 | 923 |
| 924 last_debugger_input_ = NULL; | 924 last_debugger_input_ = NULL; |
| 925 } | 925 } |
| 926 | 926 |
| 927 | 927 |
| 928 Simulator::~Simulator() { |
| 929 } |
| 930 |
| 931 |
| 928 // When the generated code calls an external reference we need to catch that in | 932 // When the generated code calls an external reference we need to catch that in |
| 929 // the simulator. The external reference will be a function compiled for the | 933 // the simulator. The external reference will be a function compiled for the |
| 930 // host architecture. We need to call that function instead of trying to | 934 // host architecture. We need to call that function instead of trying to |
| 931 // execute it with the simulator. We do that by redirecting the external | 935 // execute it with the simulator. We do that by redirecting the external |
| 932 // reference to a swi (software-interrupt) instruction that is handled by | 936 // reference to a swi (software-interrupt) instruction that is handled by |
| 933 // the simulator. We write the original destination of the jump just at a known | 937 // the simulator. We write the original destination of the jump just at a known |
| 934 // offset from the swi instruction so the simulator knows what to call. | 938 // offset from the swi instruction so the simulator knows what to call. |
| 935 class Redirection { | 939 class Redirection { |
| 936 public: | 940 public: |
| 937 Redirection(void* external_function, ExternalReference::Type type) | 941 Redirection(void* external_function, ExternalReference::Type type) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 965 return new Redirection(external_function, type); | 969 return new Redirection(external_function, type); |
| 966 } | 970 } |
| 967 | 971 |
| 968 static Redirection* FromSwiInstruction(Instruction* swi_instruction) { | 972 static Redirection* FromSwiInstruction(Instruction* swi_instruction) { |
| 969 char* addr_of_swi = reinterpret_cast<char*>(swi_instruction); | 973 char* addr_of_swi = reinterpret_cast<char*>(swi_instruction); |
| 970 char* addr_of_redirection = | 974 char* addr_of_redirection = |
| 971 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); | 975 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); |
| 972 return reinterpret_cast<Redirection*>(addr_of_redirection); | 976 return reinterpret_cast<Redirection*>(addr_of_redirection); |
| 973 } | 977 } |
| 974 | 978 |
| 979 static void* ReverseRedirection(int32_t reg) { |
| 980 Redirection* redirection = FromSwiInstruction( |
| 981 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); |
| 982 return redirection->external_function(); |
| 983 } |
| 984 |
| 975 private: | 985 private: |
| 976 void* external_function_; | 986 void* external_function_; |
| 977 uint32_t swi_instruction_; | 987 uint32_t swi_instruction_; |
| 978 ExternalReference::Type type_; | 988 ExternalReference::Type type_; |
| 979 Redirection* next_; | 989 Redirection* next_; |
| 980 }; | 990 }; |
| 981 | 991 |
| 982 | 992 |
| 983 void* Simulator::RedirectExternalReference(void* external_function, | 993 void* Simulator::RedirectExternalReference(void* external_function, |
| 984 ExternalReference::Type type) { | 994 ExternalReference::Type type) { |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 | 1392 |
| 1383 // These prototypes handle the four types of FP calls. | 1393 // These prototypes handle the four types of FP calls. |
| 1384 typedef int64_t (*SimulatorRuntimeCompareCall)(double darg0, double darg1); | 1394 typedef int64_t (*SimulatorRuntimeCompareCall)(double darg0, double darg1); |
| 1385 typedef double (*SimulatorRuntimeFPFPCall)(double darg0, double darg1); | 1395 typedef double (*SimulatorRuntimeFPFPCall)(double darg0, double darg1); |
| 1386 typedef double (*SimulatorRuntimeFPCall)(double darg0); | 1396 typedef double (*SimulatorRuntimeFPCall)(double darg0); |
| 1387 typedef double (*SimulatorRuntimeFPIntCall)(double darg0, int32_t arg0); | 1397 typedef double (*SimulatorRuntimeFPIntCall)(double darg0, int32_t arg0); |
| 1388 | 1398 |
| 1389 // This signature supports direct call in to API function native callback | 1399 // This signature supports direct call in to API function native callback |
| 1390 // (refer to InvocationCallback in v8.h). | 1400 // (refer to InvocationCallback in v8.h). |
| 1391 typedef void (*SimulatorRuntimeDirectApiCall)(int32_t arg0); | 1401 typedef void (*SimulatorRuntimeDirectApiCall)(int32_t arg0); |
| 1392 typedef void (*SimulatorRuntimeProfilingApiCall)(int32_t arg0, int32_t arg1); | 1402 typedef void (*SimulatorRuntimeProfilingApiCall)(int32_t arg0, void* arg1); |
| 1393 | 1403 |
| 1394 // This signature supports direct call to accessor getter callback. | 1404 // This signature supports direct call to accessor getter callback. |
| 1395 typedef void (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, int32_t arg1); | 1405 typedef void (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, int32_t arg1); |
| 1396 typedef void (*SimulatorRuntimeProfilingGetterCall)( | 1406 typedef void (*SimulatorRuntimeProfilingGetterCall)( |
| 1397 int32_t arg0, int32_t arg1, int32_t arg2); | 1407 int32_t arg0, int32_t arg1, void* arg2); |
| 1398 | 1408 |
| 1399 // Software interrupt instructions are used by the simulator to call into the | 1409 // Software interrupt instructions are used by the simulator to call into the |
| 1400 // C-based V8 runtime. They are also used for debugging with simulator. | 1410 // C-based V8 runtime. They are also used for debugging with simulator. |
| 1401 void Simulator::SoftwareInterrupt(Instruction* instr) { | 1411 void Simulator::SoftwareInterrupt(Instruction* instr) { |
| 1402 // There are several instructions that could get us here, | 1412 // There are several instructions that could get us here, |
| 1403 // the break_ instruction, or several variants of traps. All | 1413 // the break_ instruction, or several variants of traps. All |
| 1404 // Are "SPECIAL" class opcode, and are distinuished by function. | 1414 // Are "SPECIAL" class opcode, and are distinuished by function. |
| 1405 int32_t func = instr->FunctionFieldRaw(); | 1415 int32_t func = instr->FunctionFieldRaw(); |
| 1406 uint32_t code = (func == BREAK) ? instr->Bits(25, 6) : -1; | 1416 uint32_t code = (func == BREAK) ? instr->Bits(25, 6) : -1; |
| 1407 | 1417 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 reinterpret_cast<SimulatorRuntimeDirectApiCall>(external); | 1558 reinterpret_cast<SimulatorRuntimeDirectApiCall>(external); |
| 1549 target(arg0); | 1559 target(arg0); |
| 1550 } else if ( | 1560 } else if ( |
| 1551 redirection->type() == ExternalReference::PROFILING_API_CALL) { | 1561 redirection->type() == ExternalReference::PROFILING_API_CALL) { |
| 1552 if (::v8::internal::FLAG_trace_sim) { | 1562 if (::v8::internal::FLAG_trace_sim) { |
| 1553 PrintF("Call to host function at %p args %08x %08x\n", | 1563 PrintF("Call to host function at %p args %08x %08x\n", |
| 1554 reinterpret_cast<void*>(external), arg0, arg1); | 1564 reinterpret_cast<void*>(external), arg0, arg1); |
| 1555 } | 1565 } |
| 1556 SimulatorRuntimeProfilingApiCall target = | 1566 SimulatorRuntimeProfilingApiCall target = |
| 1557 reinterpret_cast<SimulatorRuntimeProfilingApiCall>(external); | 1567 reinterpret_cast<SimulatorRuntimeProfilingApiCall>(external); |
| 1558 target(arg0, arg1); | 1568 target(arg0, Redirection::ReverseRedirection(arg1)); |
| 1559 } else if ( | 1569 } else if ( |
| 1560 redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { | 1570 redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { |
| 1561 if (::v8::internal::FLAG_trace_sim) { | 1571 if (::v8::internal::FLAG_trace_sim) { |
| 1562 PrintF("Call to host function at %p args %08x %08x\n", | 1572 PrintF("Call to host function at %p args %08x %08x\n", |
| 1563 reinterpret_cast<void*>(external), arg0, arg1); | 1573 reinterpret_cast<void*>(external), arg0, arg1); |
| 1564 } | 1574 } |
| 1565 SimulatorRuntimeDirectGetterCall target = | 1575 SimulatorRuntimeDirectGetterCall target = |
| 1566 reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); | 1576 reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); |
| 1567 target(arg0, arg1); | 1577 target(arg0, arg1); |
| 1568 } else if ( | 1578 } else if ( |
| 1569 redirection->type() == ExternalReference::PROFILING_GETTER_CALL) { | 1579 redirection->type() == ExternalReference::PROFILING_GETTER_CALL) { |
| 1570 if (::v8::internal::FLAG_trace_sim) { | 1580 if (::v8::internal::FLAG_trace_sim) { |
| 1571 PrintF("Call to host function at %p args %08x %08x %08x\n", | 1581 PrintF("Call to host function at %p args %08x %08x %08x\n", |
| 1572 reinterpret_cast<void*>(external), arg0, arg1, arg2); | 1582 reinterpret_cast<void*>(external), arg0, arg1, arg2); |
| 1573 } | 1583 } |
| 1574 SimulatorRuntimeProfilingGetterCall target = | 1584 SimulatorRuntimeProfilingGetterCall target = |
| 1575 reinterpret_cast<SimulatorRuntimeProfilingGetterCall>(external); | 1585 reinterpret_cast<SimulatorRuntimeProfilingGetterCall>(external); |
| 1576 target(arg0, arg1, arg2); | 1586 target(arg0, arg1, Redirection::ReverseRedirection(arg2)); |
| 1577 } else { | 1587 } else { |
| 1578 SimulatorRuntimeCall target = | 1588 SimulatorRuntimeCall target = |
| 1579 reinterpret_cast<SimulatorRuntimeCall>(external); | 1589 reinterpret_cast<SimulatorRuntimeCall>(external); |
| 1580 if (::v8::internal::FLAG_trace_sim) { | 1590 if (::v8::internal::FLAG_trace_sim) { |
| 1581 PrintF( | 1591 PrintF( |
| 1582 "Call to host function at %p " | 1592 "Call to host function at %p " |
| 1583 "args %08x, %08x, %08x, %08x, %08x, %08x\n", | 1593 "args %08x, %08x, %08x, %08x, %08x, %08x\n", |
| 1584 FUNCTION_ADDR(target), | 1594 FUNCTION_ADDR(target), |
| 1585 arg0, | 1595 arg0, |
| 1586 arg1, | 1596 arg1, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 default: | 1923 default: |
| 1914 UNREACHABLE(); | 1924 UNREACHABLE(); |
| 1915 }; | 1925 }; |
| 1916 break; | 1926 break; |
| 1917 case SPECIAL2: | 1927 case SPECIAL2: |
| 1918 switch (instr->FunctionFieldRaw()) { | 1928 switch (instr->FunctionFieldRaw()) { |
| 1919 case MUL: | 1929 case MUL: |
| 1920 alu_out = rs_u * rt_u; // Only the lower 32 bits are kept. | 1930 alu_out = rs_u * rt_u; // Only the lower 32 bits are kept. |
| 1921 break; | 1931 break; |
| 1922 case CLZ: | 1932 case CLZ: |
| 1923 alu_out = __builtin_clz(rs_u); | 1933 // MIPS32 spec: If no bits were set in GPR rs, the result written to |
| 1934 // GPR rd is 32. |
| 1935 // GCC __builtin_clz: If input is 0, the result is undefined. |
| 1936 alu_out = |
| 1937 rs_u == 0 ? 32 : CompilerIntrinsics::CountLeadingZeros(rs_u); |
| 1924 break; | 1938 break; |
| 1925 default: | 1939 default: |
| 1926 UNREACHABLE(); | 1940 UNREACHABLE(); |
| 1927 }; | 1941 }; |
| 1928 break; | 1942 break; |
| 1929 case SPECIAL3: | 1943 case SPECIAL3: |
| 1930 switch (instr->FunctionFieldRaw()) { | 1944 switch (instr->FunctionFieldRaw()) { |
| 1931 case INS: { // Mips32r2 instruction. | 1945 case INS: { // Mips32r2 instruction. |
| 1932 // Interpret rd field as 5-bit msb of insert. | 1946 // Interpret rd field as 5-bit msb of insert. |
| 1933 uint16_t msb = rd_reg; | 1947 uint16_t msb = rd_reg; |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2928 } | 2942 } |
| 2929 | 2943 |
| 2930 | 2944 |
| 2931 #undef UNSUPPORTED | 2945 #undef UNSUPPORTED |
| 2932 | 2946 |
| 2933 } } // namespace v8::internal | 2947 } } // namespace v8::internal |
| 2934 | 2948 |
| 2935 #endif // USE_SIMULATOR | 2949 #endif // USE_SIMULATOR |
| 2936 | 2950 |
| 2937 #endif // V8_TARGET_ARCH_MIPS | 2951 #endif // V8_TARGET_ARCH_MIPS |
| OLD | NEW |