Page 1 of 2
Could someone help me about SATA PIO commond Programming
Posted: March 20th, 2012, 1:41
by corner
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!
Re: Could someone help me about SATA PIO commond Programming
Posted: March 20th, 2012, 4:47
by JWCC
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?
Re: Could someone help me about SATA PIO commond Programming
Posted: March 20th, 2012, 6:38
by corner
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...
Re: Could someone help me about SATA PIO commond Programming
Posted: March 20th, 2012, 13:16
by JWCC
Tried native? As in not a guest OS?
Re: Could someone help me about SATA PIO commond Programming
Posted: March 20th, 2012, 21:17
by corner
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.
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 7:00
by flykiller
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
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 11:36
by corner
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...
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 15:28
by quasimodo
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.
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.
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 18:29
by guru
use Victoria to check what port your SATA-Controller is mapped to
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 21:51
by corner
quasimodo wrote:1)Well 1F0-1F7 is correct for primary IDE.
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!
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 23:16
by corner
guru wrote:use Victoria to check what port your SATA-Controller is mapped to
Victoria checked the port is 1F0-1F7.
Re: Could someone help me about SATA PIO commond Programming
Posted: March 21st, 2012, 23:55
by quasimodo
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
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 1:45
by flykiller
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.
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 2:01
by quasimodo
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
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 2:02
by corner
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...
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 2:06
by corner
About VMWare stop itself detail reference another topic of mine:
problem-about-vmware-guset-emulate-ata-controller-t22455.htmlThank you very much!
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 21:18
by JWCC
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!
Re: Could someone help me about SATA PIO commond Programming
Posted: March 22nd, 2012, 21:59
by corner
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.
Re: Could someone help me about SATA PIO commond Programming
Posted: March 23rd, 2012, 3:25
by guru
Victoria works with API or PIO or both?
Re: Could someone help me about SATA PIO commond Programming
Posted: March 23rd, 2012, 17:34
by JWCC
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.