1 /*
2  * (c) 2017 Alexander Warg <alexander.warg@kernkonzept.com>
3  *
4  * This file is part of L4Re and distributed under the terms of the
5  * GNU General Public License 2.
6  * Please see the COPYING-GPL-2 file for details.
7  *
8  * As a special exception, you may use this file as part of a free software
9  * library without restriction.  Specifically, if other files instantiate
10  * templates or use macros or inline functions from this file, or you compile
11  * this file and link it with other files to produce an executable, this
12  * file does not by itself cause the resulting executable to be covered by
13  * the GNU General Public License.  This exception does not however
14  * invalidate any other reasons why the executable file might be covered by
15  * the GNU General Public License.
16  */
17 #pragma once
18 
19 typedef struct l4_arm_vcpu_e_info_t
20 {
21   l4_uint8_t  version;     // must be 0
22   l4_uint8_t  gic_version;
23   l4_uint8_t  _rsvd0[2];
24   l4_uint32_t features;
25   l4_uint32_t _rsvd1[14];
26   l4_umword_t user[8];
27 } l4_arm_vcpu_e_info_t;
28 
29 L4_INLINE void *l4_vcpu_e_ptr(void const *vcpu, unsigned id) L4_NOTHROW;
l4_vcpu_e_ptr(void const * vcpu,unsigned id)30 L4_INLINE void *l4_vcpu_e_ptr(void const *vcpu, unsigned id) L4_NOTHROW
31 { return (void *)((l4_addr_t)vcpu + 0x400 + (id & 0xfff)); }
32 
33 enum L4_vcpu_e_consts
34 {
35   L4_VCPU_E_NUM_LR = 4, /**< Number of list registers (LRs) */
36 };
37 
38 L4_INLINE l4_arm_vcpu_e_info_t const *
39 l4_vcpu_e_info(void const *vcpu) L4_NOTHROW;
40 
41 L4_INLINE l4_arm_vcpu_e_info_t const *
l4_vcpu_e_info(void const * vcpu)42 l4_vcpu_e_info(void const *vcpu) L4_NOTHROW
43 {
44   return (l4_arm_vcpu_e_info_t const *)((l4_addr_t)vcpu + 0x200);
45 }
46 
47 L4_INLINE l4_umword_t *
48 l4_vcpu_e_info_user(void *vcpu) L4_NOTHROW;
49 
50 L4_INLINE l4_umword_t *
l4_vcpu_e_info_user(void * vcpu)51 l4_vcpu_e_info_user(void *vcpu) L4_NOTHROW
52 {
53   return ((l4_arm_vcpu_e_info_t *)((l4_addr_t)vcpu + 0x200))->user;
54 }
55 
56 
57 /**
58  * Read a 32bit field from the extended vCPU state.
59  *
60  * \param vcpu  Pointer to the vCPU memory.
61  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
62  * \returns The value stored in the field.
63  */
64 L4_INLINE l4_uint32_t
65 l4_vcpu_e_read_32(void const *vcpu, unsigned id) L4_NOTHROW;
66 
67 L4_INLINE l4_uint32_t
l4_vcpu_e_read_32(void const * vcpu,unsigned id)68 l4_vcpu_e_read_32(void const *vcpu, unsigned id) L4_NOTHROW
69 { return *(l4_uint32_t const *)l4_vcpu_e_ptr(vcpu, id); }
70 
71 /**
72  * Write a 32bit field to the extended vCPU state.
73  *
74  * \param vcpu  Pointer to the vCPU memory.
75  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
76  * \param val   The value to be written.
77  */
78 L4_INLINE void
79 l4_vcpu_e_write_32(void *vcpu, unsigned id, l4_uint32_t val) L4_NOTHROW;
80 
81 L4_INLINE void
l4_vcpu_e_write_32(void * vcpu,unsigned id,l4_uint32_t val)82 l4_vcpu_e_write_32(void *vcpu, unsigned id, l4_uint32_t val) L4_NOTHROW
83 { *((l4_uint32_t *)l4_vcpu_e_ptr(vcpu, + id)) = val; }
84 
85 /**
86  * Read a 64bit field from the extended vCPU state.
87  *
88  * \param vcpu  Pointer to the vCPU memory.
89  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
90  * \returns The value stored in the field.
91  */
92 L4_INLINE l4_uint64_t
93 l4_vcpu_e_read_64(void const *vcpu, unsigned id) L4_NOTHROW;
94 
95 L4_INLINE l4_uint64_t
l4_vcpu_e_read_64(void const * vcpu,unsigned id)96 l4_vcpu_e_read_64(void const *vcpu, unsigned id) L4_NOTHROW
97 { return *(l4_uint64_t const *)l4_vcpu_e_ptr(vcpu, id); }
98 
99 /**
100  * Write a 64bit field to the extended vCPU state.
101  *
102  * \param vcpu  Pointer to the vCPU memory.
103  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
104  * \param val   The value to be written.
105  */
106 L4_INLINE void
107 l4_vcpu_e_write_64(void *vcpu, unsigned id, l4_uint64_t val) L4_NOTHROW;
108 
109 L4_INLINE void
l4_vcpu_e_write_64(void * vcpu,unsigned id,l4_uint64_t val)110 l4_vcpu_e_write_64(void *vcpu, unsigned id, l4_uint64_t val) L4_NOTHROW
111 { *((l4_uint64_t *)l4_vcpu_e_ptr(vcpu, id)) = val; }
112 
113 /**
114  * Read a natural register field from the extended vCPU state.
115  *
116  * \param vcpu  Pointer to the vCPU memory.
117  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
118  * \returns The value stored in the field.
119  */
120 L4_INLINE l4_umword_t
121 l4_vcpu_e_read(void const *vcpu, unsigned id) L4_NOTHROW;
122 
123 L4_INLINE l4_umword_t
l4_vcpu_e_read(void const * vcpu,unsigned id)124 l4_vcpu_e_read(void const *vcpu, unsigned id) L4_NOTHROW
125 { return *(l4_umword_t const *)l4_vcpu_e_ptr(vcpu, id); }
126 
127 /**
128  * Write a natural register field to the extended vCPU state.
129  *
130  * \param vcpu  Pointer to the vCPU memory.
131  * \param id    Field ID as defined in L4_vcpu_e_field_ids.
132  * \param val   The value to be written.
133  */
134 L4_INLINE void
135 l4_vcpu_e_write(void *vcpu, unsigned id, l4_umword_t val) L4_NOTHROW;
136 
137 L4_INLINE void
l4_vcpu_e_write(void * vcpu,unsigned id,l4_umword_t val)138 l4_vcpu_e_write(void *vcpu, unsigned id, l4_umword_t val) L4_NOTHROW
139 { *((l4_umword_t *)l4_vcpu_e_ptr(vcpu, id)) = val; }
140