• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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, kPointerSize);
25   // x64 rip (r16) has no Register instance associated.
26   RecordRegisterSavedToStack(kRipDwarfCode, -kPointerSize);
27 }
28 
29 // static
RegisterToDwarfCode(Register name)30 int 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
DwarfRegisterCodeToString(int code)47 const 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