Change the definition of the debugging registers to be an array, so

that we can index into it, rather than do pointer gymnastics on a
structure containing 8 elements.

Verified by:	MD5 hash on the produced .o files.
This commit is contained in:
Poul-Henning Kamp 2002-10-20 20:48:56 +00:00
parent 858b84f550
commit 50c026e579
6 changed files with 110 additions and 116 deletions

View File

@ -487,7 +487,7 @@ i386_set_watch(watchnum, watchaddr, size, access, d)
if (watchnum == -1) {
for (i = 0, mask = 0x3; i < 4; i++, mask <<= 2)
if ((d->dr7 & mask) == 0)
if ((d->dr[7] & mask) == 0)
break;
if (i < 4)
watchnum = i;
@ -518,13 +518,13 @@ i386_set_watch(watchnum, watchaddr, size, access, d)
mask |= access;
/* clear the bits we are about to affect */
d->dr7 &= ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
d->dr[7] &= ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
/* set drN register to the address, N=watchnum */
DBREG_DRX(d,watchnum) = watchaddr;
/* enable the watchpoint */
d->dr7 |= (0x2 << (watchnum*2)) | (mask << (watchnum*4+16));
d->dr[7] |= (0x2 << (watchnum*2)) | (mask << (watchnum*4+16));
return (watchnum);
}
@ -539,7 +539,7 @@ i386_clr_watch(watchnum, d)
if (watchnum < 0 || watchnum >= 4)
return (-1);
d->dr7 = d->dr7 & ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
d->dr[7] = d->dr[7] & ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
DBREG_DRX(d,watchnum) = 0;
return (0);
@ -559,7 +559,7 @@ db_md_set_watchpoint(addr, size)
avail = 0;
for(i=0; i<4; i++) {
if ((d.dr7 & (3 << (i*2))) == 0)
if ((d.dr[7] & (3 << (i*2))) == 0)
avail++;
}
@ -567,7 +567,7 @@ db_md_set_watchpoint(addr, size)
return (-1);
for (i=0; i<4 && (size != 0); i++) {
if ((d.dr7 & (3<<(i*2))) == 0) {
if ((d.dr[7] & (3<<(i*2))) == 0) {
if (size > 4)
wsize = 4;
else
@ -598,7 +598,7 @@ db_md_clr_watchpoint(addr, size)
fill_dbregs(NULL, &d);
for(i=0; i<4; i++) {
if (d.dr7 & (3 << (i*2))) {
if (d.dr[7] & (3 << (i*2))) {
if ((DBREG_DRX((&d), i) >= addr) &&
(DBREG_DRX((&d), i) < addr+size))
i386_clr_watch(i, &d);
@ -638,10 +638,10 @@ db_md_list_watchpoints()
db_printf(" watch status type len address\n");
db_printf(" ----- -------- ---------- --- ----------\n");
for (i=0; i<4; i++) {
if (d.dr7 & (0x03 << (i*2))) {
if (d.dr[7] & (0x03 << (i*2))) {
unsigned type, len;
type = (d.dr7 >> (16+(i*4))) & 3;
len = (d.dr7 >> (16+(i*4)+2)) & 3;
type = (d.dr[7] >> (16+(i*4))) & 3;
len = (d.dr[7] >> (16+(i*4)+2)) & 3;
db_printf(" %-5d %-8s %10s %3d 0x%08x\n",
i, "enabled", watchtype_str(type),
len+1, DBREG_DRX((&d),i));

View File

@ -2267,24 +2267,24 @@ fill_dbregs(struct thread *td, struct dbreg *dbregs)
struct pcb *pcb;
if (td == NULL) {
dbregs->dr0 = rdr0();
dbregs->dr1 = rdr1();
dbregs->dr2 = rdr2();
dbregs->dr3 = rdr3();
dbregs->dr4 = rdr4();
dbregs->dr5 = rdr5();
dbregs->dr6 = rdr6();
dbregs->dr7 = rdr7();
dbregs->dr[0] = rdr0();
dbregs->dr[1] = rdr1();
dbregs->dr[2] = rdr2();
dbregs->dr[3] = rdr3();
dbregs->dr[4] = rdr4();
dbregs->dr[5] = rdr5();
dbregs->dr[6] = rdr6();
dbregs->dr[7] = rdr7();
} else {
pcb = td->td_pcb;
dbregs->dr0 = pcb->pcb_dr0;
dbregs->dr1 = pcb->pcb_dr1;
dbregs->dr2 = pcb->pcb_dr2;
dbregs->dr3 = pcb->pcb_dr3;
dbregs->dr4 = 0;
dbregs->dr5 = 0;
dbregs->dr6 = pcb->pcb_dr6;
dbregs->dr7 = pcb->pcb_dr7;
dbregs->dr[0] = pcb->pcb_dr0;
dbregs->dr[1] = pcb->pcb_dr1;
dbregs->dr[2] = pcb->pcb_dr2;
dbregs->dr[3] = pcb->pcb_dr3;
dbregs->dr[4] = 0;
dbregs->dr[5] = 0;
dbregs->dr[6] = pcb->pcb_dr6;
dbregs->dr[7] = pcb->pcb_dr7;
}
return (0);
}
@ -2297,14 +2297,14 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
u_int32_t mask1, mask2;
if (td == NULL) {
load_dr0(dbregs->dr0);
load_dr1(dbregs->dr1);
load_dr2(dbregs->dr2);
load_dr3(dbregs->dr3);
load_dr4(dbregs->dr4);
load_dr5(dbregs->dr5);
load_dr6(dbregs->dr6);
load_dr7(dbregs->dr7);
load_dr0(dbregs->dr[0]);
load_dr1(dbregs->dr[1]);
load_dr2(dbregs->dr[2]);
load_dr3(dbregs->dr[3]);
load_dr4(dbregs->dr[4]);
load_dr5(dbregs->dr[5]);
load_dr6(dbregs->dr[6]);
load_dr7(dbregs->dr[7]);
} else {
/*
* Don't let an illegal value for dr7 get set. Specifically,
@ -2314,7 +2314,7 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
*/
for (i = 0, mask1 = 0x3<<16, mask2 = 0x2<<16; i < 8;
i++, mask1 <<= 2, mask2 <<= 2)
if ((dbregs->dr7 & mask1) == mask2)
if ((dbregs->dr[7] & mask1) == mask2)
return (EINVAL);
pcb = td->td_pcb;
@ -2335,37 +2335,37 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
*/
if (suser(td) != 0) {
if (dbregs->dr7 & 0x3) {
if (dbregs->dr[7] & 0x3) {
/* dr0 is enabled */
if (dbregs->dr0 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[0] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<2)) {
if (dbregs->dr[7] & (0x3<<2)) {
/* dr1 is enabled */
if (dbregs->dr1 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[1] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<4)) {
if (dbregs->dr[7] & (0x3<<4)) {
/* dr2 is enabled */
if (dbregs->dr2 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[2] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<6)) {
if (dbregs->dr[7] & (0x3<<6)) {
/* dr3 is enabled */
if (dbregs->dr3 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[3] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
}
pcb->pcb_dr0 = dbregs->dr0;
pcb->pcb_dr1 = dbregs->dr1;
pcb->pcb_dr2 = dbregs->dr2;
pcb->pcb_dr3 = dbregs->dr3;
pcb->pcb_dr6 = dbregs->dr6;
pcb->pcb_dr7 = dbregs->dr7;
pcb->pcb_dr0 = dbregs->dr[0];
pcb->pcb_dr1 = dbregs->dr[1];
pcb->pcb_dr2 = dbregs->dr[2];
pcb->pcb_dr3 = dbregs->dr[3];
pcb->pcb_dr6 = dbregs->dr[6];
pcb->pcb_dr7 = dbregs->dr[7];
pcb->pcb_flags |= PCB_DBREGS;
}

View File

@ -122,20 +122,17 @@ struct fpreg {
* Register set accessible via /proc/$pid/dbregs.
*/
struct dbreg {
unsigned int dr0; /* debug address register 0 */
unsigned int dr1; /* debug address register 1 */
unsigned int dr2; /* debug address register 2 */
unsigned int dr3; /* debug address register 3 */
unsigned int dr4; /* reserved */
unsigned int dr5; /* reserved */
unsigned int dr6; /* debug status register */
unsigned int dr7; /* debug control register */
unsigned int dr[8]; /* debug registers */
/* Index 0-3: debug address registers */
/* Index 4-5: reserved */
/* Index 6: debug status */
/* Index 7: debug control */
};
#define DBREG_DR7_EXEC 0x00 /* break on execute */
#define DBREG_DR7_WRONLY 0x01 /* break on write */
#define DBREG_DR7_RDWR 0x03 /* break on read or write */
#define DBREG_DRX(d,x) ((&d->dr0)[x]) /* reference dr0 - dr7 by
#define DBREG_DRX(d,x) (d->dr[(x)]) /* reference dr0 - dr7 by
register number */

View File

@ -487,7 +487,7 @@ i386_set_watch(watchnum, watchaddr, size, access, d)
if (watchnum == -1) {
for (i = 0, mask = 0x3; i < 4; i++, mask <<= 2)
if ((d->dr7 & mask) == 0)
if ((d->dr[7] & mask) == 0)
break;
if (i < 4)
watchnum = i;
@ -518,13 +518,13 @@ i386_set_watch(watchnum, watchaddr, size, access, d)
mask |= access;
/* clear the bits we are about to affect */
d->dr7 &= ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
d->dr[7] &= ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
/* set drN register to the address, N=watchnum */
DBREG_DRX(d,watchnum) = watchaddr;
/* enable the watchpoint */
d->dr7 |= (0x2 << (watchnum*2)) | (mask << (watchnum*4+16));
d->dr[7] |= (0x2 << (watchnum*2)) | (mask << (watchnum*4+16));
return (watchnum);
}
@ -539,7 +539,7 @@ i386_clr_watch(watchnum, d)
if (watchnum < 0 || watchnum >= 4)
return (-1);
d->dr7 = d->dr7 & ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
d->dr[7] = d->dr[7] & ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16)));
DBREG_DRX(d,watchnum) = 0;
return (0);
@ -559,7 +559,7 @@ db_md_set_watchpoint(addr, size)
avail = 0;
for(i=0; i<4; i++) {
if ((d.dr7 & (3 << (i*2))) == 0)
if ((d.dr[7] & (3 << (i*2))) == 0)
avail++;
}
@ -567,7 +567,7 @@ db_md_set_watchpoint(addr, size)
return (-1);
for (i=0; i<4 && (size != 0); i++) {
if ((d.dr7 & (3<<(i*2))) == 0) {
if ((d.dr[7] & (3<<(i*2))) == 0) {
if (size > 4)
wsize = 4;
else
@ -598,7 +598,7 @@ db_md_clr_watchpoint(addr, size)
fill_dbregs(NULL, &d);
for(i=0; i<4; i++) {
if (d.dr7 & (3 << (i*2))) {
if (d.dr[7] & (3 << (i*2))) {
if ((DBREG_DRX((&d), i) >= addr) &&
(DBREG_DRX((&d), i) < addr+size))
i386_clr_watch(i, &d);
@ -638,10 +638,10 @@ db_md_list_watchpoints()
db_printf(" watch status type len address\n");
db_printf(" ----- -------- ---------- --- ----------\n");
for (i=0; i<4; i++) {
if (d.dr7 & (0x03 << (i*2))) {
if (d.dr[7] & (0x03 << (i*2))) {
unsigned type, len;
type = (d.dr7 >> (16+(i*4))) & 3;
len = (d.dr7 >> (16+(i*4)+2)) & 3;
type = (d.dr[7] >> (16+(i*4))) & 3;
len = (d.dr[7] >> (16+(i*4)+2)) & 3;
db_printf(" %-5d %-8s %10s %3d 0x%08x\n",
i, "enabled", watchtype_str(type),
len+1, DBREG_DRX((&d),i));

View File

@ -2267,24 +2267,24 @@ fill_dbregs(struct thread *td, struct dbreg *dbregs)
struct pcb *pcb;
if (td == NULL) {
dbregs->dr0 = rdr0();
dbregs->dr1 = rdr1();
dbregs->dr2 = rdr2();
dbregs->dr3 = rdr3();
dbregs->dr4 = rdr4();
dbregs->dr5 = rdr5();
dbregs->dr6 = rdr6();
dbregs->dr7 = rdr7();
dbregs->dr[0] = rdr0();
dbregs->dr[1] = rdr1();
dbregs->dr[2] = rdr2();
dbregs->dr[3] = rdr3();
dbregs->dr[4] = rdr4();
dbregs->dr[5] = rdr5();
dbregs->dr[6] = rdr6();
dbregs->dr[7] = rdr7();
} else {
pcb = td->td_pcb;
dbregs->dr0 = pcb->pcb_dr0;
dbregs->dr1 = pcb->pcb_dr1;
dbregs->dr2 = pcb->pcb_dr2;
dbregs->dr3 = pcb->pcb_dr3;
dbregs->dr4 = 0;
dbregs->dr5 = 0;
dbregs->dr6 = pcb->pcb_dr6;
dbregs->dr7 = pcb->pcb_dr7;
dbregs->dr[0] = pcb->pcb_dr0;
dbregs->dr[1] = pcb->pcb_dr1;
dbregs->dr[2] = pcb->pcb_dr2;
dbregs->dr[3] = pcb->pcb_dr3;
dbregs->dr[4] = 0;
dbregs->dr[5] = 0;
dbregs->dr[6] = pcb->pcb_dr6;
dbregs->dr[7] = pcb->pcb_dr7;
}
return (0);
}
@ -2297,14 +2297,14 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
u_int32_t mask1, mask2;
if (td == NULL) {
load_dr0(dbregs->dr0);
load_dr1(dbregs->dr1);
load_dr2(dbregs->dr2);
load_dr3(dbregs->dr3);
load_dr4(dbregs->dr4);
load_dr5(dbregs->dr5);
load_dr6(dbregs->dr6);
load_dr7(dbregs->dr7);
load_dr0(dbregs->dr[0]);
load_dr1(dbregs->dr[1]);
load_dr2(dbregs->dr[2]);
load_dr3(dbregs->dr[3]);
load_dr4(dbregs->dr[4]);
load_dr5(dbregs->dr[5]);
load_dr6(dbregs->dr[6]);
load_dr7(dbregs->dr[7]);
} else {
/*
* Don't let an illegal value for dr7 get set. Specifically,
@ -2314,7 +2314,7 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
*/
for (i = 0, mask1 = 0x3<<16, mask2 = 0x2<<16; i < 8;
i++, mask1 <<= 2, mask2 <<= 2)
if ((dbregs->dr7 & mask1) == mask2)
if ((dbregs->dr[7] & mask1) == mask2)
return (EINVAL);
pcb = td->td_pcb;
@ -2335,37 +2335,37 @@ set_dbregs(struct thread *td, struct dbreg *dbregs)
*/
if (suser(td) != 0) {
if (dbregs->dr7 & 0x3) {
if (dbregs->dr[7] & 0x3) {
/* dr0 is enabled */
if (dbregs->dr0 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[0] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<2)) {
if (dbregs->dr[7] & (0x3<<2)) {
/* dr1 is enabled */
if (dbregs->dr1 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[1] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<4)) {
if (dbregs->dr[7] & (0x3<<4)) {
/* dr2 is enabled */
if (dbregs->dr2 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[2] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
if (dbregs->dr7 & (0x3<<6)) {
if (dbregs->dr[7] & (0x3<<6)) {
/* dr3 is enabled */
if (dbregs->dr3 >= VM_MAXUSER_ADDRESS)
if (dbregs->dr[3] >= VM_MAXUSER_ADDRESS)
return (EINVAL);
}
}
pcb->pcb_dr0 = dbregs->dr0;
pcb->pcb_dr1 = dbregs->dr1;
pcb->pcb_dr2 = dbregs->dr2;
pcb->pcb_dr3 = dbregs->dr3;
pcb->pcb_dr6 = dbregs->dr6;
pcb->pcb_dr7 = dbregs->dr7;
pcb->pcb_dr0 = dbregs->dr[0];
pcb->pcb_dr1 = dbregs->dr[1];
pcb->pcb_dr2 = dbregs->dr[2];
pcb->pcb_dr3 = dbregs->dr[3];
pcb->pcb_dr6 = dbregs->dr[6];
pcb->pcb_dr7 = dbregs->dr[7];
pcb->pcb_flags |= PCB_DBREGS;
}

View File

@ -122,20 +122,17 @@ struct fpreg {
* Register set accessible via /proc/$pid/dbregs.
*/
struct dbreg {
unsigned int dr0; /* debug address register 0 */
unsigned int dr1; /* debug address register 1 */
unsigned int dr2; /* debug address register 2 */
unsigned int dr3; /* debug address register 3 */
unsigned int dr4; /* reserved */
unsigned int dr5; /* reserved */
unsigned int dr6; /* debug status register */
unsigned int dr7; /* debug control register */
unsigned int dr[8]; /* debug registers */
/* Index 0-3: debug address registers */
/* Index 4-5: reserved */
/* Index 6: debug status */
/* Index 7: debug control */
};
#define DBREG_DR7_EXEC 0x00 /* break on execute */
#define DBREG_DR7_WRONLY 0x01 /* break on write */
#define DBREG_DR7_RDWR 0x03 /* break on read or write */
#define DBREG_DRX(d,x) ((&d->dr0)[x]) /* reference dr0 - dr7 by
#define DBREG_DRX(d,x) (d->dr[(x)]) /* reference dr0 - dr7 by
register number */