| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 1000 |
| 1001 int Simulator::ReadW(int32_t addr, Instruction* instr) { | 1001 int Simulator::ReadW(int32_t addr, Instruction* instr) { |
| 1002 #if V8_TARGET_CAN_READ_UNALIGNED | 1002 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1003 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); | 1003 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1004 return *ptr; | 1004 return *ptr; |
| 1005 #else | 1005 #else |
| 1006 if ((addr & 3) == 0) { | 1006 if ((addr & 3) == 0) { |
| 1007 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); | 1007 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1008 return *ptr; | 1008 return *ptr; |
| 1009 } | 1009 } |
| 1010 PrintF("Unaligned read at 0x%08x, pc=%p\n", addr, instr); | 1010 PrintF("Unaligned read at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1011 addr, |
| 1012 reinterpret_cast<intptr_t>(instr)); |
| 1011 UNIMPLEMENTED(); | 1013 UNIMPLEMENTED(); |
| 1012 return 0; | 1014 return 0; |
| 1013 #endif | 1015 #endif |
| 1014 } | 1016 } |
| 1015 | 1017 |
| 1016 | 1018 |
| 1017 void Simulator::WriteW(int32_t addr, int value, Instruction* instr) { | 1019 void Simulator::WriteW(int32_t addr, int value, Instruction* instr) { |
| 1018 #if V8_TARGET_CAN_READ_UNALIGNED | 1020 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1019 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); | 1021 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1020 *ptr = value; | 1022 *ptr = value; |
| 1021 return; | 1023 return; |
| 1022 #else | 1024 #else |
| 1023 if ((addr & 3) == 0) { | 1025 if ((addr & 3) == 0) { |
| 1024 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); | 1026 intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1025 *ptr = value; | 1027 *ptr = value; |
| 1026 return; | 1028 return; |
| 1027 } | 1029 } |
| 1028 PrintF("Unaligned write at 0x%08x, pc=%p\n", addr, instr); | 1030 PrintF("Unaligned write at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1031 addr, |
| 1032 reinterpret_cast<intptr_t>(instr)); |
| 1029 UNIMPLEMENTED(); | 1033 UNIMPLEMENTED(); |
| 1030 #endif | 1034 #endif |
| 1031 } | 1035 } |
| 1032 | 1036 |
| 1033 | 1037 |
| 1034 uint16_t Simulator::ReadHU(int32_t addr, Instruction* instr) { | 1038 uint16_t Simulator::ReadHU(int32_t addr, Instruction* instr) { |
| 1035 #if V8_TARGET_CAN_READ_UNALIGNED | 1039 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1036 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); | 1040 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1037 return *ptr; | 1041 return *ptr; |
| 1038 #else | 1042 #else |
| 1039 if ((addr & 1) == 0) { | 1043 if ((addr & 1) == 0) { |
| 1040 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); | 1044 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1041 return *ptr; | 1045 return *ptr; |
| 1042 } | 1046 } |
| 1043 PrintF("Unaligned unsigned halfword read at 0x%08x, pc=%p\n", addr, instr); | 1047 PrintF("Unaligned unsigned halfword read at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1048 addr, |
| 1049 reinterpret_cast<intptr_t>(instr)); |
| 1044 UNIMPLEMENTED(); | 1050 UNIMPLEMENTED(); |
| 1045 return 0; | 1051 return 0; |
| 1046 #endif | 1052 #endif |
| 1047 } | 1053 } |
| 1048 | 1054 |
| 1049 | 1055 |
| 1050 int16_t Simulator::ReadH(int32_t addr, Instruction* instr) { | 1056 int16_t Simulator::ReadH(int32_t addr, Instruction* instr) { |
| 1051 #if V8_TARGET_CAN_READ_UNALIGNED | 1057 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1052 int16_t* ptr = reinterpret_cast<int16_t*>(addr); | 1058 int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
| 1053 return *ptr; | 1059 return *ptr; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1067 #if V8_TARGET_CAN_READ_UNALIGNED | 1073 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1068 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); | 1074 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1069 *ptr = value; | 1075 *ptr = value; |
| 1070 return; | 1076 return; |
| 1071 #else | 1077 #else |
| 1072 if ((addr & 1) == 0) { | 1078 if ((addr & 1) == 0) { |
| 1073 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); | 1079 uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1074 *ptr = value; | 1080 *ptr = value; |
| 1075 return; | 1081 return; |
| 1076 } | 1082 } |
| 1077 PrintF("Unaligned unsigned halfword write at 0x%08x, pc=%p\n", addr, instr); | 1083 PrintF("Unaligned unsigned halfword write at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1084 addr, |
| 1085 reinterpret_cast<intptr_t>(instr)); |
| 1078 UNIMPLEMENTED(); | 1086 UNIMPLEMENTED(); |
| 1079 #endif | 1087 #endif |
| 1080 } | 1088 } |
| 1081 | 1089 |
| 1082 | 1090 |
| 1083 void Simulator::WriteH(int32_t addr, int16_t value, Instruction* instr) { | 1091 void Simulator::WriteH(int32_t addr, int16_t value, Instruction* instr) { |
| 1084 #if V8_TARGET_CAN_READ_UNALIGNED | 1092 #if V8_TARGET_CAN_READ_UNALIGNED |
| 1085 int16_t* ptr = reinterpret_cast<int16_t*>(addr); | 1093 int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
| 1086 *ptr = value; | 1094 *ptr = value; |
| 1087 return; | 1095 return; |
| 1088 #else | 1096 #else |
| 1089 if ((addr & 1) == 0) { | 1097 if ((addr & 1) == 0) { |
| 1090 int16_t* ptr = reinterpret_cast<int16_t*>(addr); | 1098 int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
| 1091 *ptr = value; | 1099 *ptr = value; |
| 1092 return; | 1100 return; |
| 1093 } | 1101 } |
| 1094 PrintF("Unaligned halfword write at 0x%08x, pc=%p\n", addr, instr); | 1102 PrintF("Unaligned halfword write at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1103 addr, |
| 1104 reinterpret_cast<intptr_t>(instr)); |
| 1095 UNIMPLEMENTED(); | 1105 UNIMPLEMENTED(); |
| 1096 #endif | 1106 #endif |
| 1097 } | 1107 } |
| 1098 | 1108 |
| 1099 | 1109 |
| 1100 uint8_t Simulator::ReadBU(int32_t addr) { | 1110 uint8_t Simulator::ReadBU(int32_t addr) { |
| 1101 uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); | 1111 uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); |
| 1102 return *ptr; | 1112 return *ptr; |
| 1103 } | 1113 } |
| 1104 | 1114 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 int32_t arg2, | 1536 int32_t arg2, |
| 1527 int32_t arg3, | 1537 int32_t arg3, |
| 1528 int32_t arg4); | 1538 int32_t arg4); |
| 1529 typedef double (*SimulatorRuntimeFPCall)(int32_t arg0, | 1539 typedef double (*SimulatorRuntimeFPCall)(int32_t arg0, |
| 1530 int32_t arg1, | 1540 int32_t arg1, |
| 1531 int32_t arg2, | 1541 int32_t arg2, |
| 1532 int32_t arg3); | 1542 int32_t arg3); |
| 1533 | 1543 |
| 1534 // This signature supports direct call in to API function native callback | 1544 // This signature supports direct call in to API function native callback |
| 1535 // (refer to InvocationCallback in v8.h). | 1545 // (refer to InvocationCallback in v8.h). |
| 1536 typedef v8::Handle<v8::Value> (*SimulatorRuntimeApiCall)(int32_t arg0); | 1546 typedef v8::Handle<v8::Value> (*SimulatorRuntimeDirectApiCall)(int32_t arg0); |
| 1547 |
| 1548 // This signature supports direct call to accessor getter callback. |
| 1549 typedef v8::Handle<v8::Value> (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, |
| 1550 int32_t arg1); |
| 1537 | 1551 |
| 1538 // Software interrupt instructions are used by the simulator to call into the | 1552 // Software interrupt instructions are used by the simulator to call into the |
| 1539 // C-based V8 runtime. | 1553 // C-based V8 runtime. |
| 1540 void Simulator::SoftwareInterrupt(Instruction* instr) { | 1554 void Simulator::SoftwareInterrupt(Instruction* instr) { |
| 1541 int svc = instr->SvcValue(); | 1555 int svc = instr->SvcValue(); |
| 1542 switch (svc) { | 1556 switch (svc) { |
| 1543 case kCallRtRedirected: { | 1557 case kCallRtRedirected: { |
| 1544 // Check if stack is aligned. Error if not aligned is reported below to | 1558 // Check if stack is aligned. Error if not aligned is reported below to |
| 1545 // include information on the function called. | 1559 // include information on the function called. |
| 1546 bool stack_aligned = | 1560 bool stack_aligned = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1567 PrintF("Call to host function at %p with args %f, %f", | 1581 PrintF("Call to host function at %p with args %f, %f", |
| 1568 FUNCTION_ADDR(target), x, y); | 1582 FUNCTION_ADDR(target), x, y); |
| 1569 if (!stack_aligned) { | 1583 if (!stack_aligned) { |
| 1570 PrintF(" with unaligned stack %08x\n", get_register(sp)); | 1584 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1571 } | 1585 } |
| 1572 PrintF("\n"); | 1586 PrintF("\n"); |
| 1573 } | 1587 } |
| 1574 CHECK(stack_aligned); | 1588 CHECK(stack_aligned); |
| 1575 double result = target(arg0, arg1, arg2, arg3); | 1589 double result = target(arg0, arg1, arg2, arg3); |
| 1576 SetFpResult(result); | 1590 SetFpResult(result); |
| 1577 } else if (redirection->type() == ExternalReference::DIRECT_CALL) { | 1591 } else if (redirection->type() == ExternalReference::DIRECT_API_CALL) { |
| 1578 SimulatorRuntimeApiCall target = | 1592 SimulatorRuntimeDirectApiCall target = |
| 1579 reinterpret_cast<SimulatorRuntimeApiCall>(external); | 1593 reinterpret_cast<SimulatorRuntimeDirectApiCall>(external); |
| 1580 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { | 1594 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1581 PrintF( | 1595 PrintF("Call to host function at %p args %08x", |
| 1582 "Call to host function at %p args %08x", | 1596 FUNCTION_ADDR(target), arg0); |
| 1583 FUNCTION_ADDR(target), | |
| 1584 arg0); | |
| 1585 if (!stack_aligned) { | 1597 if (!stack_aligned) { |
| 1586 PrintF(" with unaligned stack %08x\n", get_register(sp)); | 1598 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1587 } | 1599 } |
| 1588 PrintF("\n"); | 1600 PrintF("\n"); |
| 1589 } | 1601 } |
| 1590 CHECK(stack_aligned); | 1602 CHECK(stack_aligned); |
| 1591 v8::Handle<v8::Value> result = target(arg0); | 1603 v8::Handle<v8::Value> result = target(arg0); |
| 1592 if (::v8::internal::FLAG_trace_sim) { | 1604 if (::v8::internal::FLAG_trace_sim) { |
| 1593 PrintF("Returned %p\n", reinterpret_cast<void *>(*result)); | 1605 PrintF("Returned %p\n", reinterpret_cast<void *>(*result)); |
| 1594 } | 1606 } |
| 1595 set_register(r0, (int32_t) *result); | 1607 set_register(r0, (int32_t) *result); |
| 1608 } else if (redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { |
| 1609 SimulatorRuntimeDirectGetterCall target = |
| 1610 reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); |
| 1611 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1612 PrintF("Call to host function at %p args %08x %08x", |
| 1613 FUNCTION_ADDR(target), arg0, arg1); |
| 1614 if (!stack_aligned) { |
| 1615 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1616 } |
| 1617 PrintF("\n"); |
| 1618 } |
| 1619 CHECK(stack_aligned); |
| 1620 v8::Handle<v8::Value> result = target(arg0, arg1); |
| 1621 if (::v8::internal::FLAG_trace_sim) { |
| 1622 PrintF("Returned %p\n", reinterpret_cast<void *>(*result)); |
| 1623 } |
| 1624 set_register(r0, (int32_t) *result); |
| 1596 } else { | 1625 } else { |
| 1597 // builtin call. | 1626 // builtin call. |
| 1598 ASSERT(redirection->type() == ExternalReference::BUILTIN_CALL); | 1627 ASSERT(redirection->type() == ExternalReference::BUILTIN_CALL); |
| 1599 SimulatorRuntimeCall target = | 1628 SimulatorRuntimeCall target = |
| 1600 reinterpret_cast<SimulatorRuntimeCall>(external); | 1629 reinterpret_cast<SimulatorRuntimeCall>(external); |
| 1601 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { | 1630 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1602 PrintF( | 1631 PrintF( |
| 1603 "Call to host function at %p args %08x, %08x, %08x, %08x, %0xc", | 1632 "Call to host function at %p args %08x, %08x, %08x, %08x, %0xc", |
| 1604 FUNCTION_ADDR(target), | 1633 FUNCTION_ADDR(target), |
| 1605 arg0, | 1634 arg0, |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 set_d_register_from_double(vd, dd_value); | 2559 set_d_register_from_double(vd, dd_value); |
| 2531 } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) { | 2560 } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) { |
| 2532 // vdiv | 2561 // vdiv |
| 2533 if (instr->SzValue() != 0x1) { | 2562 if (instr->SzValue() != 0x1) { |
| 2534 UNREACHABLE(); // Not used by V8. | 2563 UNREACHABLE(); // Not used by V8. |
| 2535 } | 2564 } |
| 2536 | 2565 |
| 2537 double dn_value = get_double_from_d_register(vn); | 2566 double dn_value = get_double_from_d_register(vn); |
| 2538 double dm_value = get_double_from_d_register(vm); | 2567 double dm_value = get_double_from_d_register(vm); |
| 2539 double dd_value = dn_value / dm_value; | 2568 double dd_value = dn_value / dm_value; |
| 2569 div_zero_vfp_flag_ = (dm_value == 0); |
| 2540 set_d_register_from_double(vd, dd_value); | 2570 set_d_register_from_double(vd, dd_value); |
| 2541 } else { | 2571 } else { |
| 2542 UNIMPLEMENTED(); // Not used by V8. | 2572 UNIMPLEMENTED(); // Not used by V8. |
| 2543 } | 2573 } |
| 2544 } else { | 2574 } else { |
| 2545 if ((instr->VCValue() == 0x0) && | 2575 if ((instr->VCValue() == 0x0) && |
| 2546 (instr->VAValue() == 0x0)) { | 2576 (instr->VAValue() == 0x0)) { |
| 2547 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr); | 2577 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr); |
| 2548 } else if ((instr->VLValue() == 0x1) && | 2578 } else if ((instr->VLValue() == 0x1) && |
| 2549 (instr->VCValue() == 0x0) && | 2579 (instr->VCValue() == 0x0) && |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2764 bool double_precision = (src_precision == kDoublePrecision); | 2794 bool double_precision = (src_precision == kDoublePrecision); |
| 2765 | 2795 |
| 2766 double val = double_precision ? get_double_from_d_register(src) | 2796 double val = double_precision ? get_double_from_d_register(src) |
| 2767 : get_float_from_s_register(src); | 2797 : get_float_from_s_register(src); |
| 2768 | 2798 |
| 2769 int temp = unsigned_integer ? static_cast<uint32_t>(val) | 2799 int temp = unsigned_integer ? static_cast<uint32_t>(val) |
| 2770 : static_cast<int32_t>(val); | 2800 : static_cast<int32_t>(val); |
| 2771 | 2801 |
| 2772 inv_op_vfp_flag_ = get_inv_op_vfp_flag(mode, val, unsigned_integer); | 2802 inv_op_vfp_flag_ = get_inv_op_vfp_flag(mode, val, unsigned_integer); |
| 2773 | 2803 |
| 2804 double abs_diff = |
| 2805 unsigned_integer ? fabs(val - static_cast<uint32_t>(temp)) |
| 2806 : fabs(val - temp); |
| 2807 |
| 2808 inexact_vfp_flag_ = (abs_diff != 0); |
| 2809 |
| 2774 if (inv_op_vfp_flag_) { | 2810 if (inv_op_vfp_flag_) { |
| 2775 temp = VFPConversionSaturate(val, unsigned_integer); | 2811 temp = VFPConversionSaturate(val, unsigned_integer); |
| 2776 } else { | 2812 } else { |
| 2777 switch (mode) { | 2813 switch (mode) { |
| 2778 case RN: { | 2814 case RN: { |
| 2779 double abs_diff = | |
| 2780 unsigned_integer ? fabs(val - static_cast<uint32_t>(temp)) | |
| 2781 : fabs(val - temp); | |
| 2782 int val_sign = (val > 0) ? 1 : -1; | 2815 int val_sign = (val > 0) ? 1 : -1; |
| 2783 if (abs_diff > 0.5) { | 2816 if (abs_diff > 0.5) { |
| 2784 temp += val_sign; | 2817 temp += val_sign; |
| 2785 } else if (abs_diff == 0.5) { | 2818 } else if (abs_diff == 0.5) { |
| 2786 // Round to even if exactly halfway. | 2819 // Round to even if exactly halfway. |
| 2787 temp = ((temp % 2) == 0) ? temp : temp + val_sign; | 2820 temp = ((temp % 2) == 0) ? temp : temp + val_sign; |
| 2788 } | 2821 } |
| 2789 break; | 2822 break; |
| 2790 } | 2823 } |
| 2791 | 2824 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 uintptr_t address = *stack_slot; | 3158 uintptr_t address = *stack_slot; |
| 3126 set_register(sp, current_sp + sizeof(uintptr_t)); | 3159 set_register(sp, current_sp + sizeof(uintptr_t)); |
| 3127 return address; | 3160 return address; |
| 3128 } | 3161 } |
| 3129 | 3162 |
| 3130 } } // namespace v8::internal | 3163 } } // namespace v8::internal |
| 3131 | 3164 |
| 3132 #endif // USE_SIMULATOR | 3165 #endif // USE_SIMULATOR |
| 3133 | 3166 |
| 3134 #endif // V8_TARGET_ARCH_ARM | 3167 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |