1# Copyright 2019 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_cc//cc:cc_library.bzl", "cc_library") 16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 17load("//pw_build:compatibility.bzl", "boolean_constraint_value", "incompatible_with_mcu") 18load("//pw_build:pw_facade.bzl", "pw_facade") 19 20package(default_visibility = ["//visibility:public"]) 21 22licenses(["notice"]) 23 24# This module has three facades, each of whose backends are set with a 25# different constraint_setting. 26# 27# - entry: This is the library that handles early exception entry and prepares 28# any CPU state that must be available to the exception handler via the 29# pw_cpu_exception_State object. The backend for this facade is 30# architecture-specific. 31constraint_setting( 32 name = "entry_constraint_setting", 33) 34 35# - handler: This facade is backed by an application-specific handler that 36# determines what to do when an exception is encountered. This may be 37# capturing a crash report before resetting the device, or in some cases 38# handling the exception to allow execution to continue. 39constraint_setting( 40 name = "handler_constraint_setting", 41) 42 43# - support: This facade provides architecture-independent functions that may be 44# helpful for dumping CPU state in various forms. This allows an application 45# to create an application-specific handler that is portable across multiple 46# architectures. 47constraint_setting( 48 name = "support_constraint_setting", 49) 50 51pw_facade( 52 name = "entry", 53 hdrs = [ 54 "public/pw_cpu_exception/entry.h", 55 "public/pw_cpu_exception/state.h", 56 ], 57 backend = ":entry_backend", 58 strip_include_prefix = "public", 59 deps = [ 60 "//pw_preprocessor", 61 ], 62) 63 64pw_facade( 65 name = "handler", 66 srcs = ["start_exception_handler.cc"], 67 hdrs = ["public/pw_cpu_exception/handler.h"], 68 backend = ":handler_backend", 69 implementation_deps = [ 70 "//pw_preprocessor", 71 ], 72 strip_include_prefix = "public", 73 deps = [":entry"], 74) 75 76pw_facade( 77 name = "support", 78 hdrs = ["public/pw_cpu_exception/support.h"], 79 backend = ":support_backend", 80 strip_include_prefix = "public", 81 deps = [ 82 ":entry", 83 ], 84) 85 86constraint_value( 87 name = "basic_handler_backend", 88 constraint_setting = "//pw_cpu_exception:handler_constraint_setting", 89) 90 91# TODO: https://github.com/bazelbuild/bazel/issues/23003 - this shouldn't be 92# needed, as it should be possible to have a config_setting as to whether 93# the entry_backend is "//pw_build:unspecified_backend" or not, but that doesn't 94# work currently due to the referenced bug. 95boolean_constraint_value( 96 name = "enabled", 97) 98 99cc_library( 100 name = "basic_handler", 101 srcs = ["basic_handler.cc"], 102 deps = [ 103 ":entry", 104 ":handler.facade", 105 "//pw_log", 106 ], 107) 108 109# Override-able flags for each facade backend. 110label_flag( 111 name = "entry_backend", 112 build_setting_default = "//pw_build:unspecified_backend", 113) 114 115label_flag( 116 name = "entry_backend_impl", 117 build_setting_default = "//pw_build:unspecified_backend", 118) 119 120label_flag( 121 name = "handler_backend", 122 build_setting_default = "//pw_build:unspecified_backend", 123) 124 125label_flag( 126 name = "support_backend", 127 build_setting_default = "//pw_build:unspecified_backend", 128) 129 130sphinx_docs_library( 131 name = "docs", 132 srcs = [ 133 "backends.rst", 134 "docs.rst", 135 ], 136 prefix = "pw_cpu_exception/", 137 target_compatible_with = incompatible_with_mcu(), 138) 139