IDE driver
IDE driver
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
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....
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
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.
Translation: find the error yourself, and learn something in the process.
Re:IDE driver
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?
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?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:IDE driver
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
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
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
also another problem i thoguht of was where the hell do i set the track number in the IDE registers??
Re:IDE driver
track == cylinderslacker wrote: also another problem i thoguht of was where the hell do i set the track number in the IDE registers??
-- Stu --
Re:IDE driver
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?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:IDE driver
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 byteslacker 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?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact: