All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Could someone help me about SATA PIO commond Programming
PostPosted: March 20th, 2012, 1:41 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
hi,all
with the code:
add dx, 0x7 //status
in al, dx
test al, (_STATUS_BSY_ | _STATUS_DRQ_)
I got the _STATUS_DRQ always is 0x1, never be cleared to ZERO..

What's wrong with my code ?(The port is correct! 1F0-1F7)
thx!


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 20th, 2012, 4:47 
Offline

Joined: February 13th, 2012, 5:29
Posts: 50
Location: United States
Have you tried MHDD 4.5? It has an ATA terminal that supports basic scripting, so that you can test out hardware responses before writing and debugging the real code. It looks like the drive isn't ever ready to transfer data using an I/O port... You SURE it's showing up under that port address? Again, MHDD (any version) and Victoria can tell you this. It is standard practice with these kinds of programs to display the flags, as well. Yeah, it's a nice debugging tool for your ATA commands. ;)

http://wiki.osdev.org/ATA_PIO_Mode This has some good information.

MHDD 4.5 and 4.6 are available on this site. Victoria I'll have to look up, but it wasn't hard to find.

Code:
/* on Primary bus: ctrl->base =0x1F0, ctrl->dev_ctl =0x3F6. REG_CYL_LO=4, REG_CYL_HI=5, REG_DEVSEL=6 */
int detect_devtype (int slavebit, struct DEVICE *ctrl)
{
   ata_soft_reset(ctrl->dev_ctl);      /* waits until master drive is ready again */
   outb(ctrl->base + REG_DEVSEL, 0xA0 | slavebit<<4);
   inb(ctrl->dev_ctl);         /* wait 400ns for drive select to work */
   inb(ctrl->dev_ctl);
   inb(ctrl->dev_ctl);
   inb(ctrl->dev_ctl);
   unsigned cl=inb(ctrl->base + REG_CYL_LO);   /* get the "signature bytes" */
   unsigned ch=inb(ctrl->base + REG_CYL_HI);

   /* differentiate ATA, ATAPI, SATA and SATAPI */
   if (cl==0x14 && ch==0xEB) return ATADEV_PATAPI;
   if (cl==0x69 && ch==0x96) return ATADEV_SATAPI;
   if (cl==0 && ch == 0) return ATADEV_PATA;
   if (cl==0x3c && ch==0xc3) return ATADEV_SATA;
   return ATADEV_UNKNOWN;
}

Have you seen that part yet?


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 20th, 2012, 6:38 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
thanks very much at first of all ( thanks about MHDD and Victoria)
I've seen this part of code already before I post this topic. I'm SURE that the port of 1F0-1F7 is correct(My SATA-Controller is oprating in PCI Compatibility Mode)
The problems following still make me perplexity....
1.
At first I thought I should execute a SOFTWARE RESET before polling the BSY-bit and DRQ-bit in Status-Register..When I try to toggle the SRST-bit in Control-Register and start wait for command completion...My VMWare was stop. (I execute the code above in a VMWare Virtual WindowsXP)
2.
So I tried to polling the BSY-bit and DRQ-bit without execute SOFTWARE RESET commond, And got the resoult above that I couldn't understand...


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 20th, 2012, 13:16 
Offline

Joined: February 13th, 2012, 5:29
Posts: 50
Location: United States
Tried native? As in not a guest OS?


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 20th, 2012, 21:17 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
JWCC wrote:
Tried native? As in not a guest OS?

The code was executed in a GUEST-OS, the error is Not a GUEST-OS BSOD. Looks like the Action broken the Virtualization of VMWare, then the VMWare was stop.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 7:00 
Offline

Joined: March 11th, 2012, 12:36
Posts: 27
Location: china
corner wrote:
JWCC wrote:
Tried native? As in not a guest OS?

The code was executed in a GUEST-OS, the error is Not a GUEST-OS BSOD. Looks like the Action broken the Virtualization of VMWare, then the VMWare was stop.

if you operate softest ,You port addr error!try 0x1fa


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 11:36 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
flykiller wrote:
corner wrote:
JWCC wrote:
Tried native? As in not a guest OS?

The code was executed in a GUEST-OS, the error is Not a GUEST-OS BSOD. Looks like the Action broken the Virtualization of VMWare, then the VMWare was stop.

if you operate softest ,You port addr error!try 0x1fa

first: what did you mean about "operate softtest"?
second: what is the usage of PORT 0x1FA? I have never seen PORT 0x1FA mentioned in ATA-spec...


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 15:28 
Offline

Joined: October 23rd, 2006, 8:56
Posts: 1342
corner wrote:
hi,all
with the code:
add dx, 0x7 //status
in al, dx
test al, (_STATUS_BSY_ | _STATUS_DRQ_)
I got the _STATUS_DRQ always is 0x1, never be cleared to ZERO..

What's wrong with my code ?(The port is correct! 1F0-1F7)
thx!



1)Well 1F0-1F7 is correct for primary IDE.

Quote:
My SATA-Controller is oprating in PCI Compatibility Mode)

2)I would use IDE port and connect a IDE-SATA adapter.

3) I think trying to work with ASM in VMWare is asking for trouble, use a standalone system if you have the option.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 18:29 
Offline
User avatar

Joined: May 5th, 2004, 20:06
Posts: 2831
Location: England
use Victoria to check what port your SATA-Controller is mapped to

_________________
All went well until I plugged the drive in.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 21:51 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
quasimodo wrote:
1)Well 1F0-1F7 is correct for primary IDE.
Quote:
My SATA-Controller is oprating in PCI Compatibility Mode)

2)I would use IDE port and connect a IDE-SATA adapter.
3) I think trying to work with ASM in VMWare is asking for trouble, use a standalone system if you have the option.


about (1): yeah, you are right and 1F0-1F7 is correct. It's Class Code is "0x01018A" of my PCI-ATA-Controller which "8A" mean that it's running in PCI Compatibility Mode.(The BAR0-BAR3 is invalid).
about (3): I had tried another OPERATION(i.e mov dx, 0x17F in ax, dx), The VMWare also stop itself after instruction "in ax, dx" was executed. (These OPERATIONs is operated under Windows-XP-Kernel-Mode.)
The CORRECT instruction is "in al, dx". So what will happen when the wrong instruction "in ax, dx" is executed under a standalone-system ?

At Last:
corner wrote:
hi,all
with the code:
add dx, 0x7 //status
in al, dx
test al, (_STATUS_BSY_ | _STATUS_DRQ_)
I got the _STATUS_DRQ always is 0x1, never be cleared to ZERO..

What's wrong with my code ?(The port is correct! 1F0-1F7)
thx!

The reason is there is no one IDE-hard-disk attached to ATA-Controller on my VMWare-Guest-OS. They are all SCSI-hard-disk.
THANKS ALL YOU ARE THE BEST!


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 23:16 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
guru wrote:
use Victoria to check what port your SATA-Controller is mapped to

Victoria checked the port is 1F0-1F7.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 21st, 2012, 23:55 
Offline

Joined: October 23rd, 2006, 8:56
Posts: 1342
corner wrote:
hi,all
with the code:
add dx, 0x7 //status
in al, dx
test al, (_STATUS_BSY_ | _STATUS_DRQ_)
I got the _STATUS_DRQ always is 0x1, never be cleared to ZERO..
corner wrote:
What's wrong with my code ?(The port is correct! 1F0-1F7)
thx!

The reason is there is no one IDE-hard-disk attached to ATA-Controller on my VMWare-Guest-OS. They are all SCSI-hard-disk.
THANKS ALL YOU ARE THE BEST!


Code:
in al, dx
this should be the correct instruction, but I think you should be able to use ax as well, as long as your code continues to use the entire 16 bit register not just the lower half. but I am no expert on asm, so maybe someone else can confirm it for you.

Also I would think you should use mov rather than add
Code:
add dx, 0x7 //status


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 1:45 
Offline

Joined: March 11th, 2012, 12:36
Posts: 27
Location: china
quasimodo wrote:
corner wrote:
hi,all
with the code:
add dx, 0x7 //status
in al, dx
test al, (_STATUS_BSY_ | _STATUS_DRQ_)
I got the _STATUS_DRQ always is 0x1, never be cleared to ZERO..
corner wrote:
What's wrong with my code ?(The port is correct! 1F0-1F7)
thx!

The reason is there is no one IDE-hard-disk attached to ATA-Controller on my VMWare-Guest-OS. They are all SCSI-hard-disk.
THANKS ALL YOU ARE THE BEST!


Code:
in al, dx
this should be the correct instruction, but I think you should be able to use ax as well, as long as your code continues to use the entire 16 bit register not just the lower half. but I am no expert on asm, so maybe someone else can confirm it for you.

Also I would think you should use mov rather than add
Code:
add dx, 0x7 //status

If dx = 0x1f0 ,add dx,7 then dx=0x1f7 = cmd(write)or status(read).
But some time cmd port != controller port.Softreset
need send 0x
4 to controller port and poll status.
If bsy bit was clear,send 0x0 again.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 2:01 
Offline

Joined: October 23rd, 2006, 8:56
Posts: 1342
Yes I agree if dx is already 0x1f0 then he can add x07. Since I did not see his code I suggested mov dx, 0x1f7


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 2:02 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
quasimodo wrote:
this should be the correct instruction, but I think you should be able to use ax as well, as long as your code continues to use the entire 16 bit register not just the lower half. but I am no expert on asm, so maybe someone else can confirm it for you.

Code:
in ax, dx

This code can't execute currect under VMWare-Guest-OS. Result in VMWare stop itself~~ Not Guest-OS crash...


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 2:06 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
About VMWare stop itself detail reference another topic of mine:
problem-about-vmware-guset-emulate-ata-controller-t22455.html
Thank you very much!


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 21:18 
Offline

Joined: February 13th, 2012, 5:29
Posts: 50
Location: United States
corner wrote:
JWCC wrote:
Tried native? As in not a guest OS?

The code was executed in a GUEST-OS, the error is Not a GUEST-OS BSOD. Looks like the Action broken the Virtualization of VMWare, then the VMWare was stop.

This could be exploited for evil... hehe, pretty funny bug. Just execute these few bytes in a kernel module or something and WHAM, crash the debugging host as well as the virtualized guest in order to prevent white-hat reversing. Hopefully, there's a patch coming up that can prevent this malware trick.

Emulators are generally a poor substitute for real hardware when learning assembly or other low-level stuff. For an example, on the SNES there was a tool to add custom sounds/music to Super Mario World. It would cause the game to crash on a real system but worked fine in emulators! Lesson learned: Test this low-level stuff out on real hardware!


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 22nd, 2012, 21:59 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
JWCC wrote:
This could be exploited for evil... hehe, pretty funny bug. Just execute these few bytes in a kernel module or something and WHAM, crash the debugging host as well as the virtualized guest in order to prevent white-hat reversing. Hopefully, there's a patch coming up that can prevent this malware trick.

Did you test the code ?(the incorrect code: in ax, dx correct code: in al, dx which dx-value is 0x1F7)

JWCC wrote:
Emulators are generally a poor substitute for real hardware when learning assembly or other low-level stuff. For an example, on the SNES there was a tool to add custom sounds/music to Super Mario World. It would cause the game to crash on a real system but worked fine in emulators! Lesson learned: Test this low-level stuff out on real hardware!

I've no enough stuff to explain VMWare is weak to emulate Hardware.
Whatever, Victoria run well.... So I think we will resolve this trouble.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 23rd, 2012, 3:25 
Offline
User avatar

Joined: May 5th, 2004, 20:06
Posts: 2831
Location: England
Victoria works with API or PIO or both?

_________________
All went well until I plugged the drive in.


Top
 Profile  
 
 Post subject: Re: Could someone help me about SATA PIO commond Programming
PostPosted: March 23rd, 2012, 17:34 
Offline

Joined: February 13th, 2012, 5:29
Posts: 50
Location: United States
guru wrote:
Victoria works with API or PIO or both?

You mean under VMWare? I remember seeing both options at the top ('radio buttons') but I haven't really had a reason (until now) to run it in a VM.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group