1//===-- AppleArm64ExceptionClass.h ------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_APPLEARM64EXCEPTIONCLASS_H
10#define LLDB_TARGET_APPLEARM64EXCEPTIONCLASS_H
11
12#include <cstdint>
13
14namespace lldb_private {
15
16enum class AppleArm64ExceptionClass : unsigned {
17#define APPLE_ARM64_EXCEPTION_CLASS(Name, Code) Name = Code,
18#include "AppleArm64ExceptionClass.def"
19};
20
21/// Get the Apple ARM64 exception class encoded within \p esr.
22inline AppleArm64ExceptionClass getAppleArm64ExceptionClass(uint32_t esr) {
23  /*
24   * Exception Syndrome Register
25   *
26   *  31  26 25 24               0
27   * +------+--+------------------+
28   * |  EC  |IL|       ISS        |
29   * +------+--+------------------+
30   *
31   * EC  - Exception Class
32   * IL  - Instruction Length
33   * ISS - Instruction Specific Syndrome
34   */
35  return static_cast<AppleArm64ExceptionClass>(esr >> 26);
36}
37
38inline const char *toString(AppleArm64ExceptionClass EC) {
39  switch (EC) {
40#define APPLE_ARM64_EXCEPTION_CLASS(Name, Code)                                \
41  case AppleArm64ExceptionClass::Name:                                         \
42    return #Name;
43#include "AppleArm64ExceptionClass.def"
44  }
45  return "Unknown Exception Class";
46}
47
48} // namespace lldb_private
49
50#endif // LLDB_TARGET_APPLEARM64EXCEPTIONCLASS_H
51