/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Base.h>
#include <Library/PeCoffExtraActionLib.h>
#include <Library/DebugLib.h>
#include <ImageDebugSupport.h>
/**
Check if the hardware breakpoint in Drx is enabled by checking the Lx and Gx bit in Dr7.
It assumes that DebugAgent will set both Lx and Gx bit when setting up the hardware breakpoint.
@param RegisterIndex Index of Dr register. The value range is from 0 to 3.
@param Dr7 Value of Dr7 register.
@return TRUE The hardware breakpoint specified in the Drx is enabled.
@return FALSE The hardware breakpoint specified in the Drx is disabled.
**/
)
{
}
/**
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
**/
)
{
}
//
// Disable interrupts and save the current interrupt state
//
//
// Save Debug Register State
//
Dr0 = AsmReadDr0 ();
Dr1 = AsmReadDr1 ();
Dr2 = AsmReadDr2 ();
Dr3 = AsmReadDr3 ();
Dr7 = AsmReadDr7 ();
Cr4 = AsmReadCr4 ();
//
// DR0 = IMAGE_LOAD_SIGNATURE
// DR2 = The pointer to the ImageContext structure
// DR3 = IO_PORT_BREAKPOINT_ADDRESS
// DR7 = Disables all HW breakpoints except for DR3 I/O port access of length 1 byte
// CR4 = Make sure DE(BIT3) is set
//
AsmWriteDr7 (0);
AsmWriteDr7 (0x20000480);
//
// Do an IN from IO_PORT_BREAKPOINT_ADDRESS to generate a HW breakpoint until the port
// returns a read value other than DEBUG_AGENT_IMAGE_WAIT
//
do {
} while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT);
} else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
//
// Generate a software break point.
//
CpuBreakpoint ();
}
//
// Restore Debug Register State only when Host didn't change it inside exception handler.
// E.g.: User halts the target and sets the HW breakpoint while target is
// in the above exception handler
//
NewDr7 = AsmReadDr7 ();
if (!IsDrxEnabled (0, NewDr7)) {
AsmWriteDr0 (Dr0);
}
AsmWriteDr1 (Dr1);
}
AsmWriteDr2 (Dr2);
}
AsmWriteDr3 (Dr3);
}
AsmWriteCr4 (Cr4);
}
if (NewDr7 == 0x20000480) {
AsmWriteDr7 (Dr7);
}
//
// Restore the interrupt state
//
}
/**
that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
**/
)
{
}
//
// Disable interrupts and save the current interrupt state
//
//
// Save Debug Register State
//
Dr0 = AsmReadDr0 ();
Dr1 = AsmReadDr1 ();
Dr2 = AsmReadDr2 ();
Dr3 = AsmReadDr3 ();
Dr7 = AsmReadDr7 ();
Cr4 = AsmReadCr4 ();
//
// DR0 = IMAGE_UNLOAD_SIGNATURE
// DR2 = The pointer to the ImageContext structure
// DR3 = IO_PORT_BREAKPOINT_ADDRESS
// DR7 = Disables all HW breakpoints except for DR3 I/O port access of length 1 byte
// CR4 = Make sure DE(BIT3) is set
//
AsmWriteDr7 (0);
AsmWriteDr7 (0x20000480);
//
// Do an IN from IO_PORT_BREAKPOINT_ADDRESS to generate a HW breakpoint until the port
// returns a read value other than DEBUG_AGENT_IMAGE_WAIT
//
do {
} while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT);
} else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
//
// Generate a software break point.
//
CpuBreakpoint ();
}
//
// Restore Debug Register State only when Host didn't change it inside exception handler.
// E.g.: User halts the target and sets the HW breakpoint while target is
// in the above exception handler
//
NewDr7 = AsmReadDr7 ();
if (!IsDrxEnabled (0, NewDr7)) {
AsmWriteDr0 (Dr0);
}
AsmWriteDr1 (Dr1);
}
AsmWriteDr2 (Dr2);
}
AsmWriteDr3 (Dr3);
}
AsmWriteCr4 (Cr4);
}
if (NewDr7 == 0x20000480) {
AsmWriteDr7 (Dr7);
}
//
// Restore the interrupt state
//
}