Hello to all,
I m writing the Diagnostic code for the HDD. In that i want to do the following test
- Locate the sectors
- Reading the data from the sector
- Saving the original data into some buffer
- Writing the new data into that sectors
- Again reading back the data from the sector
- Comparing the data
- Again putting the original data back to the sectors.
I want to do all theses steps from the user application layer. For that i m using the read , write commands on the registers present inside the IDE controller.
My code is #include #include #include #include #include #include #include #include #include #include #include
#define HDD_SECTOR_COUNT_REG 0x1f2 #define HDD_CYLINDER_LOW_REG 0x1f4 #define HDD_CYLINDER_HIGH_REG 0x1f5 #define HDD_SECTOR_NUM_REG 0x1f3
#define HDD_BASE 0x1f0 #define HDD_ERROR_REG 0X1f1 #define HDD_STATUS_COMM_REG 0x1f7 #define HDD_HEAD_DRIVE_REG 0x1f6 #define HDD_DATA_READY 0x08 #define HDD_READ_SECTOR 0x20 #define HDD_BUSY 0x80 #define HDD_WRITE_SECTOR 0x30
#include #include #include #include #include #include #include #include #include #include #include
int ReadSector(); void WriteSector();
int main() {
int data2; ioperm(HDD_BASE,8,1); data2 = ReadSector(); printf("the original data = %d\n",data2); WriteSector(); ReadSector(); return 0; }
int ReadSector() { int status,status1,status2,status3,status4; int i,SectCnt; int Buffer[256]; int LBA_Adress = 400; int val; int data=0; int data3=0; while(1) { val=inb(HDD_STATUS_COMM_REG); if(val != 0x80) { printf("not busy\n");
break; } else printf("Busy\n"); } outb((LBA_Adress & 0xff),HDD_SECTOR_NUM_REG);
status=inb(HDD_SECTOR_NUM_REG); printf("%d\n",status);
outb(((LBA_Adress>>16) & 0xff),HDD_CYLINDER_HIGH_REG); outb(((LBA_Adress>>8) & 0xff),HDD_CYLINDER_LOW_REG); outb(((((LBA_Adress>>24)&0x0f) | 0xE0) &
0xff),HDD_HEAD_DRIVE_REG); outb(SectCnt,HDD_SECTOR_COUNT_REG);while(!(inb(HDD_STATUS_COMM_REG)&HDD_DATA_READY));
printf("Data Ready\n");
Buffer[0]=0; for(i=0;i>16) & 0xff),HDD_CYLINDER_HIGH_REG); outb(((LBA_Adress>>8) & 0xff),HDD_CYLINDER_LOW_REG); outb(((((LBA_Adress>>24)&0x0f) | 0xE0) &
0xff),HDD_HEAD_DRIVE_REG); outb(HDD_READ_SECTOR,HDD_STATUS_COMM_REG); outb(HDD_READ_SECTOR,HDD_STATUS_COMM_REG); outb(SectCnt,HDD_SECTOR_COUNT_REG); outb(HDD_WRITE_SECTOR,HDD_STATUS_COMM_REG);while(!(inb(HDD_STATUS_COMM_REG)&HDD_DATA_READY));
printf("Data Ready\n"); outb(data,HDD_BASE); printf("%d\n",data); }
I m using Linux SUSE OS. After execution i m getting the o/p as not busy Data Ready data3 = 0 the original data = 0 not busy Data Ready
255 not busy Data Ready data3 = 0That means after reading the Sector i get the first byte =0 Then i m writing 255 at the same ocation and reading back. But this time also i m getting the same date =0 instead of 255
At the same time after execution i m not able to login in Windows(i m working in duo mode--Linux and Wnddows) It is give me error that /system32/hal.dii file is missing or being currupted.....
Can anyone please tell me whether i m going on the right direction or not. What is the problem in my code? I don't want to do the programming from the Kernel mode.
Please guide me.....
Thanks and Regards, Nutty.