1# Copyright 2021 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_python//python:proto.bzl", "py_proto_library") 16load( 17 "//pw_build:pigweed.bzl", 18 "pw_cc_test", 19 "pw_facade", 20) 21load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_library") 22 23package(default_visibility = ["//visibility:public"]) 24 25licenses(["notice"]) 26 27# The crash facade provides architecture-independent APIs that may be helpful 28# for analysing the CPU state delegating the reporting and crashing to the 29# backend. 30constraint_setting( 31 name = "crash_constraint_setting", 32) 33 34constraint_value( 35 name = "entry_backend", 36 constraint_setting = "//pw_cpu_exception:entry_constraint_setting", 37) 38 39constraint_value( 40 name = "support_backend", 41 constraint_setting = "//pw_cpu_exception:support_constraint_setting", 42) 43 44cc_library( 45 name = "config", 46 hdrs = ["pw_cpu_exception_cortex_m_private/config.h"], 47 deps = [":config_override"], 48) 49 50label_flag( 51 name = "config_override", 52 build_setting_default = "//pw_build:default_module_config", 53) 54 55# Override-able flag for each facade backend. 56label_flag( 57 name = "crash_backend", 58 build_setting_default = ":crash_backend_multiplexer", 59) 60 61# Default facade backends. 62alias( 63 name = "crash_backend_multiplexer", 64 actual = select({ 65 "//conditions:default": "//pw_build:unspecified_backend", 66 }), 67) 68 69pw_facade( 70 name = "crash", 71 srcs = ["crash.cc"], 72 hdrs = ["public/pw_cpu_exception_cortex_m/crash.h"], 73 backend = ":crash_backend", 74 includes = ["public"], 75 target_compatible_with = select({ 76 "@platforms//cpu:armv7-m": [], 77 "@platforms//cpu:armv7e-m": [], 78 "@platforms//cpu:armv7e-mf": [], 79 "@platforms//cpu:armv8-m": [], 80 "//conditions:default": ["@platforms//:incompatible"], 81 }), 82 deps = [ 83 ":config", 84 ":cortex_m_constants", 85 ":cpu_state", 86 "//pw_preprocessor:cortex_m", 87 ], 88) 89 90cc_library( 91 name = "cpu_state", 92 hdrs = ["public/pw_cpu_exception_cortex_m/cpu_state.h"], 93 includes = ["public"], 94 deps = [ 95 "//pw_preprocessor", 96 "//pw_preprocessor:cortex_m", 97 ], 98) 99 100cc_library( 101 name = "util", 102 srcs = ["util.cc"], 103 hdrs = ["public/pw_cpu_exception_cortex_m/util.h"], 104 includes = ["public"], 105 target_compatible_with = select({ 106 "@platforms//cpu:armv7-m": [], 107 "@platforms//cpu:armv7e-m": [], 108 "@platforms//cpu:armv7e-mf": [], 109 "@platforms//cpu:armv8-m": [], 110 "//conditions:default": ["@platforms//:incompatible"], 111 }), 112 deps = [ 113 ":config", 114 ":cortex_m_constants", 115 ":cpu_state", 116 "//pw_log", 117 "//pw_preprocessor:cortex_m", 118 ], 119) 120 121cc_library( 122 name = "support", 123 srcs = ["support.cc"], 124 deps = [ 125 ":config", 126 ":cortex_m_constants", 127 ":cpu_state", 128 ":util", 129 "//pw_cpu_exception:support_facade", 130 "//pw_log", 131 "//pw_preprocessor", 132 "//pw_preprocessor:cortex_m", 133 "//pw_string", 134 ], 135) 136 137cc_library( 138 name = "proto_dump", 139 srcs = ["proto_dump.cc"], 140 hdrs = ["public/pw_cpu_exception_cortex_m/proto_dump.h"], 141 includes = ["public"], 142 deps = [ 143 ":config", 144 ":cpu_state", 145 ":cpu_state_protos_cc.pwpb", 146 ":support", 147 "//pw_protobuf", 148 "//pw_status", 149 "//pw_stream", 150 ], 151) 152 153proto_library( 154 name = "cpu_state_protos", 155 srcs = ["pw_cpu_exception_cortex_m_protos/cpu_state.proto"], 156 import_prefix = "pw_cpu_exception_cortex_m_protos", 157 strip_import_prefix = "/pw_cpu_exception_cortex_m/pw_cpu_exception_cortex_m_protos", 158) 159 160py_proto_library( 161 name = "cpu_state_protos_pb2", 162 deps = [":cpu_state_protos"], 163) 164 165pw_proto_library( 166 name = "cpu_state_protos_cc", 167 deps = [":cpu_state_protos"], 168) 169 170cc_library( 171 name = "cpu_exception", 172 hdrs = [ 173 "public_overrides/pw_cpu_exception_backend/state.h", 174 ], 175 includes = [ 176 "public_overrides", 177 ], 178 deps = [ 179 ":cpu_state", 180 "//pw_cpu_exception:entry_facade", 181 "//pw_preprocessor", 182 "//pw_preprocessor:cortex_m", 183 ], 184) 185 186cc_library( 187 name = "cpu_exception_impl", 188 srcs = ["entry.cc"], 189 deps = [ 190 ":config", 191 ":cortex_m_constants", 192 ":cpu_state", 193 ":util", 194 # Depend on the full backends in the impl target. 195 "//pw_cpu_exception:entry", 196 "//pw_cpu_exception:handler", 197 ], 198) 199 200cc_library( 201 name = "snapshot", 202 srcs = ["snapshot.cc"], 203 hdrs = ["public/pw_cpu_exception_cortex_m/snapshot.h"], 204 deps = [ 205 ":config", 206 ":cortex_m_constants", 207 ":cpu_state", 208 ":cpu_state_protos_cc.pwpb", 209 ":proto_dump", 210 ":util", 211 "//pw_log", 212 "//pw_protobuf", 213 "//pw_status", 214 "//pw_thread:snapshot", 215 "//pw_thread:thread_cc.pwpb", 216 ], 217) 218 219cc_library( 220 name = "cortex_m_constants", 221 hdrs = ["pw_cpu_exception_cortex_m_private/cortex_m_constants.h"], 222 visibility = ["//visibility:private"], 223 deps = ["//pw_preprocessor:cortex_m"], 224) 225 226pw_cc_test( 227 name = "cpu_exception_entry_test", 228 srcs = [ 229 "exception_entry_test.cc", 230 ], 231 deps = [ 232 ":config", 233 ":cpu_exception", 234 ":cpu_state", 235 "//pw_cpu_exception:handler", 236 ], 237) 238 239pw_cc_test( 240 name = "util_test", 241 srcs = [ 242 "util_test.cc", 243 ], 244 deps = [ 245 ":cpu_state", 246 ":util", 247 ], 248) 249 250# This test defines a crash backend so one must not be specified. 251cc_library( 252 name = "crash_test_util", 253 srcs = [ 254 "crash.cc", 255 ], 256 hdrs = [ 257 "private/pw_cpu_exception_cortex_m_backend/crash.h", 258 "public/pw_cpu_exception_cortex_m/crash.h", 259 ], 260 visibility = ["//visibility:private"], 261 deps = [ 262 ":config", 263 ":cortex_m_constants", 264 ":cpu_state", 265 ":util", 266 "//pw_cpu_exception:entry", 267 "//pw_preprocessor", 268 "//pw_preprocessor:cortex_m", 269 ], 270) 271 272pw_cc_test( 273 name = "crash_test", 274 srcs = [ 275 "crash_test.cc", 276 ], 277 target_compatible_with = select({ 278 "@platforms//cpu:armv7-m": [], 279 "@platforms//cpu:armv7e-m": [], 280 "@platforms//cpu:armv7e-mf": [], 281 "@platforms//cpu:armv8-m": [], 282 "//conditions:default": ["@platforms//:incompatible"], 283 }), 284 deps = [ 285 ":config", 286 ":cortex_m_constants", 287 ":cpu_state", 288 ":crash_test_util", 289 ":util", 290 "//pw_cpu_exception:entry", 291 "//pw_preprocessor", 292 "//pw_preprocessor:cortex_m", 293 "//pw_status", 294 "//pw_string:builder", 295 "//pw_sync:lock_annotations", 296 "//pw_sync:mutex", 297 ], 298) 299