RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Context.c
Go to the documentation of this file.
1 
11 #include "EfiScannerHeaders.h"
12 
13 
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 }
61 
62 
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 }
109 
110 
111 
112 
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 }
167 
168 
169 
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 }
223 
224 
225 
226 
227 VOID ContextX64Test(VOID)
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 }