11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/diagnostics/eh-frame.h"
61cb0ef41Sopenharmony_ci#include "src/zone/zone-containers.h"
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cinamespace v8 {
91cb0ef41Sopenharmony_cinamespace internal {
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cistatic const int kRaxDwarfCode = 0;
121cb0ef41Sopenharmony_cistatic const int kRbpDwarfCode = 6;
131cb0ef41Sopenharmony_cistatic const int kRspDwarfCode = 7;
141cb0ef41Sopenharmony_cistatic const int kRipDwarfCode = 16;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst int EhFrameConstants::kCodeAlignmentFactor = 1;
171cb0ef41Sopenharmony_ciconst int EhFrameConstants::kDataAlignmentFactor = -8;
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_civoid EhFrameWriter::WriteReturnAddressRegisterCode() {
201cb0ef41Sopenharmony_ci  WriteULeb128(kRipDwarfCode);
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_civoid EhFrameWriter::WriteInitialStateInCie() {
241cb0ef41Sopenharmony_ci  SetBaseAddressRegisterAndOffset(rsp, kSystemPointerSize);
251cb0ef41Sopenharmony_ci  // x64 rip (r16) has no Register instance associated.
261cb0ef41Sopenharmony_ci  RecordRegisterSavedToStack(kRipDwarfCode, -kSystemPointerSize);
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci// static
301cb0ef41Sopenharmony_ciint EhFrameWriter::RegisterToDwarfCode(Register name) {
311cb0ef41Sopenharmony_ci  switch (name.code()) {
321cb0ef41Sopenharmony_ci    case kRegCode_rbp:
331cb0ef41Sopenharmony_ci      return kRbpDwarfCode;
341cb0ef41Sopenharmony_ci    case kRegCode_rsp:
351cb0ef41Sopenharmony_ci      return kRspDwarfCode;
361cb0ef41Sopenharmony_ci    case kRegCode_rax:
371cb0ef41Sopenharmony_ci      return kRaxDwarfCode;
381cb0ef41Sopenharmony_ci    default:
391cb0ef41Sopenharmony_ci      UNIMPLEMENTED();
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci}
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci#ifdef ENABLE_DISASSEMBLER
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci// static
461cb0ef41Sopenharmony_ciconst char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) {
471cb0ef41Sopenharmony_ci  switch (code) {
481cb0ef41Sopenharmony_ci    case kRbpDwarfCode:
491cb0ef41Sopenharmony_ci      return "rbp";
501cb0ef41Sopenharmony_ci    case kRspDwarfCode:
511cb0ef41Sopenharmony_ci      return "rsp";
521cb0ef41Sopenharmony_ci    case kRipDwarfCode:
531cb0ef41Sopenharmony_ci      return "rip";
541cb0ef41Sopenharmony_ci    default:
551cb0ef41Sopenharmony_ci      UNIMPLEMENTED();
561cb0ef41Sopenharmony_ci  }
571cb0ef41Sopenharmony_ci}
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci#endif
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci}  // namespace internal
621cb0ef41Sopenharmony_ci}  // namespace v8
63