blob: 7d9cf967151b5f9c2356ba17a6f71a507c1ea3ed [file] [log] [blame]
Per Åstrand79929ff2021-01-26 14:42:43 +01001/*
2 * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* to be able to print from nonsecure world since uart is mapped
20 * to secure world. */
21#include "../common/secure_entries.hpp"
22
23/* Disable semihosting */
24__asm(".global __use_no_semihosting\n");
25
26/* Target specific CMSIS Device header is included by compiler,
27 * see cmsis.cmake in core_software */
28
29using namespace std;
30
31extern "C" void SystemInit() {
32 /* secure world is doing the neccessary setup, since it has
33 * the privilege to do so, and non-secure doesn't
34 */
35 nonsecure_print("skipping system init from non-secure world");
36}
37
38/*
39 * Retargeting stubs for the non-secure world
40 */
41extern "C" {
42
43void _sys_exit(int code) {
Anton Moberg908a07c2021-04-08 09:50:57 +020044 (void)code;
Per Åstrand79929ff2021-01-26 14:42:43 +010045 nonsecure_print("Returning to secure world!");
46 /*
47 * Make sure we return to secure world when exit by
48 * setting LR to FNC_RETURN and branching to tell CPU
49 * we want to leave the non-secure world
50 */
51 asm("LDR r14, =0xFEFFFFFE\n");
52 asm("BX lr\n");
53}
54
55void _ttywrch(int ch) {
56 (void)ch;
57}
58
59char *_sys_command_string(char *cmd, int len) {
60 (void)len;
61
62 return cmd;
63}
64
65} // extern "C"
66
67int result = -1;
68
69int return_nonsecure_result(void) {
70 return result;
71}
72
73int main() {
74 nonsecure_print("Non-secure main starting up.");
75
76 set_result_function(return_nonsecure_result);
77
78 /* Execute inference in secure world with data not accessible from
79 * non-secure world
80 */
81 nonsecure_print("Starting secure inference.");
82 int inference_failed = run_secure_inference();
83
84 nonsecure_print("Inference returned: ");
85 nonsecure_print(inference_failed ? "failed" : "success");
86
87 result = inference_failed ? -1 : 0;
88
89 return 0;
90}