1// Copyright 2016 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "src/eh-frame.h" 6#include "src/zone/zone-containers.h" 7 8namespace v8 { 9namespace internal { 10 11static const int kRaxDwarfCode = 0; 12static const int kRbpDwarfCode = 6; 13static const int kRspDwarfCode = 7; 14static const int kRipDwarfCode = 16; 15 16const int EhFrameConstants::kCodeAlignmentFactor = 1; 17const int EhFrameConstants::kDataAlignmentFactor = -8; 18 19void EhFrameWriter::WriteReturnAddressRegisterCode() { 20 WriteULeb128(kRipDwarfCode); 21} 22 23void EhFrameWriter::WriteInitialStateInCie() { 24 SetBaseAddressRegisterAndOffset(rsp, kPointerSize); 25 // x64 rip (r16) has no Register instance associated. 26 RecordRegisterSavedToStack(kRipDwarfCode, -kPointerSize); 27} 28 29// static 30int EhFrameWriter::RegisterToDwarfCode(Register name) { 31 switch (name.code()) { 32 case Register::kCode_rbp: 33 return kRbpDwarfCode; 34 case Register::kCode_rsp: 35 return kRspDwarfCode; 36 case Register::kCode_rax: 37 return kRaxDwarfCode; 38 default: 39 UNIMPLEMENTED(); 40 return -1; 41 } 42} 43 44#ifdef ENABLE_DISASSEMBLER 45 46// static 47const char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) { 48 switch (code) { 49 case kRbpDwarfCode: 50 return "rbp"; 51 case kRspDwarfCode: 52 return "rsp"; 53 case kRipDwarfCode: 54 return "rip"; 55 default: 56 UNIMPLEMENTED(); 57 return nullptr; 58 } 59} 60 61#endif 62 63} // namespace internal 64} // namespace v8 65