OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 LoadStoreHelper(instr, offset, Offset); | 1215 LoadStoreHelper(instr, offset, Offset); |
1216 } | 1216 } |
1217 | 1217 |
1218 | 1218 |
1219 void Simulator::LoadStoreHelper(Instruction* instr, | 1219 void Simulator::LoadStoreHelper(Instruction* instr, |
1220 int64_t offset, | 1220 int64_t offset, |
1221 AddrMode addrmode) { | 1221 AddrMode addrmode) { |
1222 unsigned srcdst = instr->Rt(); | 1222 unsigned srcdst = instr->Rt(); |
1223 unsigned addr_reg = instr->Rn(); | 1223 unsigned addr_reg = instr->Rn(); |
1224 uint8_t* address = LoadStoreAddress(addr_reg, offset, addrmode); | 1224 uint8_t* address = LoadStoreAddress(addr_reg, offset, addrmode); |
1225 int num_bytes = 1 << instr->SizeLS(); | |
1226 uint8_t* stack = NULL; | 1225 uint8_t* stack = NULL; |
1227 | 1226 |
1228 // Handle the writeback for stores before the store. On a CPU the writeback | 1227 // Handle the writeback for stores before the store. On a CPU the writeback |
1229 // and the store are atomic, but when running on the simulator it is possible | 1228 // and the store are atomic, but when running on the simulator it is possible |
1230 // to be interrupted in between. The simulator is not thread safe and V8 does | 1229 // to be interrupted in between. The simulator is not thread safe and V8 does |
1231 // not require it to be to run JavaScript therefore the profiler may sample | 1230 // not require it to be to run JavaScript therefore the profiler may sample |
1232 // the "simulated" CPU in the middle of load/store with writeback. The code | 1231 // the "simulated" CPU in the middle of load/store with writeback. The code |
1233 // below ensures that push operations are safe even when interrupted: the | 1232 // below ensures that push operations are safe even when interrupted: the |
1234 // stack pointer will be decremented before adding an element to the stack. | 1233 // stack pointer will be decremented before adding an element to the stack. |
1235 if (instr->IsStore()) { | 1234 if (instr->IsStore()) { |
1236 LoadStoreWriteBack(addr_reg, offset, addrmode); | 1235 LoadStoreWriteBack(addr_reg, offset, addrmode); |
1237 | 1236 |
1238 // For store the address post writeback is used to check access below the | 1237 // For store the address post writeback is used to check access below the |
1239 // stack. | 1238 // stack. |
1240 stack = reinterpret_cast<uint8_t*>(sp()); | 1239 stack = reinterpret_cast<uint8_t*>(sp()); |
1241 } | 1240 } |
1242 | 1241 |
1243 LoadStoreOp op = static_cast<LoadStoreOp>(instr->Mask(LoadStoreOpMask)); | 1242 LoadStoreOp op = static_cast<LoadStoreOp>(instr->Mask(LoadStoreOpMask)); |
1244 switch (op) { | 1243 switch (op) { |
1245 case LDRB_w: | 1244 case LDRB_w: set_xreg(srcdst, MemoryRead8(address)); break; |
1246 case LDRH_w: | 1245 case LDRH_w: set_xreg(srcdst, MemoryRead16(address)); break; |
1247 case LDR_w: | 1246 case LDR_w: set_xreg(srcdst, MemoryRead32(address)); break; |
1248 case LDR_x: set_xreg(srcdst, MemoryRead(address, num_bytes)); break; | 1247 case LDR_x: set_xreg(srcdst, MemoryRead64(address)); break; |
1249 case STRB_w: | 1248 case STRB_w: MemoryWrite8(address, reg<uint8_t>(srcdst)); break; |
1250 case STRH_w: | 1249 case STRH_w: MemoryWrite16(address, reg<uint16_t>(srcdst)); break; |
1251 case STR_w: | 1250 case STR_w: MemoryWrite32(address, reg<uint32_t>(srcdst)); break; |
1252 case STR_x: MemoryWrite(address, xreg(srcdst), num_bytes); break; | 1251 case STR_x: MemoryWrite64(address, reg<uint64_t>(srcdst)); break; |
1253 case LDRSB_w: { | 1252 case LDRSB_w: { |
1254 set_wreg(srcdst, ExtendValue(kWRegSize, MemoryRead8(address), SXTB)); | 1253 set_wreg(srcdst, ExtendValue(kWRegSize, MemoryRead8(address), SXTB)); |
1255 break; | 1254 break; |
1256 } | 1255 } |
1257 case LDRSB_x: { | 1256 case LDRSB_x: { |
1258 set_xreg(srcdst, ExtendValue(kXRegSize, MemoryRead8(address), SXTB)); | 1257 set_xreg(srcdst, ExtendValue(kXRegSize, MemoryRead8(address), SXTB)); |
1259 break; | 1258 break; |
1260 } | 1259 } |
1261 case LDRSH_w: { | 1260 case LDRSH_w: { |
1262 set_wreg(srcdst, ExtendValue(kWRegSize, MemoryRead16(address), SXTH)); | 1261 set_wreg(srcdst, ExtendValue(kWRegSize, MemoryRead16(address), SXTH)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 | 1471 |
1473 uint64_t Simulator::MemoryRead(uint8_t* address, unsigned num_bytes) { | 1472 uint64_t Simulator::MemoryRead(uint8_t* address, unsigned num_bytes) { |
1474 ASSERT(address != NULL); | 1473 ASSERT(address != NULL); |
1475 ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t))); | 1474 ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t))); |
1476 uint64_t read = 0; | 1475 uint64_t read = 0; |
1477 memcpy(&read, address, num_bytes); | 1476 memcpy(&read, address, num_bytes); |
1478 return read; | 1477 return read; |
1479 } | 1478 } |
1480 | 1479 |
1481 | 1480 |
1482 uint8_t Simulator::MemoryRead8(uint8_t* address) { | |
1483 return MemoryRead(address, sizeof(uint8_t)); | |
1484 } | |
1485 | |
1486 | |
1487 uint16_t Simulator::MemoryRead16(uint8_t* address) { | |
1488 return MemoryRead(address, sizeof(uint16_t)); | |
1489 } | |
1490 | |
1491 | |
1492 uint32_t Simulator::MemoryRead32(uint8_t* address) { | |
1493 return MemoryRead(address, sizeof(uint32_t)); | |
1494 } | |
1495 | |
1496 | |
1497 float Simulator::MemoryReadFP32(uint8_t* address) { | 1481 float Simulator::MemoryReadFP32(uint8_t* address) { |
1498 return rawbits_to_float(MemoryRead32(address)); | 1482 return rawbits_to_float(MemoryRead32(address)); |
1499 } | 1483 } |
1500 | 1484 |
1501 | 1485 |
1502 uint64_t Simulator::MemoryRead64(uint8_t* address) { | |
1503 return MemoryRead(address, sizeof(uint64_t)); | |
1504 } | |
1505 | |
1506 | |
1507 double Simulator::MemoryReadFP64(uint8_t* address) { | 1486 double Simulator::MemoryReadFP64(uint8_t* address) { |
1508 return rawbits_to_double(MemoryRead64(address)); | 1487 return rawbits_to_double(MemoryRead64(address)); |
1509 } | 1488 } |
1510 | 1489 |
1511 | 1490 |
1512 void Simulator::MemoryWrite(uint8_t* address, | 1491 void Simulator::MemoryWrite(uint8_t* address, |
1513 uint64_t value, | 1492 uint64_t value, |
1514 unsigned num_bytes) { | 1493 unsigned num_bytes) { |
1515 ASSERT(address != NULL); | 1494 ASSERT(address != NULL); |
1516 ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t))); | 1495 ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t))); |
1517 | 1496 |
1518 LogWrite(address, value, num_bytes); | 1497 LogWrite(address, value, num_bytes); |
1519 memcpy(address, &value, num_bytes); | 1498 memcpy(address, &value, num_bytes); |
1520 } | 1499 } |
1521 | 1500 |
1522 | 1501 |
1523 void Simulator::MemoryWrite32(uint8_t* address, uint32_t value) { | |
1524 MemoryWrite(address, value, sizeof(uint32_t)); | |
1525 } | |
1526 | |
1527 | |
1528 void Simulator::MemoryWriteFP32(uint8_t* address, float value) { | 1502 void Simulator::MemoryWriteFP32(uint8_t* address, float value) { |
1529 MemoryWrite32(address, float_to_rawbits(value)); | 1503 MemoryWrite32(address, float_to_rawbits(value)); |
1530 } | 1504 } |
1531 | 1505 |
1532 | 1506 |
1533 void Simulator::MemoryWrite64(uint8_t* address, uint64_t value) { | |
1534 MemoryWrite(address, value, sizeof(uint64_t)); | |
1535 } | |
1536 | |
1537 | |
1538 void Simulator::MemoryWriteFP64(uint8_t* address, double value) { | 1507 void Simulator::MemoryWriteFP64(uint8_t* address, double value) { |
1539 MemoryWrite64(address, double_to_rawbits(value)); | 1508 MemoryWrite64(address, double_to_rawbits(value)); |
1540 } | 1509 } |
1541 | 1510 |
1542 | 1511 |
1543 void Simulator::VisitMoveWideImmediate(Instruction* instr) { | 1512 void Simulator::VisitMoveWideImmediate(Instruction* instr) { |
1544 MoveWideImmediateOp mov_op = | 1513 MoveWideImmediateOp mov_op = |
1545 static_cast<MoveWideImmediateOp>(instr->Mask(MoveWideImmediateMask)); | 1514 static_cast<MoveWideImmediateOp>(instr->Mask(MoveWideImmediateMask)); |
1546 int64_t new_xn_val = 0; | 1515 int64_t new_xn_val = 0; |
1547 | 1516 |
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3405 default: | 3374 default: |
3406 UNIMPLEMENTED(); | 3375 UNIMPLEMENTED(); |
3407 } | 3376 } |
3408 } | 3377 } |
3409 | 3378 |
3410 #endif // USE_SIMULATOR | 3379 #endif // USE_SIMULATOR |
3411 | 3380 |
3412 } } // namespace v8::internal | 3381 } } // namespace v8::internal |
3413 | 3382 |
3414 #endif // V8_TARGET_ARCH_A64 | 3383 #endif // V8_TARGET_ARCH_A64 |
OLD | NEW |