xref: /aosp_15_r20/external/pigweed/pw_cpu_exception/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker# Copyright 2020 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker#
3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker# the License at
6*61c4878aSAndroid Build Coastguard Worker#
7*61c4878aSAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker#
9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker# the License.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Workerimport("//build_overrides/pigweed.gni")
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/facade.gni")
18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_docgen/docs.gni")
19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_unit_test/test.gni")
20*61c4878aSAndroid Build Coastguard Workerimport("backend.gni")
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Workerconfig("public_include_path") {
23*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "public" ]
24*61c4878aSAndroid Build Coastguard Worker}
25*61c4878aSAndroid Build Coastguard Worker
26*61c4878aSAndroid Build Coastguard Workergroup("pw_cpu_exception") {
27*61c4878aSAndroid Build Coastguard Worker  public_deps = [
28*61c4878aSAndroid Build Coastguard Worker    ":entry",
29*61c4878aSAndroid Build Coastguard Worker    ":handler",
30*61c4878aSAndroid Build Coastguard Worker  ]
31*61c4878aSAndroid Build Coastguard Worker}
32*61c4878aSAndroid Build Coastguard Worker
33*61c4878aSAndroid Build Coastguard Worker# This module has three facades, each of whose backends are set with a
34*61c4878aSAndroid Build Coastguard Worker# different GN variable.
35*61c4878aSAndroid Build Coastguard Worker#
36*61c4878aSAndroid Build Coastguard Worker# - entry: This is the library that handles early exception entry and prepares
37*61c4878aSAndroid Build Coastguard Worker#   any CPU state that must be available to the exception handler via the
38*61c4878aSAndroid Build Coastguard Worker#   pw_cpu_exception_State object. The backend for this facade is
39*61c4878aSAndroid Build Coastguard Worker#   architecture-specific.
40*61c4878aSAndroid Build Coastguard Worker#   Set this facade's backend via `pw_cpu_exception_ENTRY_BACKEND`
41*61c4878aSAndroid Build Coastguard Worker#
42*61c4878aSAndroid Build Coastguard Worker# - handler: This facade is backed by an application-specific handler that
43*61c4878aSAndroid Build Coastguard Worker#   determines what to do when an exception is encountered. This may be
44*61c4878aSAndroid Build Coastguard Worker#   capturing a crash report before resetting the device, or in some cases
45*61c4878aSAndroid Build Coastguard Worker#   handling the exception to allow execution to continue.
46*61c4878aSAndroid Build Coastguard Worker#   Set this facade's backend via `pw_cpu_exception_HANDLER_BACKEND`
47*61c4878aSAndroid Build Coastguard Worker#
48*61c4878aSAndroid Build Coastguard Worker# - support: This facade provides architecture-independent functions that may be
49*61c4878aSAndroid Build Coastguard Worker#   helpful for dumping CPU state in various forms. This allows an application
50*61c4878aSAndroid Build Coastguard Worker#   to create an application-specific handler that is portable across multiple
51*61c4878aSAndroid Build Coastguard Worker#   architectures.
52*61c4878aSAndroid Build Coastguard Worker#   Set this facade's backend via `pw_cpu_exception_SUPPORT_BACKEND`
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard Workerpw_facade("entry") {
55*61c4878aSAndroid Build Coastguard Worker  backend = pw_cpu_exception_ENTRY_BACKEND
56*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
57*61c4878aSAndroid Build Coastguard Worker  public_deps = [ "$dir_pw_preprocessor" ]
58*61c4878aSAndroid Build Coastguard Worker  public = [
59*61c4878aSAndroid Build Coastguard Worker    "public/pw_cpu_exception/entry.h",
60*61c4878aSAndroid Build Coastguard Worker    "public/pw_cpu_exception/state.h",
61*61c4878aSAndroid Build Coastguard Worker  ]
62*61c4878aSAndroid Build Coastguard Worker}
63*61c4878aSAndroid Build Coastguard Worker
64*61c4878aSAndroid Build Coastguard Worker# The entry facade is hard tied to the definition of the pw_cpu_exception_State,
65*61c4878aSAndroid Build Coastguard Worker# so spliting them into separate facades would require extra configurations
66*61c4878aSAndroid Build Coastguard Worker# along with extra compatibility checks to ensure they are never mismatched.
67*61c4878aSAndroid Build Coastguard Worker#
68*61c4878aSAndroid Build Coastguard Worker# Instead, this ":entry_impl" target collects the entry implementation from the
69*61c4878aSAndroid Build Coastguard Worker# backend that depends on the handler which in turn depends on ":entry" to avoid
70*61c4878aSAndroid Build Coastguard Worker# circular deps.
71*61c4878aSAndroid Build Coastguard Worker#
72*61c4878aSAndroid Build Coastguard Worker# This group ("$dir_pw_cpu_exception:entry_impl") must listed in
73*61c4878aSAndroid Build Coastguard Worker# pw_build_LINK_DEPS if pw_cpu_exception_ENTRY_BACKEND is set.
74*61c4878aSAndroid Build Coastguard Worker#
75*61c4878aSAndroid Build Coastguard Worker# Entry backends must provide their own "*.impl" target that collects their
76*61c4878aSAndroid Build Coastguard Worker# entry implementation.
77*61c4878aSAndroid Build Coastguard Workergroup("entry_impl") {
78*61c4878aSAndroid Build Coastguard Worker  public_deps = []
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard Worker  if (pw_cpu_exception_ENTRY_BACKEND != "") {
81*61c4878aSAndroid Build Coastguard Worker    public_deps += [ get_label_info(pw_cpu_exception_ENTRY_BACKEND,
82*61c4878aSAndroid Build Coastguard Worker                                    "label_no_toolchain") + ".impl" ]
83*61c4878aSAndroid Build Coastguard Worker  }
84*61c4878aSAndroid Build Coastguard Worker}
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Workerpw_facade("handler") {
87*61c4878aSAndroid Build Coastguard Worker  backend = pw_cpu_exception_HANDLER_BACKEND
88*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
89*61c4878aSAndroid Build Coastguard Worker  public_deps = [
90*61c4878aSAndroid Build Coastguard Worker    ":entry",
91*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_preprocessor",
92*61c4878aSAndroid Build Coastguard Worker  ]
93*61c4878aSAndroid Build Coastguard Worker  sources = [ "start_exception_handler.cc" ]
94*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_cpu_exception/handler.h" ]
95*61c4878aSAndroid Build Coastguard Worker}
96*61c4878aSAndroid Build Coastguard Worker
97*61c4878aSAndroid Build Coastguard Worker# This library is technically optional. It is recommended to use `support` when
98*61c4878aSAndroid Build Coastguard Worker# doing basic dumps of CPU state. As an alternative, projects may choose to
99*61c4878aSAndroid Build Coastguard Worker# directly depend on the entry backend if they require direct access to
100*61c4878aSAndroid Build Coastguard Worker# pw_cpu_exception_State members.
101*61c4878aSAndroid Build Coastguard Workerpw_facade("support") {
102*61c4878aSAndroid Build Coastguard Worker  backend = pw_cpu_exception_SUPPORT_BACKEND
103*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
104*61c4878aSAndroid Build Coastguard Worker  public_deps = [
105*61c4878aSAndroid Build Coastguard Worker    ":entry",
106*61c4878aSAndroid Build Coastguard Worker    dir_pw_span,
107*61c4878aSAndroid Build Coastguard Worker  ]
108*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_cpu_exception/support.h" ]
109*61c4878aSAndroid Build Coastguard Worker}
110*61c4878aSAndroid Build Coastguard Worker
111*61c4878aSAndroid Build Coastguard Workerpw_source_set("basic_handler") {
112*61c4878aSAndroid Build Coastguard Worker  deps = [
113*61c4878aSAndroid Build Coastguard Worker    ":handler.facade",
114*61c4878aSAndroid Build Coastguard Worker    dir_pw_log,
115*61c4878aSAndroid Build Coastguard Worker  ]
116*61c4878aSAndroid Build Coastguard Worker  sources = [ "basic_handler.cc" ]
117*61c4878aSAndroid Build Coastguard Worker}
118*61c4878aSAndroid Build Coastguard Worker
119*61c4878aSAndroid Build Coastguard Workerpw_doc_group("docs") {
120*61c4878aSAndroid Build Coastguard Worker  sources = [
121*61c4878aSAndroid Build Coastguard Worker    "backends.rst",
122*61c4878aSAndroid Build Coastguard Worker    "docs.rst",
123*61c4878aSAndroid Build Coastguard Worker  ]
124*61c4878aSAndroid Build Coastguard Worker}
125*61c4878aSAndroid Build Coastguard Worker
126*61c4878aSAndroid Build Coastguard Workerpw_test_group("tests") {
127*61c4878aSAndroid Build Coastguard Worker}
128