Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 May 2007 02:17:48 +0400
From:      stas.ibragimov@gmail.com
To:        freebsd-hackers@freebsd.org
Subject:   Debug and control registers in kdb.
Message-ID:  <20070501221455.GA7263@q.q>

next in thread | raw e-mail | index | archive | help

--2B/JsCI69OhZNC5r
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello everybody.
In ddb(4) we can read/write only cs-ss,eax-edx,esp,ebp,esi,edi,eip and efl registers of CPU?
Why not implemented reding/writing to the dr0-dr7 and cr0-cr4 registers? 
In attach there are small patch, that implements it. 

--2B/JsCI69OhZNC5r
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename=patch

*** db_trace.c.org	Wed May  2 00:12:22 2007
--- db_trace.c	Wed May  2 01:04:01 2007
***************
*** 59,64 ****
--- 59,69 ----
  static db_varfcn_t db_esp;
  static db_varfcn_t db_frame;
  static db_varfcn_t db_ss;
+ static db_varfcn_t db_cr0;
+ static db_varfcn_t db_cr1;
+ static db_varfcn_t db_cr2;
+ static db_varfcn_t db_cr3;
+ static db_varfcn_t db_cr4;
  
  /*
   * Machine register set.
***************
*** 88,95 ****
  	{ "dr5",	NULL,			db_dr5 },
  	{ "dr6",	NULL,			db_dr6 },
  	{ "dr7",	NULL,			db_dr7 },
  	
! #define	DB_N_SHOW_REGS	23	/* Don't show registers after here. */
  };
  struct db_variable *db_eregs = db_regs + DB_N_SHOW_REGS;
  
--- 93,105 ----
  	{ "dr5",	NULL,			db_dr5 },
  	{ "dr6",	NULL,			db_dr6 },
  	{ "dr7",	NULL,			db_dr7 },
+ 	{ "cr0",        NULL,                   db_cr0 },
+ 	{ "cr1",        NULL,                   db_cr1 },
+ 	{ "cr2",        NULL,                   db_cr2 },
+ 	{ "cr3",        NULL,                   db_cr3 },
+ 	{ "cr4",        NULL,                   db_cr4 },
  	
! #define	DB_N_SHOW_REGS	28	/* Don't show registers after here. */
  };
  struct db_variable *db_eregs = db_regs + DB_N_SHOW_REGS;
  
***************
*** 106,111 ****
--- 116,122 ----
  		load_ ## reg (*valuep); \
  	return (1);			\
  }
+ 
  DB_DRX_FUNC(dr0)
  DB_DRX_FUNC(dr1)
  DB_DRX_FUNC(dr2)
***************
*** 114,119 ****
--- 125,135 ----
  DB_DRX_FUNC(dr5)
  DB_DRX_FUNC(dr6)
  DB_DRX_FUNC(dr7)
+ DB_DRX_FUNC(cr0)
+ DB_DRX_FUNC(cr1)
+ DB_DRX_FUNC(cr2)
+ DB_DRX_FUNC(cr3)
+ DB_DRX_FUNC(cr4)
  
  static __inline int
  get_esp(struct trapframe *tf)
*** cpufunc.h.org	Wed May  2 01:57:40 2007
--- cpufunc.h	Wed May  2 01:18:31 2007
***************
*** 388,394 ****
--- 388,414 ----
  }
  
  
+ static __inline void
+ load_cr1(u_int data)
+ {
  
+         __asm __volatile("movl %0,%%cr1" : : "r" (data));
+ }
+ static __inline u_int
+ rcr1(void)
+ {
+     u_int   data;
+ 
+     __asm __volatile("movl %%cr1,%0" : "=r" (data));
+     return (data);
+ }
+ 
+ static __inline void
+ load_cr2(u_int data)
+ {
+ 
+         __asm __volatile("movl %0,%%cr2" : : "r" (data));
+ }
  
  static __inline u_int
  rcr2(void)

--2B/JsCI69OhZNC5r--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070501221455.GA7263>