RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Context.c File Reference

Functions for obtaining the CPU context state (x86 and x64) More...

Include dependency graph for Context.c:

Go to the source code of this file.

Macros

#define LOG_VALUE(name, val)   LogFullAscii(name, val);
 
#define LOG_VALUE(name, val)   LogFullAscii(name, val);
 

Functions

EFI_STATUS GetX64Context (x64_context *Context)
 
EFI_STATUS GetX86Context (x86_context *Context)
 
EFI_STATUS DisplayLogX64Context (x64_context *Context)
 
EFI_STATUS DisplayLogX86Context (x86_context *Context)
 
VOID ContextX64Test (VOID)
 

Detailed Description

Functions for obtaining the CPU context state (x86 and x64)

Author
Piotr Bania
Date
Feb 2013 Functions for obtaining the CPU context state (x86 and x64)

Definition in file Context.c.

Macro Definition Documentation

#define LOG_VALUE (   name,
  val 
)    LogFullAscii(name, val);
#define LOG_VALUE (   name,
  val 
)    LogFullAscii(name, val);

Function Documentation

VOID ContextX64Test ( VOID  )

Definition at line 227 of file Context.c.

References DisplayLogX64Context(), DisplayLogX86Context(), GetX64Context(), and GetX86Context().

Referenced by ProcessCommand(), and TestDumpHandles().

228 {
229 
230 #if defined(_WIN64)
231  x64_context Context;
232  GetX64Context(&Context);
233  DisplayLogX64Context(&Context);
234 #else
235  x86_context ContextX86;
236  GetX86Context(&ContextX86);
237  DisplayLogX86Context(&ContextX86);
238 
239 #endif
240 
241 
242 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DisplayLogX64Context ( x64_context *  Context)

Function displays the X64 context structure.

Parameters
ContextPointer to x64_context structure
Return values
EFI_SUCCESS

Definition at line 123 of file Context.c.

References _x64_context::_Cr0, _x64_context::_Cr2, _x64_context::_Cr3, _x64_context::_Cr4, _x64_context::_Cr8, _x64_context::_Cs, _x64_context::_Dr0, _x64_context::_Dr2, _x64_context::_Dr3, _x64_context::_Dr6, _x64_context::_Dr7, _x64_context::_Ds, _x64_context::_Es, _x64_context::_Fs, _x64_context::_Gs, _x64_context::_Rax, _x64_context::_Rbp, _x64_context::_Rbx, _x64_context::_Rcx, _x64_context::_Rdi, _x64_context::_Rdx, _x64_context::_Rflags, _x64_context::_Rsi, _x64_context::_Rsp, _x64_context::_Ss, LOG_VALUE, and LogFullAscii().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

124 {
125 
126 #define LOG_VALUE(name, val) LogFullAscii(name, val);
127 
128  LogFullAscii("----- X64 CONTEXT DUMP -----\r\n");
129 
130  LOG_VALUE("Rax = %016lx\r\n", Context->_Rax);
131  LOG_VALUE("Rbx = %016lx\r\n", Context->_Rbx);
132  LOG_VALUE("Rcx = %016lx\r\n", Context->_Rcx);
133  LOG_VALUE("Rdx = %016lx\r\n", Context->_Rdx);
134  LOG_VALUE("Rsi = %016lx\r\n", Context->_Rsi);
135  LOG_VALUE("Rdi = %016lx\r\n", Context->_Rdi);
136  LOG_VALUE("Rbp = %016lx\r\n", Context->_Rbp);
137  LOG_VALUE("Rsp = %016lx\r\n", Context->_Rsp);
138 
139 
140  LOG_VALUE("Dr0 = %016lx\r\n", Context->_Dr0);
141  LOG_VALUE("Dr2 = %016lx\r\n", Context->_Dr2);
142  LOG_VALUE("Dr3 = %016lx\r\n", Context->_Dr3);
143  LOG_VALUE("Dr6 = %016lx\r\n", Context->_Dr6);
144  LOG_VALUE("Dr7 = %016lx\r\n", Context->_Dr7);
145 
146  LOG_VALUE("Cr0 = %016lx\r\n", Context->_Cr0);
147  LOG_VALUE("Cr2 = %016lx\r\n", Context->_Cr2);
148  LOG_VALUE("Cr3 = %016lx\r\n", Context->_Cr3);
149  LOG_VALUE("Cr4 = %016lx\r\n", Context->_Cr4);
150  LOG_VALUE("Cr8 = %016lx\r\n", Context->_Cr8);
151 
152  LOG_VALUE("Rflags = %016lx\r\n", Context->_Rflags);
153 
154  LOG_VALUE("Cs = %04x\r\n", Context->_Cs);
155  LOG_VALUE("Ds = %04x\r\n", Context->_Ds);
156  LOG_VALUE("Es = %04x\r\n", Context->_Es);
157  LOG_VALUE("Fs = %04x\r\n", Context->_Fs);
158  LOG_VALUE("Gs = %04x\r\n", Context->_Gs);
159  LOG_VALUE("Ss = %04x\r\n", Context->_Ss);
160 
161 
162 #undef LOG_VALUE
163 
164 
165  return EFI_SUCCESS;
166 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DisplayLogX86Context ( x86_context *  Context)

Function displays the X86 context structure.

Parameters
ContextPointer to x86_context structure
Return values
EFI_SUCCESS

Definition at line 180 of file Context.c.

References _x86_context::_Cr0, _x86_context::_Cr2, _x86_context::_Cr3, _x86_context::_Cr4, _x86_context::_Cs, _x86_context::_Dr0, _x86_context::_Dr2, _x86_context::_Dr3, _x86_context::_Dr6, _x86_context::_Dr7, _x86_context::_Ds, _x86_context::_Eax, _x86_context::_Ebp, _x86_context::_Ebx, _x86_context::_Ecx, _x86_context::_Edi, _x86_context::_Edx, _x86_context::_Eflags, _x86_context::_Es, _x86_context::_Esi, _x86_context::_Esp, _x86_context::_Fs, _x86_context::_Gs, _x86_context::_Ss, LOG_VALUE, and LogFullAscii().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

181 {
182 
183 #define LOG_VALUE(name, val) LogFullAscii(name, val);
184 
185  LogFullAscii("----- X64 CONTEXT DUMP -----\r\n");
186 
187  LOG_VALUE("Rax = %08x\r\n", Context->_Eax);
188  LOG_VALUE("Rbx = %08x\r\n", Context->_Ebx);
189  LOG_VALUE("Rcx = %08x\r\n", Context->_Ecx);
190  LOG_VALUE("Rdx = %08x\r\n", Context->_Edx);
191  LOG_VALUE("Rsi = %08x\r\n", Context->_Esi);
192  LOG_VALUE("Rdi = %08x\r\n", Context->_Edi);
193  LOG_VALUE("Rbp = %08x\r\n", Context->_Ebp);
194  LOG_VALUE("Rsp = %08x\r\n", Context->_Esp);
195 
196 
197  LOG_VALUE("Dr0 = %08x\r\n", Context->_Dr0);
198  LOG_VALUE("Dr2 = %08x\r\n", Context->_Dr2);
199  LOG_VALUE("Dr3 = %08x\r\n", Context->_Dr3);
200  LOG_VALUE("Dr6 = %08x\r\n", Context->_Dr6);
201  LOG_VALUE("Dr7 = %08x\r\n", Context->_Dr7);
202 
203  LOG_VALUE("Cr0 = %08x\r\n", Context->_Cr0);
204  LOG_VALUE("Cr2 = %08x\r\n", Context->_Cr2);
205  LOG_VALUE("Cr3 = %08x\r\n", Context->_Cr3);
206  LOG_VALUE("Cr4 = %08x\r\n", Context->_Cr4);
207 
208  LOG_VALUE("Eflags = %08x\r\n", Context->_Eflags);
209 
210  LOG_VALUE("Cs = %04x\r\n", Context->_Cs);
211  LOG_VALUE("Ds = %04x\r\n", Context->_Ds);
212  LOG_VALUE("Es = %04x\r\n", Context->_Es);
213  LOG_VALUE("Fs = %04x\r\n", Context->_Fs);
214  LOG_VALUE("Gs = %04x\r\n", Context->_Gs);
215  LOG_VALUE("Ss = %04x\r\n", Context->_Ss);
216 
217 
218 #undef LOG_VALUE
219 
220 
221  return EFI_SUCCESS;
222 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS GetX64Context ( x64_context *  Context)

Function fills the X64 Context structure.

Parameters
ContextPointer to x64_context structure
Return values
EFI_SUCCESS

Definition at line 24 of file Context.c.

References _x64_context::_Cr0, _x64_context::_Cr2, _x64_context::_Cr3, _x64_context::_Cr4, _x64_context::_Cr8, _x64_context::_Cs, _x64_context::_Dr0, _x64_context::_Dr2, _x64_context::_Dr3, _x64_context::_Dr6, _x64_context::_Dr7, _x64_context::_Ds, _x64_context::_Es, _x64_context::_Fs, _x64_context::_Gs, _x64_context::_Rax, _x64_context::_Rbp, _x64_context::_Rbx, _x64_context::_Rcx, _x64_context::_Rdi, _x64_context::_Rdx, _x64_context::_Rflags, _x64_context::_Rsi, _x64_context::_Rsp, _x64_context::_Ss, ASMGetRegCr0(), ASMGetRegCr2(), ASMGetRegCr3(), ASMGetRegCr4(), ASMGetRegCr8(), ASMGetRegCs(), ASMGetRegDr0(), ASMGetRegDr2(), ASMGetRegDr3(), ASMGetRegDr6(), ASMGetRegDr7(), ASMGetRegDs(), ASMGetRegEs(), ASMGetRegFs(), ASMGetRegGs(), ASMGetRegRax(), ASMGetRegRbp(), ASMGetRegRbx(), ASMGetRegRcx(), ASMGetRegRdi(), ASMGetRegRdx(), ASMGetRegRflags(), ASMGetRegRsi(), ASMGetRegRsp(), and ASMGetRegSs().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

25 {
26 
27  Context->_Rax = ASMGetRegRax();
28  Context->_Rbx = ASMGetRegRbx();
29  Context->_Rcx = ASMGetRegRcx();
30  Context->_Rdx = ASMGetRegRdx();
31  Context->_Rsi = ASMGetRegRsi();
32  Context->_Rdi = ASMGetRegRdi();
33  Context->_Rbp = ASMGetRegRbp();
34  Context->_Rsp = ASMGetRegRsp();
35 
36  Context->_Rflags = ASMGetRegRflags();
37 
38 
39  Context->_Cs = ASMGetRegCs();
40  Context->_Ds = ASMGetRegDs();
41  Context->_Es = ASMGetRegEs();
42  Context->_Fs = ASMGetRegFs();
43  Context->_Gs = ASMGetRegGs();
44  Context->_Ss = ASMGetRegSs();
45 
46  Context->_Dr0 = ASMGetRegDr0();
47  Context->_Dr2 = ASMGetRegDr2();
48  Context->_Dr3 = ASMGetRegDr3();
49  Context->_Dr6 = ASMGetRegDr6();
50  Context->_Dr7 = ASMGetRegDr7();
51 
52  Context->_Cr0 = ASMGetRegCr0();
53  Context->_Cr2 = ASMGetRegCr2();
54  Context->_Cr3 = ASMGetRegCr3();
55  Context->_Cr4 = ASMGetRegCr4();
56  Context->_Cr8 = ASMGetRegCr8();
57 
58 
59  return EFI_SUCCESS;
60 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS GetX86Context ( x86_context *  Context)

Function fills the X86 Context structure.

Parameters
ContextPointer to x86_context structure
Return values
EFI_SUCCESS

Definition at line 73 of file Context.c.

References _x86_context::_Cr0, _x86_context::_Cr2, _x86_context::_Cr3, _x86_context::_Cr4, _x86_context::_Cs, _x86_context::_Dr0, _x86_context::_Dr2, _x86_context::_Dr3, _x86_context::_Dr6, _x86_context::_Dr7, _x86_context::_Ds, _x86_context::_Eax, _x86_context::_Ebp, _x86_context::_Ebx, _x86_context::_Ecx, _x86_context::_Edi, _x86_context::_Edx, _x86_context::_Eflags, _x86_context::_Es, _x86_context::_Esi, _x86_context::_Esp, _x86_context::_Fs, _x86_context::_Gs, _x86_context::_Ss, ASMGetRegCr0(), ASMGetRegCr2(), ASMGetRegCr3(), ASMGetRegCr4(), ASMGetRegCs(), ASMGetRegDr0(), ASMGetRegDr2(), ASMGetRegDr3(), ASMGetRegDr6(), ASMGetRegDr7(), ASMGetRegDs(), ASMGetRegEs(), ASMGetRegFs(), ASMGetRegGs(), ASMGetRegRax(), ASMGetRegRbp(), ASMGetRegRbx(), ASMGetRegRcx(), ASMGetRegRdi(), ASMGetRegRdx(), ASMGetRegRflags(), ASMGetRegRsi(), ASMGetRegRsp(), and ASMGetRegSs().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

74 {
75 
76  Context->_Eax = (ULONG)ASMGetRegRax();
77  Context->_Ebx = (ULONG)ASMGetRegRbx();
78  Context->_Ecx = (ULONG)ASMGetRegRcx();
79  Context->_Edx = (ULONG)ASMGetRegRdx();
80  Context->_Esi = (ULONG)ASMGetRegRsi();
81  Context->_Edi = (ULONG)ASMGetRegRdi();
82  Context->_Ebp = (ULONG)ASMGetRegRbp();
83  Context->_Esp = (ULONG)ASMGetRegRsp();
84 
85  Context->_Eflags = (ULONG)ASMGetRegRflags();
86 
87  Context->_Cs = ASMGetRegCs();
88  Context->_Ds = ASMGetRegDs();
89  Context->_Es = ASMGetRegEs();
90  Context->_Fs = ASMGetRegFs();
91  Context->_Gs = ASMGetRegGs();
92  Context->_Ss = ASMGetRegSs();
93 
94  Context->_Dr0 = (ULONG)ASMGetRegDr0();
95  Context->_Dr2 = (ULONG)ASMGetRegDr2();
96  Context->_Dr3 = (ULONG)ASMGetRegDr3();
97  Context->_Dr6 = (ULONG)ASMGetRegDr6();
98  Context->_Dr7 = (ULONG)ASMGetRegDr7();
99 
100  Context->_Cr0 = (ULONG)ASMGetRegCr0();
101  Context->_Cr2 = (ULONG)ASMGetRegCr2();
102  Context->_Cr3 = (ULONG)ASMGetRegCr3();
103  Context->_Cr4 = (ULONG)ASMGetRegCr4();
104  //Context->_Cr8 = ASMGetRegCr8();
105 
106 
107  return EFI_SUCCESS;
108 }

Here is the call graph for this function:

Here is the caller graph for this function: