Page 1 of 2
IDE driver
Posted: Sat May 10, 2003 7:24 am
by slacker
to write data to disk you use 0x1f0 but i think the port is only 1 byte in size and in several tutorials i have looked at people have been using OUTSW and OUTSD....shouldnt people be using OUTSB?
Re:IDE driver
Posted: Sat May 10, 2003 6:14 pm
by slacker
also...
does anyone know why this code isnt working correctly to write data to
disk?
I call TestDisk(); TestDisk() completes but when i dump the disk(with
MS debug) to screen the bytes are left unchanged. any help would be
appreciated....
Code: Select all
---------------------
char DiskBuff[512];
--------------------
void WaitForDisk()
{
char Status;
Print("%waiting for ready...");
asm("cli");
do{
Status=PortIn(0x1F7);
Status=Status&0x80;
}while(Status!=0x00);
asm("sti");
Print("done\n");
}
--------------------
void SetNumSects(char NumSects)
{
WaitForDisk();
Print("%setting number sectors\n");
asm("cli");
PortOut(0x1F2, NumSects);
WaitForDisk();
asm("sti");
Print("done\n");
}
-----------------------------------
void SetSector(char Sector)
{
Print("%set sector\n");
WaitForDisk();
asm("cli");
PortOut(0x1F3, Sector);
WaitForDisk();
asm("sti");
Print("done\n");
}
-----------------------------------
void SetCylinderLow(char CylLow)
{
Print("%set cylinder low\n");
WaitForDisk();
asm("cli");
PortOut(0x1F4, CylLow);
WaitForDisk();
asm("sti");
Print("done\n");
}
----------------------------------------
void SetCylinderHigh(char CylHigh)
{
Print("%set cylinder high\n");
WaitForDisk();
asm("cli");
PortOut(0x1F5, CylHigh);
WaitForDisk();
asm("sti");
Print("done\n");
}
-------------------------------------
void SetDrive_Head()
{
Print("%set drive&head\n");
WaitForDisk();
asm("cli");
PortOut(0x1F6, 0xA0); //primary, head 0
WaitForDisk();
asm("sti");
Print("done\n");
}
--------------------------------------
void SendWrite()
{
Print("%sending write command...");
WaitForDisk();
asm("cli");
PortOut(0x1F7, 0x30);
WaitForDisk();
asm("sti");
Print("done\n");
}
----------------------------------
void CheckDRQ()
{
Print("%checking DRQ bit...");
asm("cli");
char DRQBit=0;
while(DRQBit!=0x08)
{
DRQBit=PortIn(0x1F7);
DRQBit=DRQBit&0x08;
}
asm("sti");
Print("done.\n");
}
-----------------------------------------
void Write()
{
CheckDRQ();
asm("cli");
Print("%writing disk...");
for(int i=0; i<512; i++)
{
PortOut(0x1F0,DiskBuff[i]);
Print("byte written\n");
}
WaitForDisk();
asm("sti");
}
---------------------------------------
void TestDisk()
{
InitBuffer();
SetNumSects(1);
SetSector(1);
SetCylinderLow(0);
SetCylinderHigh(0);
SetDrive_Head();
SendWrite();
Write();
Print("$text disk successful");
}
Re:IDE driver
Posted: Sun May 11, 2003 3:37 pm
by slacker
anyone....?
Re:IDE driver
Posted: Sun May 11, 2003 6:02 pm
by Tim
It would be a thousand times more useful for you to how to debug code on your own that it would be for somebody to post a fix to your code.
Translation: find the error yourself, and learn something in the process.
Re:IDE driver
Posted: Sun May 11, 2003 6:53 pm
by slacker
ok i kinda fixed the problem..but not really
when i write to disk(with my function), i can reboot the PC and read those same bytes correctly. but when i DUMP the disk to screen i dont see the bytes that i wrote...is it a problem with my code? or does "MS debug" have a special format or something that doesnt work the way my functions are expecting data?
Re:IDE driver
Posted: Mon May 12, 2003 6:14 am
by Pype.Clicker
i wouldn't use MS debug if i were you. That tool is likely to use logical sectors from within the partition rather than 'physical' sectors. Maybe you can use Norton Disk Editor or PCTools instead ... don't ask me for those tools, btw: i don't have the rights to share them.
Re:IDE driver
Posted: Mon May 12, 2003 11:47 am
by slacker
whats the difference between logical and physical sectors? also when i tried writing the bytes 0x55 and 0xAA in a loop to the first sector i still get the bios error message which means i am not writing the bootsector(sector 1) correctly right?
Re:IDE driver
Posted: Mon May 12, 2003 11:49 am
by slacker
also is it alright if i send data byte by byte to port 0x1f0 instead word by word? and read byte by byte?
Re:IDE driver
Posted: Mon May 12, 2003 1:37 pm
by slacker
also another problem i thoguht of was where the hell do i set the track number in the IDE registers??
Re:IDE driver
Posted: Mon May 12, 2003 3:16 pm
by df
slacker wrote:
also another problem i thoguht of was where the hell do i set the track number in the IDE registers??
track == cylinder
Re:IDE driver
Posted: Mon May 12, 2003 3:55 pm
by slacker
i didnt know tracks and cylinders are the same thing...
Re:IDE driver
Posted: Mon May 12, 2003 3:58 pm
by slacker
i got it working but also...when i send words to port 0x1f0 like 0xaa55 aa and 55 get switched so when i read should i always switch the word again?
Re:IDE driver
Posted: Tue May 13, 2003 5:13 am
by Pype.Clicker
slacker wrote:
i got it working but also...when i send words to port 0x1f0 like 0xaa55 aa and 55 get switched so when i read should i always switch the word again?
err .. remember on Intel processor the lowest byte is written the first, so if you put 0x12345678 on a 4-bytes memory region, it becomes 0x78 0x56 0x34 0x12 if you read it byte per byte
Re:IDE driver
Posted: Tue May 13, 2003 12:45 pm
by slacker
if a port is a word big, do i have to read a word from the port?
Re:IDE driver
Posted: Wed Jun 04, 2003 3:17 pm
by Pype.Clicker
i guess you should. i would surely give better results.