pw_cpu_exception: Split facade
The pw_cpu_exception facade is comprised of three parts: the part
implemented by the architecture, and the part implemented by the
application, and some supporting libraries that make it easier to dump
CPU state. Since these are provided independently, the facade has been
split into three facades:
1. entry
2. handler
3. support
Change-Id: I48c92f42b208f79596740f1bec59ed3d29e277a8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/11646
Commit-Queue: Armando Montanez <amontanez@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_cpu_exception/start_exception_handler.cc b/pw_cpu_exception/start_exception_handler.cc
new file mode 100644
index 0000000..dc566d9
--- /dev/null
+++ b/pw_cpu_exception/start_exception_handler.cc
@@ -0,0 +1,36 @@
+// Copyright 2020 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include "pw_cpu_exception/handler.h"
+
+namespace pw::cpu_exception {
+
+static void (*exception_handler)(pw_CpuExceptionState*) =
+ &pw_CpuExceptionDefaultHandler;
+
+extern "C" void pw_CpuExceptionSetHandler(
+ void (*handler)(pw_CpuExceptionState*)) {
+ exception_handler = handler;
+}
+
+// Revert the exception handler to point to pw_CpuExceptionDefaultHandler().
+extern "C" void pw_CpuExceptionRestoreDefaultHandler() {
+ exception_handler = &pw_CpuExceptionDefaultHandler;
+}
+
+extern "C" void pw_HandleCpuException(void* cpu_state) {
+ exception_handler(reinterpret_cast<pw_CpuExceptionState*>(cpu_state));
+}
+
+} // namespace pw::cpu_exception
\ No newline at end of file