arm64: Add support for read and write registers at current EL in assembly
In order to ease the process of reading and writing any register at current EL, provide read_current and write_current assembly macros. These are included in arch/lib_helpers.h under the __ASSEMBLY__ macro condition. This is done to allow the same header file to be included by .c and .S files. BUG=chrome-os-partner:30785 BRANCH=None TEST=Compiles successfully Change-Id: I1258850438624abfe3b1ed7240df0db0e7905be6 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/216373 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Tom Warren <twarren@nvidia.com> Tested-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
parent
82826e3c44
commit
c11c7287f5
1 changed files with 97 additions and 0 deletions
|
|
@ -30,6 +30,9 @@
|
|||
* file.
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_LIB_HELPERS_H__
|
||||
#define __ARCH_LIB_HELPERS_H__
|
||||
|
||||
#define EL0 0
|
||||
#define EL1 1
|
||||
#define EL2 2
|
||||
|
|
@ -38,6 +41,96 @@
|
|||
#define CURRENT_EL_MASK 0x3
|
||||
#define CURRENT_EL_SHIFT 2
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
|
||||
/* Macro to switch to label based on current el */
|
||||
.macro switch_el xreg label1 label2 label3
|
||||
mrs \xreg, CurrentEL
|
||||
/* Currently at EL1 */
|
||||
cmp \xreg, #(EL1 << CURRENT_EL_SHIFT)
|
||||
b.eq \label1
|
||||
/* Currently at EL2 */
|
||||
cmp \xreg, #(EL2 << CURRENT_EL_SHIFT)
|
||||
b.eq \label2
|
||||
/* Currently at EL3 */
|
||||
cmp \xreg, #(EL3 << CURRENT_EL_SHIFT)
|
||||
b.eq \label3
|
||||
.endm
|
||||
|
||||
/* Macro to read sysreg at current EL
|
||||
xreg - reg in which read value needs to be stored
|
||||
sysreg - system reg that is to be read
|
||||
*/
|
||||
.macro read_current xreg sysreg
|
||||
switch_el \xreg, 101f, 102f, 103f
|
||||
101:
|
||||
mrs \xreg, \sysreg\()_el1
|
||||
b 104f
|
||||
102:
|
||||
mrs \xreg, \sysreg\()_el2
|
||||
b 104f
|
||||
103:
|
||||
mrs \xreg, \sysreg\()_el3
|
||||
b 104f
|
||||
104:
|
||||
.endm
|
||||
|
||||
/* Macro to write sysreg at current EL
|
||||
xreg - reg from which value needs to be written
|
||||
sysreg - system reg that is to be written
|
||||
temp - temp reg that can be used to read current EL
|
||||
*/
|
||||
.macro write_current sysreg xreg temp
|
||||
switch_el \temp, 101f, 102f, 103f
|
||||
101:
|
||||
msr \sysreg\()_el1, \xreg
|
||||
b 104f
|
||||
102:
|
||||
msr \sysreg\()_el2, \xreg
|
||||
b 104f
|
||||
103:
|
||||
msr \sysreg\()_el3, \xreg
|
||||
b 104f
|
||||
104:
|
||||
.endm
|
||||
|
||||
/* Macro to read sysreg at current EL - 1
|
||||
xreg - reg in which read value needs to be stored
|
||||
sysreg - system reg that is to be read
|
||||
*/
|
||||
.macro read_lower xreg sysreg
|
||||
switch_el \xreg, 101f, 102f, 103f
|
||||
101:
|
||||
b 104f
|
||||
102:
|
||||
mrs \xreg, \sysreg\()_el1
|
||||
b 104f
|
||||
103:
|
||||
mrs \xreg, \sysreg\()_el2
|
||||
b 104f
|
||||
104:
|
||||
.endm
|
||||
|
||||
/* Macro to write sysreg at current EL - 1
|
||||
xreg - reg from which value needs to be written
|
||||
sysreg - system reg that is to be written
|
||||
temp - temp reg that can be used to read current EL
|
||||
*/
|
||||
.macro write_lower sysreg xreg temp
|
||||
switch_el \temp, 101f, 102f, 103f
|
||||
101:
|
||||
b 104f
|
||||
102:
|
||||
msr \sysreg\()_el1, \xreg
|
||||
b 104f
|
||||
103:
|
||||
msr \sysreg\()_el2, \xreg
|
||||
b 104f
|
||||
104:
|
||||
.endm
|
||||
|
||||
#else
|
||||
|
||||
#define DAIF_DBG_BIT (1<<3)
|
||||
#define DAIF_ABT_BIT (1<<2)
|
||||
#define DAIF_IRQ_BIT (1<<1)
|
||||
|
|
@ -298,3 +391,7 @@ void tlbiallis_el2(void);
|
|||
void tlbiallis_el3(void);
|
||||
void tlbiallis_current(void);
|
||||
void tlbivaa_el1(uint64_t va);
|
||||
|
||||
#endif // __ASSEMBLY__
|
||||
|
||||
#endif // __ARCH_LIB_HELPERS_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue