]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/arm/include/asm/setup_mmu.h
arm: Fix coding style of asm blocks
[jailhouse.git] / hypervisor / arch / arm / include / asm / setup_mmu.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) ARM Limited, 2014
5  *
6  * Authors:
7  *  Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #ifndef _JAILHOUSE_ASM_SETUP_MMU_H
14 #define _JAILHOUSE_ASM_SETUP_MMU_H
15
16 #include <asm/head.h>
17 #include <asm/percpu.h>
18
19 #ifndef __ASSEMBLY__
20
21 /* Procedures used to translate addresses during the MMU setup process */
22 typedef void* (*phys2virt_t)(unsigned long);
23 typedef unsigned long (*virt2phys_t)(volatile const void *);
24
25 static void __attribute__((naked)) __attribute__((noinline))
26 cpu_switch_el2(unsigned long phys_bootstrap, virt2phys_t virt2phys)
27 {
28         asm volatile(
29                 /*
30                  * The linux hyp stub allows to install the vectors with a
31                  * single hvc. The vector base address is in r0
32                  * (phys_bootstrap).
33                  */
34                 "hvc    #0\n\t"
35
36                 /*
37                  * Now that the bootstrap vectors are installed, call setup_el2
38                  * with the translated physical values of lr and sp as
39                  * arguments.
40                  */
41                 "mov    r0, sp\n\t"
42                 "push   {lr}\n\t"
43                 "blx    %0\n\t"
44                 "pop    {lr}\n\t"
45                 "push   {r0}\n\t"
46                 "mov    r0, lr\n\t"
47                 "blx    %0\n\t"
48                 "pop    {r1}\n\t"
49                 "hvc    #0\n\t"
50                 :
51                 : "r" (virt2phys)
52                 /*
53                  * The call to virt2phys may clobber all temp registers. This
54                  * list ensures that the compiler uses a decent register for
55                  * hvirt2phys.
56                  */
57                 : "cc", "memory", "r0", "r1", "r2", "r3");
58 }
59
60 static inline void  __attribute__((always_inline))
61 cpu_switch_phys2virt(phys2virt_t phys2virt)
62 {
63         /* phys2virt is allowed to touch the stack */
64         asm volatile(
65                 "mov    r0, lr\n\t"
66                 "blx    %0\n\t"
67                 /* Save virt_lr */
68                 "push   {r0}\n\t"
69                 /* Translate phys_sp */
70                 "mov    r0, sp\n\t"
71                 "blx    %0\n\t"
72                 /* Jump back to virtual addresses */
73                 "mov    sp, r0\n\t"
74                 "pop    {pc}\n\t"
75                 :
76                 : "r" (phys2virt)
77                 : "cc", "r0", "r1", "r2", "r3", "lr", "sp");
78 }
79
80 #endif /* !__ASSEMBLY__ */
81 #endif /* _JAILHOUSE_ASM_SETUP_MMU_H */