The Pedigree Project  0.1
ppc32/state.cc
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 #include "pedigree/kernel/processor/state.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/processor/Processor.h"
23 
24 const char *PPC32InterruptStateRegisterName[40] = {
25  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
26  "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
27  "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29",
28  "r30", "r31", "lr", "ctr", "cr", "srr0", "srr1", "dsisr", "dar", "xer"};
29 
31  : m_IntNumber(0), m_Xer(0), m_Ctr(0), m_Lr(0), m_Cr(0), m_Srr0(0),
32  m_Srr1(0), m_Dsisr(0), m_Dar(0), m_R0(0), m_R1(), m_R2(0), m_R3(0),
33  m_R4(0), m_R5(0), m_R6(0), m_R7(0), m_R8(0), m_R9(0), m_R10(0), m_R11(0),
34  m_R12(0), m_R13(0), m_R14(0), m_R15(0), m_R16(0), m_R17(0), m_R18(0),
35  m_R19(0), m_R20(0), m_R21(0), m_R22(0), m_R23(0), m_R24(0), m_R25(0),
36  m_R26(0), m_R27(0), m_R28(0), m_R29(0), m_R30(0), m_R31(0)
37 {
38 }
39 
41  : m_IntNumber(is.m_IntNumber), m_Xer(is.m_Xer), m_Ctr(is.m_Ctr),
42  m_Lr(is.m_Lr), m_Cr(is.m_Cr), m_Srr0(is.m_Srr0), m_Srr1(is.m_Srr1),
43  m_Dsisr(is.m_Dsisr), m_Dar(is.m_Dar), m_R0(is.m_R0), m_R1(is.m_R1),
44  m_R2(is.m_R2), m_R3(is.m_R3), m_R4(is.m_R4), m_R5(is.m_R5), m_R6(is.m_R6),
45  m_R7(is.m_R7), m_R8(is.m_R8), m_R9(is.m_R9), m_R10(is.m_R10),
46  m_R11(is.m_R11), m_R12(is.m_R12), m_R13(is.m_R13), m_R14(is.m_R14),
47  m_R15(is.m_R15), m_R16(is.m_R16), m_R17(is.m_R17), m_R18(is.m_R18),
48  m_R19(is.m_R19), m_R20(is.m_R20), m_R21(is.m_R21), m_R22(is.m_R22),
49  m_R23(is.m_R23), m_R24(is.m_R24), m_R25(is.m_R25), m_R26(is.m_R26),
50  m_R27(is.m_R27), m_R28(is.m_R28), m_R29(is.m_R29), m_R30(is.m_R30),
51  m_R31(is.m_R31)
52 {
53 }
54 
57 {
59  m_Xer = is.m_Xer;
60  m_Ctr = is.m_Ctr;
61  m_Lr = is.m_Lr;
62  m_Cr = is.m_Cr;
63  m_Srr0 = is.m_Srr0;
64  m_Srr1 = is.m_Srr1;
65  m_Dsisr = is.m_Dsisr;
66  m_Dar = is.m_Dar;
67  m_R0 = is.m_R0;
68  m_R1 = is.m_R1;
69  m_R2 = is.m_R2;
70  m_R3 = is.m_R3;
71  m_R4 = is.m_R4;
72  m_R5 = is.m_R5;
73  m_R6 = is.m_R6;
74  m_R7 = is.m_R7;
75  m_R8 = is.m_R8;
76  m_R9 = is.m_R9;
77  m_R10 = is.m_R10;
78  m_R11 = is.m_R11;
79  m_R12 = is.m_R12;
80  m_R13 = is.m_R13;
81  m_R14 = is.m_R14;
82  m_R15 = is.m_R15;
83  m_R16 = is.m_R16;
84  m_R17 = is.m_R17;
85  m_R18 = is.m_R18;
86  m_R19 = is.m_R19;
87  m_R20 = is.m_R20;
88  m_R21 = is.m_R21;
89  m_R22 = is.m_R22;
90  m_R23 = is.m_R23;
91  m_R24 = is.m_R24;
92  m_R25 = is.m_R25;
93  m_R26 = is.m_R26;
94  m_R27 = is.m_R27;
95  m_R28 = is.m_R28;
96  m_R29 = is.m_R29;
97  m_R30 = is.m_R30;
98  m_R31 = is.m_R31;
99  return *this;
100 }
101 
103 {
104  return 40;
105 }
106 processor_register_t PPC32InterruptState::getRegister(size_t index) const
107 {
108  switch (index)
109  {
110  case 0:
111  return m_R0;
112  case 1:
113  return m_R1;
114  case 2:
115  return m_R2;
116  case 3:
117  return m_R3;
118  case 4:
119  return m_R4;
120  case 5:
121  return m_R5;
122  case 6:
123  return m_R6;
124  case 7:
125  return m_R7;
126  case 8:
127  return m_R8;
128  case 9:
129  return m_R9;
130  case 10:
131  return m_R10;
132  case 11:
133  return m_R11;
134  case 12:
135  return m_R12;
136  case 13:
137  return m_R13;
138  case 14:
139  return m_R14;
140  case 15:
141  return m_R15;
142  case 16:
143  return m_R16;
144  case 17:
145  return m_R17;
146  case 18:
147  return m_R18;
148  case 19:
149  return m_R19;
150  case 20:
151  return m_R20;
152  case 21:
153  return m_R21;
154  case 22:
155  return m_R22;
156  case 23:
157  return m_R23;
158  case 24:
159  return m_R24;
160  case 25:
161  return m_R25;
162  case 26:
163  return m_R26;
164  case 27:
165  return m_R27;
166  case 28:
167  return m_R28;
168  case 29:
169  return m_R29;
170  case 30:
171  return m_R30;
172  case 31:
173  return m_R31;
174  case 32:
175  return m_Lr;
176  case 33:
177  return m_Ctr;
178  case 34:
179  return m_Cr;
180  case 35:
181  return m_Srr0;
182  case 36:
183  return m_Srr1;
184  case 37:
185  return m_Dsisr;
186  case 38:
187  return m_Dar;
188  case 39:
189  return m_Xer;
190  default:
191  return 0;
192  }
193 }
194 const char *PPC32InterruptState::getRegisterName(size_t index) const
195 {
196  return PPC32InterruptStateRegisterName[index];
197 }
198 
200 PPC32InterruptState::construct(PPC32ProcessorState &state, bool userMode)
201 {
202  // Obtain the stack pointer.
203  uintptr_t *pStack = reinterpret_cast<uintptr_t *>(state.getStackPointer());
204 
205  uint32_t msr = MSR_IR | MSR_DR | MSR_EE | MSR_FP;
206  if (userMode)
207  msr |= MSR_PR;
208 
209  *--pStack = state.m_R31;
210  *--pStack = state.m_R30;
211  *--pStack = state.m_R29;
212  *--pStack = state.m_R28;
213  *--pStack = state.m_R27;
214  *--pStack = state.m_R26;
215  *--pStack = state.m_R25;
216  *--pStack = state.m_R24;
217  *--pStack = state.m_R23;
218  *--pStack = state.m_R22;
219  *--pStack = state.m_R21;
220  *--pStack = state.m_R20;
221  *--pStack = state.m_R19;
222  *--pStack = state.m_R18;
223  *--pStack = state.m_R17;
224  *--pStack = state.m_R16;
225  *--pStack = state.m_R15;
226  *--pStack = state.m_R14;
227  *--pStack = state.m_R13;
228  *--pStack = state.m_R12;
229  *--pStack = state.m_R11;
230  *--pStack = state.m_R10;
231  *--pStack = state.m_R9;
232  *--pStack = state.m_R8;
233  *--pStack = state.m_R7;
234  *--pStack = state.m_R6;
235  *--pStack = state.m_R5;
236  *--pStack = state.m_R4;
237  *--pStack = state.m_R3;
238  *--pStack = state.m_R2;
239  *--pStack = state.m_R1;
240  *--pStack = state.m_R0;
241  *--pStack = 0; // DAR
242  *--pStack = 0; // DSISR
243  *--pStack = msr; // SRR1
244  *--pStack = state.getInstructionPointer(); // SRR0
245  *--pStack = state.m_Cr;
246  *--pStack = state.m_Lr;
247  *--pStack = state.m_Ctr;
248  *--pStack = state.m_Xer;
249  *--pStack = 0; // IntNumber
250 
251  PPC32InterruptState *toRet =
252  reinterpret_cast<PPC32InterruptState *>(pStack);
253  return toRet;
254 }
const char * getRegisterName(size_t index) const
Definition: ppc32/state.cc:194
size_t getRegisterCount() const
Definition: ppc32/state.cc:102
processor_register_t getRegister(size_t index) const
Definition: ppc32/state.cc:106
PPC32InterruptState & operator=(const PPC32InterruptState &)
Definition: ppc32/state.cc:56
static PPC32InterruptState * construct(PPC32ProcessorState &state, bool userMode)
Definition: ppc32/state.cc:200