Merged from sys/i386/i386/machdep.c revisions 1.384 and 1.385.
This commit is contained in:
parent
9c675e3c19
commit
ce4274863e
@ -1031,6 +1031,28 @@ setregs(p, entry, stack, ps_strings)
|
||||
else
|
||||
pcb->pcb_gs = _udatasel;
|
||||
|
||||
/*
|
||||
* Reset the hardware debug registers if they were in use.
|
||||
* They won't have any meaning for the newly exec'd process.
|
||||
*/
|
||||
if (pcb->pcb_flags & PCB_DBREGS) {
|
||||
pcb->pcb_dr0 = 0;
|
||||
pcb->pcb_dr1 = 0;
|
||||
pcb->pcb_dr2 = 0;
|
||||
pcb->pcb_dr3 = 0;
|
||||
pcb->pcb_dr6 = 0;
|
||||
pcb->pcb_dr7 = 0;
|
||||
if (pcb == curpcb) {
|
||||
/*
|
||||
* Clear the debug registers on the running
|
||||
* CPU, otherwise they will end up affecting
|
||||
* the next process we switch to.
|
||||
*/
|
||||
reset_dbregs();
|
||||
}
|
||||
pcb->pcb_flags &= ~PCB_DBREGS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the math emulator (if any) for the current process.
|
||||
* Actually, just clear the bit that says that the emulator has
|
||||
@ -2470,6 +2492,76 @@ set_dbregs(p, dbregs)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return > 0 if a hardware breakpoint has been hit, and the
|
||||
* breakpoint was in user space. Return 0, otherwise.
|
||||
*/
|
||||
int
|
||||
user_dbreg_trap(void)
|
||||
{
|
||||
u_int32_t dr7, dr6; /* debug registers dr6 and dr7 */
|
||||
u_int32_t bp; /* breakpoint bits extracted from dr6 */
|
||||
int nbp; /* number of breakpoints that triggered */
|
||||
caddr_t addr[4]; /* breakpoint addresses */
|
||||
int i;
|
||||
|
||||
dr7 = rdr7();
|
||||
if ((dr7 & 0x000000ff) == 0) {
|
||||
/*
|
||||
* all GE and LE bits in the dr7 register are zero,
|
||||
* thus the trap couldn't have been caused by the
|
||||
* hardware debug registers
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
nbp = 0;
|
||||
dr6 = rdr6();
|
||||
bp = dr6 & 0x0000000f;
|
||||
|
||||
if (!bp) {
|
||||
/*
|
||||
* None of the breakpoint bits are set meaning this
|
||||
* trap was not caused by any of the debug registers
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* at least one of the breakpoints were hit, check to see
|
||||
* which ones and if any of them are user space addresses
|
||||
*/
|
||||
|
||||
if (bp & 0x01) {
|
||||
addr[nbp++] = (caddr_t)rdr0();
|
||||
}
|
||||
if (bp & 0x02) {
|
||||
addr[nbp++] = (caddr_t)rdr1();
|
||||
}
|
||||
if (bp & 0x04) {
|
||||
addr[nbp++] = (caddr_t)rdr2();
|
||||
}
|
||||
if (bp & 0x08) {
|
||||
addr[nbp++] = (caddr_t)rdr3();
|
||||
}
|
||||
|
||||
for (i=0; i<nbp; i++) {
|
||||
if (addr[i] <
|
||||
(caddr_t)VM_MAXUSER_ADDRESS) {
|
||||
/*
|
||||
* addr[i] is in user space
|
||||
*/
|
||||
return nbp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* None of the breakpoints are in user space.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef DDB
|
||||
void
|
||||
Debugger(const char *msg)
|
||||
|
@ -1031,6 +1031,28 @@ setregs(p, entry, stack, ps_strings)
|
||||
else
|
||||
pcb->pcb_gs = _udatasel;
|
||||
|
||||
/*
|
||||
* Reset the hardware debug registers if they were in use.
|
||||
* They won't have any meaning for the newly exec'd process.
|
||||
*/
|
||||
if (pcb->pcb_flags & PCB_DBREGS) {
|
||||
pcb->pcb_dr0 = 0;
|
||||
pcb->pcb_dr1 = 0;
|
||||
pcb->pcb_dr2 = 0;
|
||||
pcb->pcb_dr3 = 0;
|
||||
pcb->pcb_dr6 = 0;
|
||||
pcb->pcb_dr7 = 0;
|
||||
if (pcb == curpcb) {
|
||||
/*
|
||||
* Clear the debug registers on the running
|
||||
* CPU, otherwise they will end up affecting
|
||||
* the next process we switch to.
|
||||
*/
|
||||
reset_dbregs();
|
||||
}
|
||||
pcb->pcb_flags &= ~PCB_DBREGS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the math emulator (if any) for the current process.
|
||||
* Actually, just clear the bit that says that the emulator has
|
||||
@ -2470,6 +2492,76 @@ set_dbregs(p, dbregs)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return > 0 if a hardware breakpoint has been hit, and the
|
||||
* breakpoint was in user space. Return 0, otherwise.
|
||||
*/
|
||||
int
|
||||
user_dbreg_trap(void)
|
||||
{
|
||||
u_int32_t dr7, dr6; /* debug registers dr6 and dr7 */
|
||||
u_int32_t bp; /* breakpoint bits extracted from dr6 */
|
||||
int nbp; /* number of breakpoints that triggered */
|
||||
caddr_t addr[4]; /* breakpoint addresses */
|
||||
int i;
|
||||
|
||||
dr7 = rdr7();
|
||||
if ((dr7 & 0x000000ff) == 0) {
|
||||
/*
|
||||
* all GE and LE bits in the dr7 register are zero,
|
||||
* thus the trap couldn't have been caused by the
|
||||
* hardware debug registers
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
nbp = 0;
|
||||
dr6 = rdr6();
|
||||
bp = dr6 & 0x0000000f;
|
||||
|
||||
if (!bp) {
|
||||
/*
|
||||
* None of the breakpoint bits are set meaning this
|
||||
* trap was not caused by any of the debug registers
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* at least one of the breakpoints were hit, check to see
|
||||
* which ones and if any of them are user space addresses
|
||||
*/
|
||||
|
||||
if (bp & 0x01) {
|
||||
addr[nbp++] = (caddr_t)rdr0();
|
||||
}
|
||||
if (bp & 0x02) {
|
||||
addr[nbp++] = (caddr_t)rdr1();
|
||||
}
|
||||
if (bp & 0x04) {
|
||||
addr[nbp++] = (caddr_t)rdr2();
|
||||
}
|
||||
if (bp & 0x08) {
|
||||
addr[nbp++] = (caddr_t)rdr3();
|
||||
}
|
||||
|
||||
for (i=0; i<nbp; i++) {
|
||||
if (addr[i] <
|
||||
(caddr_t)VM_MAXUSER_ADDRESS) {
|
||||
/*
|
||||
* addr[i] is in user space
|
||||
*/
|
||||
return nbp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* None of the breakpoints are in user space.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef DDB
|
||||
void
|
||||
Debugger(const char *msg)
|
||||
|
Loading…
Reference in New Issue
Block a user