The Pedigree Project  0.1
armv7/state.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_ARMV7_STATE_H
21 #define KERNEL_PROCESSOR_ARMV7_STATE_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
31 {
32  public:
33  //
34  // General Interface (both InterruptState and SyscallState)
35  //
38  inline uintptr_t getStackPointer() const;
41  inline void setStackPointer(uintptr_t stackPointer);
45  inline uintptr_t getInstructionPointer() const;
48  inline void setInstructionPointer(uintptr_t instructionPointer);
51  inline uintptr_t getBasePointer() const;
54  inline void setBasePointer(uintptr_t basePointer);
57  size_t getRegisterCount() const;
61  processor_register_t getRegister(size_t index) const;
65  const char *getRegisterName(size_t index) const;
69  inline size_t getRegisterSize(size_t index) const;
70 
71  //
72  // InterruptState Interface
73  //
76  inline bool kernelMode() const;
79  inline size_t getInterruptNumber() const;
80 
81  //
82  // SyscallState Interface
83  //
86  inline size_t getSyscallService() const;
89  inline size_t getSyscallNumber() const;
91  inline uintptr_t getSyscallParameter(size_t n) const;
92  inline void setSyscallReturnValue(uintptr_t val);
93 
94  private:
97  public:
99 
109  {
110  }
111 
113  uint32_t m_usersp;
114  uint32_t m_userlr;
115  uint32_t m_r0;
116  uint32_t m_r1;
117  uint32_t m_r2;
118  uint32_t m_r3;
119  uint32_t m_r4;
120  uint32_t m_r5;
121  uint32_t m_r6;
122  uint32_t m_r7;
123  uint32_t m_r8;
124  uint32_t m_r9;
125  uint32_t m_r10;
126  uint32_t m_r11;
127  uint32_t m_r12;
128  uint32_t m_lr;
129  uint32_t m_pc;
130  uint32_t m_spsr;
131 } PACKED;
132 
135 
136 class __attribute__((aligned(8))) ARMV7SchedulerState
137 {
138  public:
139  uint32_t r4;
140  uint32_t r5;
141  uint32_t r6;
142  uint32_t r7;
143  uint32_t r8;
144  uint32_t r9;
145  uint32_t r10;
146  uint32_t r11;
147  uint32_t r12;
148  uint32_t sp;
149  uint32_t lr;
150 } __attribute__((aligned(8)));
151 
154 //
155 // Part of the Implementation
156 //
157 
159 {
160  return m_usersp;
161 }
162 void ARMV7InterruptState::setStackPointer(uintptr_t stackPointer)
163 {
164  m_usersp = stackPointer;
165 }
167 {
168  return m_pc;
169 }
170 void ARMV7InterruptState::setInstructionPointer(uintptr_t instructionPointer)
171 {
172  m_pc = instructionPointer;
173 }
175 {
176  return m_r11;
177 }
178 void ARMV7InterruptState::setBasePointer(uintptr_t basePointer)
179 {
180  m_r11 = basePointer;
181 }
182 size_t ARMV7InterruptState::getRegisterSize(size_t index) const
183 {
184 #if defined(BITS_32)
185  return 4;
186 #else
187  return 4; // TODO: handle other bits sizes (this is mainly here)
188  // in order to help future development if ARM ends up
189  // requiring 64-bit or something
190 #endif
191 }
192 
194 {
195  uint32_t cpsr;
196  asm volatile("mrs %0, cpsr" : "=r"(cpsr));
197  return ((cpsr & 0x1F) != 0x10);
198 }
200 {
202  return 0;
203 }
204 
206 {
208  return 0;
209 }
211 {
213  return 0;
214 }
216 {
217  return 0;
218 }
219 void ARMV7InterruptState::setSyscallReturnValue(uintptr_t val)
220 {
221 }
222 
223 #endif
size_t getRegisterSize(size_t index) const
Definition: armv7/state.h:182
void setInstructionPointer(uintptr_t instructionPointer)
Definition: armv7/state.h:170
void setStackPointer(uintptr_t stackPointer)
Definition: armv7/state.h:162
ARMV7InterruptState & operator=(const ARMV7InterruptState &)
Definition: armv7/state.cc:44
const char * getRegisterName(size_t index) const
Definition: armv7/state.cc:113
processor_register_t getRegister(size_t index) const
Definition: armv7/state.cc:69
void setBasePointer(uintptr_t basePointer)
Definition: armv7/state.h:178
bool kernelMode() const
Definition: armv7/state.h:193
uintptr_t getStackPointer() const
Definition: armv7/state.h:158
size_t getSyscallService() const
Definition: armv7/state.h:205
size_t getInterruptNumber() const
Definition: armv7/state.h:199
uintptr_t getBasePointer() const
Definition: armv7/state.h:174
uintptr_t getInstructionPointer() const
Definition: armv7/state.h:166
uintptr_t getSyscallParameter(size_t n) const
Definition: armv7/state.h:215
size_t getSyscallNumber() const
Definition: armv7/state.h:210
size_t getRegisterCount() const
Definition: armv7/state.cc:65