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
71cb0ef41Sopenharmony_cinamespace v8 {
81cb0ef41Sopenharmony_cinamespace internal {
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cistatic const int kR0DwarfCode = 0;
111cb0ef41Sopenharmony_cistatic const int kFpDwarfCode = 11;
121cb0ef41Sopenharmony_cistatic const int kSpDwarfCode = 13;
131cb0ef41Sopenharmony_cistatic const int kLrDwarfCode = 14;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst int EhFrameConstants::kCodeAlignmentFactor = 4;
161cb0ef41Sopenharmony_ciconst int EhFrameConstants::kDataAlignmentFactor = -4;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_civoid EhFrameWriter::WriteReturnAddressRegisterCode() {
191cb0ef41Sopenharmony_ci  WriteULeb128(kLrDwarfCode);
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_civoid EhFrameWriter::WriteInitialStateInCie() {
231cb0ef41Sopenharmony_ci  SetBaseAddressRegisterAndOffset(fp, 0);
241cb0ef41Sopenharmony_ci  RecordRegisterNotModified(lr);
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci// static
281cb0ef41Sopenharmony_ciint EhFrameWriter::RegisterToDwarfCode(Register name) {
291cb0ef41Sopenharmony_ci  switch (name.code()) {
301cb0ef41Sopenharmony_ci    case kRegCode_fp:
311cb0ef41Sopenharmony_ci      return kFpDwarfCode;
321cb0ef41Sopenharmony_ci    case kRegCode_sp:
331cb0ef41Sopenharmony_ci      return kSpDwarfCode;
341cb0ef41Sopenharmony_ci    case kRegCode_lr:
351cb0ef41Sopenharmony_ci      return kLrDwarfCode;
361cb0ef41Sopenharmony_ci    case kRegCode_r0:
371cb0ef41Sopenharmony_ci      return kR0DwarfCode;
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 kFpDwarfCode:
491cb0ef41Sopenharmony_ci      return "fp";
501cb0ef41Sopenharmony_ci    case kSpDwarfCode:
511cb0ef41Sopenharmony_ci      return "sp";
521cb0ef41Sopenharmony_ci    case kLrDwarfCode:
531cb0ef41Sopenharmony_ci      return "lr";
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