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/diagnostics/eh-frame.h"
6 #include "src/zone/zone-containers.h"
7 
8 namespace v8 {
9 namespace internal {
10 
11 static const int kRaxDwarfCode = 0;
12 static const int kRbpDwarfCode = 6;
13 static const int kRspDwarfCode = 7;
14 static const int kRipDwarfCode = 16;
15 
16 const int EhFrameConstants::kCodeAlignmentFactor = 1;
17 const int EhFrameConstants::kDataAlignmentFactor = -8;
18 
WriteReturnAddressRegisterCode()19 void EhFrameWriter::WriteReturnAddressRegisterCode() {
20   WriteULeb128(kRipDwarfCode);
21 }
22 
WriteInitialStateInCie()23 void EhFrameWriter::WriteInitialStateInCie() {
24   SetBaseAddressRegisterAndOffset(rsp, kSystemPointerSize);
25   // x64 rip (r16) has no Register instance associated.
26   RecordRegisterSavedToStack(kRipDwarfCode, -kSystemPointerSize);
27 }
28 
29 // static
RegisterToDwarfCode(Register name)30 int EhFrameWriter::RegisterToDwarfCode(Register name) {
31   switch (name.code()) {
32     case kRegCode_rbp:
33       return kRbpDwarfCode;
34     case kRegCode_rsp:
35       return kRspDwarfCode;
36     case kRegCode_rax:
37       return kRaxDwarfCode;
38     default:
39       UNIMPLEMENTED();
40   }
41 }
42 
43 #ifdef ENABLE_DISASSEMBLER
44 
45 // static
DwarfRegisterCodeToString(int code)46 const char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) {
47   switch (code) {
48     case kRbpDwarfCode:
49       return "rbp";
50     case kRspDwarfCode:
51       return "rsp";
52     case kRipDwarfCode:
53       return "rip";
54     default:
55       UNIMPLEMENTED();
56   }
57 }
58 
59 #endif
60 
61 }  // namespace internal
62 }  // namespace v8
63