My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cpu.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 #ifndef __CPU_H__
24 #define __CPU_H__
25 
26 #include <sw_types.h>
27 #include <sw_board.h>
28 
29 #define SCTLR_EE_BIT (1<<25)
30 #define SCTLR_ALIGN_BITS (1<<1 | 1<<3)
31 
32 #define SCTLR_MMUCACHE_ON (1 << 0 | 1 << 2 | 1 << 12)
33 
34 #define SCR_RESET (1<<2 | 1<<8 | 1<<10)
35 #define SCR_NS_BIT (1<<0)
36 #define SCR_FIQ_BIT (1<<2)
37 #define SCR_ST_BIT (1<<11)
38 
39 #define MODE_EL0 0x0
40 #define MODE_EL1 0x1
41 #define MODE_EL2 0x2
42 #define MODE_EL3 0x3
43 
44 #define MODE_SP0 0x0
45 #define MODE_SPX 0x1
46 
47 #define MODE_ARCH64 0x0
48 #define MODE_ARCH32 0x1
49 
50 #define PSR_EL1_RESET (0xf<<6 | MODE_ARCH64<<4 | MODE_EL1<<2 | MODE_SPX)
51 #define PSR_EL1h_SET (0xe<<6 | MODE_ARCH64<<4 | MODE_EL1<<2 | MODE_SPX)
52 #define PSR_EL1t_SET (0xe<<6 | MODE_ARCH64<<4 | MODE_EL1<<2 | MODE_SP0)
53 #define PSR_EL2_RESET (0xf<<6 | MODE_ARCH64<<4 | MODE_EL2<<2 | MODE_SPX)
54 #define PSR_EL3_RESET (0xf<<6 | MODE_ARCH64<<4 | MODE_EL3<<2 | MODE_SPX)
55 
56 #ifdef __CCODE__
57 struct psr64 {
58  u32 sp:1;
59  u32 res0_3:1;
60  u32 el:2;
61  u32 nRW:1;
62  u32 res0_2:1;
63  u32 f:1;
64  u32 i:1;
65  u32 a:1;
66  u32 d:1;
67  u32 res0_1:10;
68  u32 il:1;
69  u32 ss:1;
70  u32 res0_0:6;
71  u32 v:1;
72  u32 c:1;
73  u32 z:1;
74  u32 n:1;
75 };
76 
77 typedef struct {
78  u64 sp_el0;
79  u64 sp_el1;
80  u64 elr_el1;
81  struct psr64 spsr_el1;
82  u64 vbar_el1;
83  u64 ttbr0_el1;
84  u64 ttbr1_el1;
85  u64 sctlr_el1;
86 } lower_el_regs;
87 
88 typedef struct {
89  struct psr64 spsr;
90  u64 elr_elx;
91 #ifdef __KERNEL_EL3__
92  lower_el_regs ler;
93 #endif
94  u64 res0;
95  u64 x[31];
96 } core_registers;
97 
98 typedef struct {
99  core_registers regs;
100 #ifdef __KERNEL_EL3__
101  u32 security_state;
102 #endif
103 } state_context;
104 
105 /* Default Entry function for all ELX */
106 int main(void);
107 
108 static inline void data_memory_barrier(void)
109 {
110 
111  __asm volatile("dsb osh" : : : "memory");
112 }
113 
117 static inline void data_sync_barrier(void)
118 {
119 
120  __asm volatile("dmb ish" : : : "memory");
121 }
122 
123 extern u64 elx_stack[];
124 #ifdef __KERNEL_EL3__
125 extern state_context context[2][MAX_CORES];
126 #endif
127 #ifdef __KERNEL_EL2__
128 extern state_context context[MAX_GUESTS][MAX_CORES];
129 #endif
130 
131 #endif /* __CCODE__ */
132 
133 #endif
macro save_context stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp!stp mov sp endm macro restore_context mov sp
Definition: macros.h:24
int main(void)
Sample application to show the implementation of Global Platform Client API specification.
Definition: otz_boot_ack.c:46
#define MAX_CORES
Definition: sw_board.h:26
#define MAX_GUESTS
Definition: sw_board.h:28
void data_memory_barrier(void)
calls the data memory barrier instruction
Definition: cpu.c:195
unsigned int res0
Definition: sw_buddy.h:39
void data_sync_barrier(void)
calls the data synchronization barrier instruction
Definition: cpu.c:203