The Pedigree Project  0.1
x86/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 
22 const char *X86InterruptStateRegisterName[11] = {
23  "eax", "ebx", "ecx", "edx", "edi", "esi", "ebp", "esp", "eip", "eflags"};
24 
26 {
27  return 10;
28 }
29 processor_register_t X86InterruptState::getRegister(size_t index) const
30 {
31  if (index == 0)
32  return m_Eax;
33  if (index == 1)
34  return m_Ebx;
35  if (index == 2)
36  return m_Ecx;
37  if (index == 3)
38  return m_Edx;
39  if (index == 4)
40  return m_Edi;
41  if (index == 5)
42  return m_Esi;
43  if (index == 6)
44  return m_Ebp;
45  if (index == 7)
46  return getStackPointer();
47  if (index == 8)
48  return m_Eip;
49  if (index == 9)
50  return m_Eflags;
51  return 0;
52 }
53 const char *X86InterruptState::getRegisterName(size_t index) const
54 {
55  return X86InterruptStateRegisterName[index];
56 }
57 
60 {
61  // Obtain the stack pointer.
62  uintptr_t *pStack = reinterpret_cast<uintptr_t *>(state.getStackPointer());
63 
64  if (userMode)
65  {
66  *--pStack = (userMode) ? 0x23 : 0x10; // SS
67  *--pStack = state.esp; // ESP
68  }
69  *--pStack = 0x200; // EFLAGS - IF enabled.
70  *--pStack = (userMode) ? 0x1b : 0x08; // CS
71  *--pStack = state.eip; // EIP
72  *--pStack = 0; // Error code
73  *--pStack = 0; // Interrupt number
74  *--pStack = state.eax; // EAX
75  *--pStack = state.ecx; // ECX
76  *--pStack = state.edx; // EDX
77  *--pStack = state.ebx; // EBX
78  *--pStack = 0; // Reserved/unused
79  *--pStack = state.ebp; // EBP
80  *--pStack = state.esi; // ESI
81  *--pStack = state.edi; // EDI
82  *--pStack = (userMode) ? 0x23 : 0x10; // DS.
83 
84  X86InterruptState *toRet = reinterpret_cast<X86InterruptState *>(pStack);
85 
86  return toRet;
87 }
uint32_t m_Edi
Definition: x86/state.h:132
processor_register_t getRegister(size_t index) const
Definition: x86/state.cc:29
uint32_t m_Ebx
Definition: x86/state.h:140
size_t getRegisterCount() const
Definition: x86/state.cc:25
static X86InterruptState * construct(class X86ProcessorState &state, bool userMode)
Definition: x86/state.cc:59
uint32_t m_Esi
Definition: x86/state.h:134
uint32_t m_Edx
Definition: x86/state.h:142
uint32_t m_Eip
Definition: x86/state.h:152
uint32_t m_Eax
Definition: x86/state.h:146
uintptr_t getStackPointer() const
Definition: x86/state.h:255
uint32_t m_Eflags
Definition: x86/state.h:156
const char * getRegisterName(size_t index) const
Definition: x86/state.cc:53
uintptr_t getStackPointer() const
Definition: x86/state.h:384
uint32_t m_Ebp
Definition: x86/state.h:136
uint32_t m_Ecx
Definition: x86/state.h:144