1 // SPDX-License-Identifier: GPL-2.0+
3 * Switch to non-secure mode
5 * Copyright (c) 2018 Heinrich Schuchardt
7 * This module contains the ARMv7 specific code required for leaving the
8 * secure mode before booting an operating system.
13 #include <asm/armv7.h>
14 #include <asm/secure.h>
15 #include <asm/setjmp.h>
18 * entry_non_secure() - entry point when switching to non-secure mode
20 * When switching to non-secure mode switch_to_non_secure_mode() calls this
21 * function passing a jump buffer. We use this jump buffer to restore the
22 * original stack and register state.
24 * @non_secure_jmp: jump buffer for restoring stack and registers
26 static void entry_non_secure(struct jmp_buf_data *non_secure_jmp)
29 debug("Reached non-secure mode\n");
31 /* Restore stack and registers saved in switch_to_non_secure_mode() */
32 longjmp(non_secure_jmp, 1);
36 * switch_to_non_secure_mode() - switch to non-secure mode
38 * Operating systems may expect to run in non-secure mode. Here we check if
39 * we are running in secure mode and switch to non-secure mode if necessary.
41 void switch_to_non_secure_mode(void)
43 static bool is_nonsec;
44 struct jmp_buf_data non_secure_jmp;
46 if (armv7_boot_nonsec() && !is_nonsec) {
47 if (setjmp(&non_secure_jmp))
49 dcache_disable(); /* flush cache before switch to HYP */
52 secure_ram_addr(_do_nonsec_entry)(entry_non_secure,
53 (uintptr_t)&non_secure_jmp,