ReactOS 0.4.16-dev-106-g10b08aa
amd64_sup.c File Reference
#include "kdgdb.h"
Include dependency graph for amd64_sup.c:

Go to the source code of this file.

Enumerations

enum  reg_name {
  RAX , RBX , RCX , RDX ,
  RSI , RDI , RBP , RSP ,
  R8 , R9 , R10 , R11 ,
  R12 , R13 , R14 , R15 ,
  RIP , EFLAGS , CS , SS ,
  DS , ES , FS , GS ,
  ST0 , ST1 , ST2 , ST3 ,
  ST4 , ST5 , ST6 , ST7 ,
  FCTRL , FSTAT , FTAG , FISEG ,
  FIOFF , FOSEG , FOOFF , FOP ,
  EAX , ECX , EDX , EBX ,
  ESP , EBP , ESI , EDI ,
  EIP , EFLAGS , CS , SS ,
  DS , ES , FS , GS ,
  ST0 , ST1 , ST2 , ST3 ,
  ST4 , ST5 , ST6 , ST7 ,
  FCTRL , FSTAT , FTAG , FISEG ,
  FIOFF , FOSEG , FOOFF , FOP ,
  XMM0 , XMM1 , XMM2 , XMM3 ,
  XMM4 , XMM5 , XMM6 , XMM7 ,
  MXCSR
}
 

Functions

static voidctx_to_reg (CONTEXT *ctx, enum reg_name name)
 
static voidthread_to_reg (PETHREAD Thread, enum reg_name reg_name)
 
KDSTATUS gdb_send_registers (void)
 
KDSTATUS gdb_send_register (void)
 

Variables

static const unsigned char reg_size []
 

Enumeration Type Documentation

◆ reg_name

Enumerator
RAX 
RBX 
RCX 
RDX 
RSI 
RDI 
RBP 
RSP 
R8 
R9 
R10 
R11 
R12 
R13 
R14 
R15 
RIP 
EFLAGS 
CS 
SS 
DS 
ES 
FS 
GS 
ST0 
ST1 
ST2 
ST3 
ST4 
ST5 
ST6 
ST7 
FCTRL 
FSTAT 
FTAG 
FISEG 
FIOFF 
FOSEG 
FOOFF 
FOP 
EAX 
ECX 
EDX 
EBX 
ESP 
EBP 
ESI 
EDI 
EIP 
EFLAGS 
CS 
SS 
DS 
ES 
FS 
GS 
ST0 
ST1 
ST2 
ST3 
ST4 
ST5 
ST6 
ST7 
FCTRL 
FSTAT 
FTAG 
FISEG 
FIOFF 
FOSEG 
FOOFF 
FOP 
XMM0 
XMM1 
XMM2 
XMM3 
XMM4 
XMM5 
XMM6 
XMM7 
MXCSR 

Definition at line 10 of file amd64_sup.c.

11{
12 RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP,
13 R8, R9, R10, R11, R12, R13, R14, R15,
14 RIP,
15 EFLAGS,
16 CS, SS, DS, ES, FS, GS,
17 ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7,
19};
@ RDX
Definition: amd64_sup.c:12
@ ST7
Definition: amd64_sup.c:17
@ EFLAGS
Definition: amd64_sup.c:15
@ RSP
Definition: amd64_sup.c:12
@ FSTAT
Definition: amd64_sup.c:18
@ FOOFF
Definition: amd64_sup.c:18
@ FTAG
Definition: amd64_sup.c:18
@ R15
Definition: amd64_sup.c:13
@ R13
Definition: amd64_sup.c:13
@ RSI
Definition: amd64_sup.c:12
@ FOSEG
Definition: amd64_sup.c:18
@ ST2
Definition: amd64_sup.c:17
@ FCTRL
Definition: amd64_sup.c:18
@ RBX
Definition: amd64_sup.c:12
@ ST1
Definition: amd64_sup.c:17
@ R12
Definition: amd64_sup.c:13
@ R9
Definition: amd64_sup.c:13
@ FS
Definition: amd64_sup.c:16
@ ES
Definition: amd64_sup.c:16
@ FISEG
Definition: amd64_sup.c:18
@ ST5
Definition: amd64_sup.c:17
@ CS
Definition: amd64_sup.c:16
@ FIOFF
Definition: amd64_sup.c:18
@ RDI
Definition: amd64_sup.c:12
@ RCX
Definition: amd64_sup.c:12
@ RIP
Definition: amd64_sup.c:14
@ GS
Definition: amd64_sup.c:16
@ RBP
Definition: amd64_sup.c:12
@ ST4
Definition: amd64_sup.c:17
@ ST6
Definition: amd64_sup.c:17
@ DS
Definition: amd64_sup.c:16
@ R14
Definition: amd64_sup.c:13
@ FOP
Definition: amd64_sup.c:18
@ SS
Definition: amd64_sup.c:16
@ RAX
Definition: amd64_sup.c:12
@ R8
Definition: amd64_sup.c:13
@ ST3
Definition: amd64_sup.c:17
@ R11
Definition: amd64_sup.c:13
@ R10
Definition: amd64_sup.c:13
@ ST0
Definition: amd64_sup.c:17

Function Documentation

◆ ctx_to_reg()

static void * ctx_to_reg ( CONTEXT ctx,
enum reg_name  name 
)
static

Definition at line 34 of file amd64_sup.c.

35{
36 switch (name)
37 {
38 case RAX: return &ctx->Rax;
39 case RBX: return &ctx->Rbx;
40 case RCX: return &ctx->Rcx;
41 case RDX: return &ctx->Rdx;
42 case RSP: return &ctx->Rsp;
43 case RBP: return &ctx->Rbp;
44 case RSI: return &ctx->Rsi;
45 case RDI: return &ctx->Rdi;
46 case RIP: return &ctx->Rip;
47 case R8: return &ctx->R8;
48 case R9: return &ctx->R9;
49 case R10: return &ctx->R10;
50 case R11: return &ctx->R11;
51 case R12: return &ctx->R12;
52 case R13: return &ctx->R13;
53 case R14: return &ctx->R14;
54 case R15: return &ctx->R15;
55 case EFLAGS: return &ctx->EFlags;
56 case CS: return &ctx->SegCs;
57 case DS: return &ctx->SegSs;
58 case ES: return &ctx->SegEs;
59 case FS: return &ctx->SegFs;
60 case GS: return &ctx->SegGs;
61 case SS: return &ctx->SegSs;
62 }
63#undef return_reg
64 return 0;
65}
Definition: name.c:39

Referenced by gdb_send_register(), and gdb_send_registers().

◆ gdb_send_register()

KDSTATUS gdb_send_register ( void  )

Definition at line 219 of file amd64_sup.c.

220{
221 enum reg_name reg_name;
222 void *ptr;
223
224 /* Get the GDB register name (gdb_input = "pXX") */
226
227 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
229 {
230 /* We can get it from the context of the current exception */
232 }
233 else
234 {
235 PETHREAD DbgThread;
236
237 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
238
239 if (DbgThread == NULL)
240 {
241 /* Thread is dead */
242 return send_gdb_packet("E03");
243 }
244
245 ptr = thread_to_reg(DbgThread, reg_name);
246 }
247
248 if (!ptr)
249 {
250 unsigned char size = reg_size[reg_name];
252 while (size--)
254 return finish_gdb_packet();
255 }
256 else
257 {
258 KDDBGPRINT("KDDBG : Sending registers as memory.\n");
260 }
261}
static void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name)
Definition: amd64_sup.c:69
static const unsigned char reg_size[]
Definition: amd64_sup.c:21
static void * ctx_to_reg(CONTEXT *ctx, enum reg_name name)
Definition: amd64_sup.c:34
reg_name
Definition: amd64_sup.c:11
#define NULL
Definition: types.h:112
#define KDDBGPRINT(...)
Definition: kddll.h:19
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
char hex_value(char ch)
Definition: gdb_receive.c:15
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:158
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
void start_gdb_packet(void)
Definition: gdb_send.c:52
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
GLsizeiptr size
Definition: glext.h:5919
CONTEXT CurrentContext
Definition: kdpacket.c:29
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
static PVOID ptr
Definition: dispmode.c:27
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by gdb_receive_and_interpret_packet().

◆ gdb_send_registers()

KDSTATUS gdb_send_registers ( void  )

Definition at line 144 of file amd64_sup.c.

145{
146 CHAR RegisterStr[17];
147 UCHAR* RegisterPtr;
148 unsigned short i;
149 unsigned short size;
150
152
153 KDDBGPRINT("Sending registers of thread %" PRIxPTR ".\n", gdb_dbg_tid);
154 KDDBGPRINT("Current thread_id: %p.\n", PsGetThreadId((PETHREAD)(ULONG_PTR)CurrentStateChange.Thread));
155 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
157 {
158 for (i = 0; i < 24; i++)
159 {
160 RegisterPtr = ctx_to_reg(&CurrentContext, i);
161 size = reg_size[i] * 2;
162 RegisterStr[size] = 0;
163 while (size)
164 {
165 size--;
166 RegisterStr[size] = hex_chars[RegisterPtr[size/2] & 0xF];
167 size--;
168 RegisterStr[size] = hex_chars[RegisterPtr[size/2] >> 4];
169 }
170
171 send_gdb_partial_packet(RegisterStr);
172 }
173 }
174 else
175 {
176 PETHREAD DbgThread;
177
178 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
179
180 if (DbgThread == NULL)
181 {
182 /* Thread is dead */
184 return finish_gdb_packet();
185 }
186
187 for (i = 0; i < 24; i++)
188 {
189 RegisterPtr = thread_to_reg(DbgThread, i);
190 size = reg_size[i] * 2;
191 RegisterStr[size] = 0;
192
193 while (size)
194 {
195 if (RegisterPtr)
196 {
197 size--;
198 RegisterStr[size] = hex_chars[RegisterPtr[size/2] & 0xF];
199 size--;
200 RegisterStr[size] = hex_chars[RegisterPtr[size/2] >> 4];
201 }
202 else
203 {
204 size--;
205 RegisterStr[size] = 'x';
206 size--;
207 RegisterStr[size] = 'x';
208 }
209 }
210
211 send_gdb_partial_packet(RegisterStr);
212 }
213 }
214
215 return finish_gdb_packet();
216}
const char hex_chars[]
Definition: gdb_send.c:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define PRIxPTR
Definition: inttypes.h:236
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_manipulate().

◆ thread_to_reg()

static void * thread_to_reg ( PETHREAD  Thread,
enum reg_name  reg_name 
)
static

Definition at line 69 of file amd64_sup.c.

70{
71 static const void* NullValue = NULL;
72
73#if 0
74 if (Thread->Tcb.TrapFrame)
75 {
76 PKTRAP_FRAME TrapFrame = Thread->Tcb.TrapFrame;
77
78 switch (reg_name)
79 {
80 case RAX: return &TrapFrame->Rax;
81 case RBX: return &TrapFrame->Rbx;
82 case RCX: return &TrapFrame->Rcx;
83 case RDX: return &TrapFrame->Rdx;
84 case RSP: return &TrapFrame->Rsp;
85 case RBP: return &TrapFrame->Rbp;
86 case RSI: return &TrapFrame->Rsi;
87 case RDI: return &TrapFrame->Rdi;
88 case RIP: return &TrapFrame->Rip;
89 case R8: return &TrapFrame->R8;
90 case R9: return &TrapFrame->R9;
91 case R10: return &TrapFrame->R10;
92 case R11: return &TrapFrame->R11;
93 case EFLAGS: return &TrapFrame->EFlags;
94 case CS: return &TrapFrame->SegCs;
95 case DS: return &TrapFrame->SegSs;
96 case ES: return &TrapFrame->SegEs;
97 case FS: return &TrapFrame->SegFs;
98 case GS: return &TrapFrame->SegGs;
99 case SS: return &TrapFrame->SegSs;
100 default:
101 KDDBGPRINT("Unhandled regname: %d.\n", reg_name);
102 }
103 }
104 else
105#endif
106 if (!Thread->Tcb.InitialStack)
107 {
108 /* Terminated thread ? */
109 switch (reg_name)
110 {
111 case RSP:
112 case RBP:
113 case RIP:
114 KDDBGPRINT("Returning NULL for register %d.\n", reg_name);
115 return &NullValue;
116 default:
117 return NULL;
118 }
119 }
120 else
121 {
122 switch(reg_name)
123 {
124 case RSP: return &Thread->Tcb.KernelStack;
125 case RIP:
126 {
128 return &Rsp[3];
129 }
130 case RBP:
131 {
133 return &Rsp[4];
134 }
135 default:
136 return NULL;
137 }
138 }
139
140 return NULL;
141}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
KTHREAD Tcb
Definition: pstypes.h:1104
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1774
PVOID InitialStack
Definition: ketypes.h:1664
PVOID KernelStack
Definition: ketypes.h:1675
UINT64 Rsp
Definition: ketypes.h:471
UINT64 Rdi
Definition: ketypes.h:455
UINT64 Rbp
Definition: ketypes.h:457
UINT64 Rsi
Definition: ketypes.h:456
UINT64 Rdx
Definition: ketypes.h:405
ULONG EFlags
Definition: ketypes.h:469
UINT64 Rbx
Definition: ketypes.h:454
USHORT SegSs
Definition: ketypes.h:472
USHORT SegCs
Definition: ketypes.h:465
UINT64 Rax
Definition: ketypes.h:403
UINT64 R10
Definition: ketypes.h:408
UINT64 Rip
Definition: ketypes.h:464
USHORT SegEs
Definition: ketypes.h:450
USHORT SegFs
Definition: ketypes.h:451
USHORT SegGs
Definition: ketypes.h:452
UINT64 R9
Definition: ketypes.h:407
UINT64 R8
Definition: ketypes.h:406
UINT64 Rcx
Definition: ketypes.h:404
UINT64 R11
Definition: ketypes.h:409
uint32_t * PULONG_PTR
Definition: typedefs.h:65

Referenced by gdb_send_register(), and gdb_send_registers().

Variable Documentation

◆ reg_size

const unsigned char reg_size[]
static
Initial value:
=
{
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8,
4,
4, 4, 4, 4, 4, 4,
10, 10, 10, 10, 10, 10, 10, 10,
8, 8, 8, 8, 8, 8, 8, 8
}

Definition at line 21 of file amd64_sup.c.

Referenced by AtapiDmaInit(), gdb_send_register(), and gdb_send_registers().