The Pedigree Project  0.1
ppc32/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_MIPS32_STATE_H
21 #define KERNEL_PROCESSOR_MIPS32_STATE_H
22 
23 #include "pedigree/kernel/Log.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 
30 typedef class PPC32InterruptState PPC32SyscallState;
31 typedef class PPC32InterruptState PPC32ProcessorState;
32 
35 {
36  public:
37  //
38  // General Interface (both InterruptState and SyscallState)
39  //
42  inline uintptr_t getStackPointer() const;
45  inline void setStackPointer(uintptr_t stackPointer);
49  inline uintptr_t getInstructionPointer() const;
52  inline void setInstructionPointer(uintptr_t instructionPointer);
55  inline uintptr_t getBasePointer() const;
58  inline void setBasePointer(uintptr_t basePointer);
61  size_t getRegisterCount() const;
65  processor_register_t getRegister(size_t index) const;
69  const char *getRegisterName(size_t index) const;
73  inline size_t getRegisterSize(size_t index) const;
74 
75  //
76  // InterruptState Interface
77  //
80  inline bool kernelMode() const;
83  inline size_t getInterruptNumber() const;
84 
85  //
86  // SyscallState Interface
87  //
90  inline size_t getSyscallService() const;
93  inline size_t getSyscallNumber() const;
94  inline uintptr_t getSyscallParameter(size_t n) const;
95  inline void setSyscallReturnValue(uintptr_t val);
96 
99  static PPC32InterruptState *
100  construct(PPC32ProcessorState &state, bool userMode);
101 
102  private:
105  public:
107 
117  {
118  }
119 
121  uint32_t m_IntNumber;
123  uint32_t m_Xer;
125  uint32_t m_Ctr;
127  uint32_t m_Lr;
129  uint32_t m_Cr;
131  uint32_t m_Srr0;
133  uint32_t m_Srr1;
135  uint32_t m_Dsisr;
137  uint32_t m_Dar;
139  uint32_t m_R0;
141  uint32_t m_R1;
143  uint32_t m_R2;
145  uint32_t m_R3;
147  uint32_t m_R4;
149  uint32_t m_R5;
151  uint32_t m_R6;
153  uint32_t m_R7;
155  uint32_t m_R8;
157  uint32_t m_R9;
159  uint32_t m_R10;
161  uint32_t m_R11;
163  uint32_t m_R12;
165  uint32_t m_R13;
167  uint32_t m_R14;
169  uint32_t m_R15;
171  uint32_t m_R16;
173  uint32_t m_R17;
175  uint32_t m_R18;
177  uint32_t m_R19;
179  uint32_t m_R20;
181  uint32_t m_R21;
183  uint32_t m_R22;
185  uint32_t m_R23;
187  uint32_t m_R24;
189  uint32_t m_R25;
191  uint32_t m_R26;
193  uint32_t m_R27;
195  uint32_t m_R28;
197  uint32_t m_R29;
199  uint32_t m_R30;
201  uint32_t m_R31;
202 } PACKED;
203 
205 {
206 } PACKED;
207 
210 //
211 // Part of the Implementation
212 //
213 
215 {
216  return m_R1;
217 }
218 void PPC32InterruptState::setStackPointer(uintptr_t stackPointer)
219 {
220  m_R1 = stackPointer;
221 }
223 {
224  return m_Srr0;
225 }
226 void PPC32InterruptState::setInstructionPointer(uintptr_t instructionPointer)
227 {
228  m_Srr0 = instructionPointer;
229 }
231 {
232  return 0xdeadbaba;
233 }
234 void PPC32InterruptState::setBasePointer(uintptr_t basePointer)
235 {
236 }
237 size_t PPC32InterruptState::getRegisterSize(size_t index) const
238 {
239  return 4;
240 }
241 
243 {
244  return m_Srr1 & (1 << 15);
245 }
247 {
248  return m_IntNumber;
249 }
250 
252 {
253  return ((m_R3 >> 16) & 0xFFFF);
254 }
256 {
257  return (m_R3 & 0xFFFF);
258 }
259 uintptr_t PPC32InterruptState::getSyscallParameter(size_t n) const
260 {
261  switch (n)
262  {
263  case 0:
264  return m_R6;
265  case 1:
266  return m_R7;
267  case 2:
268  return m_R8;
269  case 3:
270  return m_R9;
271  case 4:
272  return m_R10;
273  default:
274  WARNING("Bad syscall parameter requested: " << Dec << n);
275  return 0;
276  }
277 }
278 void PPC32InterruptState::setSyscallReturnValue(uintptr_t val)
279 {
280  m_R3 = val;
281 }
282 
283 #endif
void setInstructionPointer(uintptr_t instructionPointer)
Definition: ppc32/state.h:226
uintptr_t getInstructionPointer() const
Definition: ppc32/state.h:222
size_t getInterruptNumber() const
Definition: ppc32/state.h:246
void setBasePointer(uintptr_t basePointer)
Definition: ppc32/state.h:234
const char * getRegisterName(size_t index) const
Definition: ppc32/state.cc:194
void setStackPointer(uintptr_t stackPointer)
Definition: ppc32/state.h:218
size_t getSyscallService() const
Definition: ppc32/state.h:251
bool kernelMode() const
Definition: ppc32/state.h:242
#define WARNING(text)
Definition: Log.h:78
size_t getRegisterCount() const
Definition: ppc32/state.cc:102
uintptr_t getBasePointer() const
Definition: ppc32/state.h:230
processor_register_t getRegister(size_t index) const
Definition: ppc32/state.cc:106
size_t getSyscallNumber() const
Definition: ppc32/state.h:255
PPC32InterruptState & operator=(const PPC32InterruptState &)
Definition: ppc32/state.cc:56
uintptr_t getStackPointer() const
Definition: ppc32/state.h:214
size_t getRegisterSize(size_t index) const
Definition: ppc32/state.h:237
Definition: Log.h:138
static PPC32InterruptState * construct(PPC32ProcessorState &state, bool userMode)
Definition: ppc32/state.cc:200