/*
小弟在做LBA 48bit 硬盘PIO方式读数据时。一直没有读到数据。而28bit PIO完全没有问题。
请教各位。下列代码出错在哪里。(DMA 方式读写48bit LBA没问题)。请大家帮帮呀。
*/
extern "C"
{
#include <ntddk.h>
}
/* _Wait... */
void sleep(ULONG mSecond)
{
LARGE_INTEGER timeout;
timeout = RtlConvertLongToLargeInteger(-10*1000*mSecond);
KeDelayExecutionThread(KernelMode,false,&timeout);
}
/* _Read Sector
*uLba - 扇区逻辑地址 48bit.
*uCount - 要读的扇区数
*buffer - 数据缓冲区
*/
void Lba48Read(ULONGLONG uLba,USHORT uCounts,PUCHAR buffer)
{
WRITE_PORT_UCHAR((PUCHAR)0x1f1,0);
WRITE_PORT_UCHAR((PUCHAR)0x1f2,uCounts >> 8);
WRITE_PORT_UCHAR((PUCHAR)0x1f3,uLba >> 24);
WRITE_PORT_UCHAR((PUCHAR)0x1f4,uLba >> 32);
WRITE_PORT_UCHAR((PUCHAR)0x1f5,uLba >> 40);
WRITE_PORT_UCHAR((PUCHAR)0x1f1,0);
WRITE_PORT_UCHAR((PUCHAR)0x1f2,uCounts);
WRITE_PORT_UCHAR((PUCHAR)0x1f3,uLba);
WRITE_PORT_UCHAR((PUCHAR)0x1f4,uLba >> 8);
WRITE_PORT_UCHAR((PUCHAR)0x1f5,uLba >> 16);
WRITE_PORT_UCHAR((PUCHAR)0x1f6,0x40);
WRITE_PORT_UCHAR((PUCHAR)0x1f7,0x24);
sleep(5000);
// (status = 0x50 && Error = 0x0)
KdPrint(("status = 0x%02x\n",READ_PORT_UCHAR((PUCHAR)0x3f6)));
KdPrint(("Error = 0x%02x\n",READ_PORT_UCHAR((PUCHAR)0x1f1)));
while (uCounts)
{
// 出错。读还到数据。死循环
while((READ_PORT_UCHAR((PUCHAR)0x1f7)&0xf)!=0x08)
{
sleep(5);
}
// (status = 0x50 && Error = 0x0)但读不到数据。
READ_PORT_BUFFER_USHORT((PUSHORT)0x1f0,(PUSHORT)buffer,256);
buffer += 512 ;
uCounts--;
}
}
void UnLoad(PDRIVER_OBJECT pDrvObj)
{
KdPrint(("UnLoad OK!\n"));
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDrvObj,PUNICODE_STRING pReg)
{
UCHAR szText[512] = {0};
Lba48Read(0x888888,1,szText);
for (USHORT i = 0; i < 512; i ++)
{
KdPrint(("%02x ",szText[i]));
if (i % 16 == 15) KdPrint((" --%d\n",i / 16 +1));
}
KdPrint(("Load OK!\n"));
pDrvObj->DriverUnload = UnLoad;
return STATUS_SUCCESS;
}
[课程]FART 脱壳王!加量不加价!FART作者讲授!