The Pedigree Project  0.1
hosted/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_HOSTED_STATE_H
21 #define KERNEL_PROCESSOR_HOSTED_STATE_H
22 
23 #include "pedigree/kernel/Log.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 
32 {
33  friend class HostedProcessorState;
34  friend class HostedInterruptManager;
35  friend class PageFaultHandler;
36 
37  public:
38  //
39  // General Interface (InterruptState, SyscallState & ProcessorState)
40  //
43  inline uintptr_t getStackPointer() const;
46  inline void setStackPointer(uintptr_t stackPointer);
50  inline uintptr_t getInstructionPointer() const;
53  inline void setInstructionPointer(uintptr_t instructionPointer);
56  inline uintptr_t getBasePointer() const;
59  inline void setBasePointer(uintptr_t basePointer);
60 
61  //
62  // General Interface (InterruptState & SyscallState)
63  //
66  size_t getRegisterCount() const;
70  processor_register_t getRegister(size_t index) const;
74  const char *getRegisterName(size_t index) const;
78  inline size_t getRegisterSize(size_t index) const;
79 
80  //
81  // InterruptState Interface
82  //
85  inline bool kernelMode() const;
88  inline size_t getInterruptNumber() const;
89 
92  inline uint64_t getFlags() const;
95  inline void setFlags(uint64_t flags);
96 
99  static HostedInterruptState *
100  construct(class HostedProcessorState &state, bool userMode);
101 
102  private:
113 
117  uint64_t state;
119  uint64_t which;
121  uint64_t extra;
126  uint64_t meta;
127 
129  uintptr_t m_basePointer;
130  uintptr_t m_instructionPointer;
131  uintptr_t m_stackPointer;
132 } PACKED;
133 
136 {
137  friend class HostedProcessorState;
138  friend class HostedSyscallManager;
139 
140  public:
141  //
142  // General Interface (InterruptState, SyscallState & ProcessorState)
143  //
146  inline uintptr_t getStackPointer() const;
149  inline void setStackPointer(uintptr_t stackPointer);
153  inline uintptr_t getInstructionPointer() const;
156  inline void setInstructionPointer(uintptr_t instructionPointer);
159  inline uintptr_t getBasePointer() const;
162  inline void setBasePointer(uintptr_t basePointer);
163 
164  //
165  // General Interface (InterruptState & SyscallState)
166  //
169  size_t getRegisterCount() const;
173  processor_register_t getRegister(size_t index) const;
177  const char *getRegisterName(size_t index) const;
181  inline size_t getRegisterSize(size_t index) const;
182 
183  //
184  // SyscallState Interface
185  //
188  inline size_t getSyscallService() const;
191  inline size_t getSyscallNumber() const;
193  inline uintptr_t getSyscallParameter(size_t n) const;
194  inline void setSyscallReturnValue(uintptr_t val);
195  inline void setSyscallErrno(uintptr_t val);
196 
197  public:
198  uint64_t service;
199  uint64_t number;
200  uint64_t p1, p2, p3, p4, p5;
201  uint64_t error;
202  uint64_t error_ptr; // pointer to error
203  uint64_t result;
204  uint64_t rsp;
205  uint64_t _align0; // deterministically pad to 16 bytes
206 } PACKED;
207 
210 {
211  public:
213  inline HostedProcessorState();
231  inline ~HostedProcessorState();
232 
233  //
234  // General Interface (InterruptState, SyscallState & ProcessorState)
235  //
238  inline uintptr_t getStackPointer() const;
241  inline void setStackPointer(uintptr_t stackPointer);
245  inline uintptr_t getInstructionPointer() const;
248  inline void setInstructionPointer(uintptr_t instructionPointer);
251  inline uintptr_t getBasePointer() const;
254  inline void setBasePointer(uintptr_t basePointer);
255 
256  uint64_t state;
257 };
258 
261 {
262  public:
263  uint64_t state[128];
264 };
265 
268 //
269 // Part of the Implementation
270 //
272 {
273  return m_stackPointer;
274 }
275 void HostedInterruptState::setStackPointer(uintptr_t stackPointer)
276 {
277  m_stackPointer = stackPointer;
278 }
280 {
281  return m_instructionPointer;
282 }
283 void HostedInterruptState::setInstructionPointer(uintptr_t instructionPointer)
284 {
285  m_instructionPointer = instructionPointer;
286 }
288 {
289  return m_basePointer;
290 }
291 void HostedInterruptState::setBasePointer(uintptr_t basePointer)
292 {
293  m_basePointer = basePointer;
294 }
295 size_t HostedInterruptState::getRegisterSize(size_t index) const
296 {
297  return sizeof(processor_register_t);
298 }
299 
301 {
302  return true;
303 }
305 {
306  return which;
307 }
308 
310 {
311  return 0;
312 }
313 void HostedInterruptState::setFlags(uint64_t flags)
314 {
315 }
316 
318 {
319  return rsp;
320 }
321 void HostedSyscallState::setStackPointer(uintptr_t stackPointer)
322 {
323  rsp = stackPointer;
324 }
326 {
327  return 0;
328 }
329 void HostedSyscallState::setInstructionPointer(uintptr_t instructionPointer)
330 {
331 }
333 {
334  return 0;
335 }
336 void HostedSyscallState::setBasePointer(uintptr_t basePointer)
337 {
338 }
339 size_t HostedSyscallState::getRegisterSize(size_t index) const
340 {
341  return sizeof(processor_register_t);
342 }
343 
345 {
346  return service;
347 }
349 {
350  return number;
351 }
353 {
354  if (n == 0)
355  return p1;
356  if (n == 1)
357  return p2;
358  if (n == 2)
359  return p3;
360  if (n == 3)
361  return p4;
362  if (n == 4)
363  return p5;
364  return 0;
365 }
366 void HostedSyscallState::setSyscallReturnValue(uintptr_t val)
367 {
368  result = val;
369 }
370 void HostedSyscallState::setSyscallErrno(uintptr_t val)
371 {
372  error = val;
373 }
374 
376 {
377 }
379  : state(x.state)
380 {
381 }
383  : state(x.state)
384 {
385 }
387 {
388 }
391 {
392  state = x.state;
393  return *this;
394 }
397 {
398  state = x.state;
399  return *this;
400 }
403 {
404  return *this;
405 }
407 {
408 }
409 
411 {
412  return 0;
413 }
414 void HostedProcessorState::setStackPointer(uintptr_t stackPointer)
415 {
416 }
418 {
419  return 0;
420 }
421 void HostedProcessorState::setInstructionPointer(uintptr_t instructionPointer)
422 {
423 }
425 {
426  return 0;
427 }
428 void HostedProcessorState::setBasePointer(uintptr_t basePointer)
429 {
430 }
431 
432 #endif
uintptr_t getStackPointer() const
Definition: hosted/state.h:271
size_t getSyscallNumber() const
Definition: hosted/state.h:348
void setStackPointer(uintptr_t stackPointer)
Definition: hosted/state.h:414
void setBasePointer(uintptr_t basePointer)
Definition: hosted/state.h:428
uintptr_t getStackPointer() const
Definition: hosted/state.h:317
size_t getRegisterSize(size_t index) const
Definition: hosted/state.h:339
void setInstructionPointer(uintptr_t instructionPointer)
Definition: hosted/state.h:421
size_t getInterruptNumber() const
Definition: hosted/state.h:304
uintptr_t getStackPointer() const
Definition: hosted/state.h:410
uintptr_t getInstructionPointer() const
Definition: hosted/state.h:417
void setBasePointer(uintptr_t basePointer)
Definition: hosted/state.h:291
size_t getRegisterCount() const
Definition: hosted/state.cc:36
void setStackPointer(uintptr_t stackPointer)
Definition: hosted/state.h:275
size_t getRegisterSize(size_t index) const
Definition: hosted/state.h:295
HostedProcessorState & operator=(const HostedProcessorState &)
Definition: hosted/state.h:390
uintptr_t getInstructionPointer() const
Definition: hosted/state.h:279
size_t getSyscallService() const
Definition: hosted/state.h:344
void setBasePointer(uintptr_t basePointer)
Definition: hosted/state.h:336
processor_register_t getRegister(size_t index) const
Definition: hosted/state.cc:40
void setInstructionPointer(uintptr_t instructionPointer)
Definition: hosted/state.h:329
const char * getRegisterName(size_t index) const
Definition: hosted/state.cc:50
void setInstructionPointer(uintptr_t instructionPointer)
Definition: hosted/state.h:283
static HostedInterruptState * construct(class HostedProcessorState &state, bool userMode)
Definition: hosted/state.cc:71
bool kernelMode() const
Definition: hosted/state.h:300
uintptr_t getBasePointer() const
Definition: hosted/state.h:287
uintptr_t getBasePointer() const
Definition: hosted/state.h:332
HostedInterruptState & operator=(const HostedInterruptState &)
void setFlags(uint64_t flags)
Definition: hosted/state.h:313
uintptr_t getBasePointer() const
Definition: hosted/state.h:424
uintptr_t getInstructionPointer() const
Definition: hosted/state.h:325
uintptr_t getSyscallParameter(size_t n) const
Definition: hosted/state.h:352
void setStackPointer(uintptr_t stackPointer)
Definition: hosted/state.h:321
uint64_t getFlags() const
Definition: hosted/state.h:309