IDE driver

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
slacker

IDE driver

Post 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?
slacker

Re:IDE driver

Post 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");
}
slacker

Re:IDE driver

Post by slacker »

anyone....?
Tim

Re:IDE driver

Post 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.
slacker

Re:IDE driver

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:IDE driver

Post 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.
slacker

Re:IDE driver

Post 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?
slacker

Re:IDE driver

Post 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?
slacker

Re:IDE driver

Post by slacker »

also another problem i thoguht of was where the hell do i set the track number in the IDE registers??
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:IDE driver

Post 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
-- Stu --
slacker

Re:IDE driver

Post by slacker »

i didnt know tracks and cylinders are the same thing...
slacker

Re:IDE driver

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:IDE driver

Post 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
slacker

Re:IDE driver

Post by slacker »

if a port is a word big, do i have to read a word from the port?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:IDE driver

Post by Pype.Clicker »

i guess you should. i would surely give better results.
Post Reply