All times are UTC - 5 hours [ DST ]


Forum rules


Please do not post questions about data recovery cases here (use this forum instead). This forum is for topics on finding new ways to recover data. Accessing firmware, writing programs, reading bits off the platter, recovering data from dust...



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Accesing hardisk from asm
PostPosted: May 9th, 2015, 13:09 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
i am writing an asm (NBASM) program to access the hard drive. I am using Ubuntu. I have put the bios in ata(IDE) mode.
My asm code to test busy flag
section .data
msg db "hello, world!"

section .text
global _start
_start:
MOV DX, 177h ;status register
LOOP1:
IN AL, DX

AND AL, 10000000b
JNE LOOP1

however when i run the program i get segmentation fault. Also if any one mention me the port address to access the drive it would be helpfull


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 9th, 2015, 14:49 
Offline
User avatar

Joined: May 13th, 2010, 11:17
Posts: 2517
Location: Kuwait
Always start FROM where others STOPPED. never from the beginning. (unless you have plenty of time of course)

_________________
Kuwait Data Recovery - UNIX GTC
The only reason for time is so that everything doesn't happen at once. By: Albert Einstein


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 9th, 2015, 15:08 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
can u please give me some links


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 9th, 2015, 15:50 
Offline
User avatar

Joined: September 8th, 2009, 18:21
Posts: 11709
Location: Australia
See viewtopic.php?f=13&t=26971

_________________
A backup a day keeps DR away.


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 9th, 2015, 16:14 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
tnks tat was really helpfull


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 11th, 2015, 17:39 
Offline

Joined: January 29th, 2012, 1:43
Posts: 642
Location: United States
Since you mentioned using Ubuntu, my following answer is Linux specific. If you are writing this code as a kernel driver and installing it as such then I am not sure if this answer applies. However, if you are just creating an executable and running it from user space then this most likely will apply to you.

I am not familiar with assembly, but I do write in C. And C is just compiled into assembly so I am almost certain that this would apply to you.

The first and most obvious thing is the program must be run as root, using sudo or su (super user). If you try to access a port without root access it will seg fault.

The second and not so obvious thing is that when in Linux, your program MUST ask permission from the kernel to access a port before it tries to. I can say from experience that if you forget that code or get it wrong, you will get a seg fault every time! In C the call is to ioperm. I do not know how this would be done in assembly.

Useful commands to list ports in Linux:

cat /proc/ioports
This will produce a very basic list of available ports. Useful if you already know what you are looking for.

lspci -v
This will produce very detailed information, port addresses can be found in this. And there is enough information that you can tell more or less what they belong to.

Hope this is useful information.

_________________
http://www.sdcomputingservice.com
Home of HDDSuperClone and HDDSuperTool


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 12th, 2015, 7:30 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
output of ioport filterred by hardisk drivers

4060-406f : ata_piix

4070-407f : ata_piix

4080-408f : ata_piix

4090-409f : ata_piix

40a0-40a7 : ata_piix

40a8-40af : ata_piix

40b0-40b7 : ata_piix

40b8-40bf : ata_piix

40c0-40c3 : ata_piix

40c4-40c7 : ata_piix

40c8-40cb : ata_piix

40cc-40cf : ata_piix



here there are lot of ports which particular port should i access. If i need to scan them one by on e how to do that any help



output of lspci -v
00:1f.2 IDE interface: Intel Corporation 7 Series Chipset Family 4-port SATA Controller [IDE mode] (rev 04) (prog-if 8f [Master SecP SecO PriP PriO])
Subsystem: Dell Device 05b8
Flags: bus master, 66MHz, medium devsel, latency 0, IRQ 19
I/O ports at 40b8 [size=8]
I/O ports at 40cc [size=4]
I/O ports at 40b0 [size=8]
I/O ports at 40c8 [size=4]
I/O ports at 4090 [size=16]
I/O ports at 4080 [size=16]
Capabilities: <access denied>
Kernel driver in use: ata_piix




00:1f.5 IDE interface: Intel Corporation 7 Series Chipset Family 2-port SATA Controller [IDE mode] (rev 04) (prog-if 85 [Master SecO PriO])
Subsystem: Dell Device 05b8
Flags: bus master, 66MHz, medium devsel, latency 0, IRQ 21
I/O ports at 40a8 [size=8]
I/O ports at 40c4 [size=4]
I/O ports at 40a0 [size=8]
I/O ports at 40c0 [size=4]
I/O ports at 4070 [size=16]
I/O ports at 4060 [size=16]
Capabilities: <access denied>
Kernel driver in use: ata_piix


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 12th, 2015, 17:15 
Offline

Joined: January 29th, 2012, 1:43
Posts: 642
Location: United States
Starting with the normal basic information copied from http://lateblt.tripod.com/atapi.htm

Primary IDE controller: 1F0h to 1F7h and 3F6h to 3F7h
Secondary IDE controller: 170h to 177h and 376h to 377h
1F0 (Read and Write): Data Register
1F1 (Read): Error Register
1F1 (Write): Features Register
1F2 (Read and Write): Sector Count Register
1F3 (Read and Write): LBA Low Register
1F4 (Read and Write): LBA Mid Register
1F5 (Read and Write): LBA High Register
1F6 (Read and Write): Drive/Head Register
1F7 (Read): Status Register
1F7 (Write): Command Register
3F6 (Read): Alternate Status Register
3F6 (Write): Device Control Register

So for your 4-port controller the equivalent would be:
I/O ports at 40b8 [size=8] = 40b8-40bf = Primary IDE controller: 1F0h to 1F7h
I/O ports at 40cc [size=4] = 40cc-40cf = Primary IDE controller: 3F6h to 3F7h (this is tricky, but normally the third byte (40ce in this case) is the equivalent to 3F6)
I/O ports at 40b0 [size=8] = 40b0-40b7 = Secondary IDE controller: 170h to 177h
I/O ports at 40c8 [size=4] = 40c8-40cb = Secondary IDE controller: 376h to 377h (40ca would = 376)
I/O ports at 4090 [size=16] - for DMA access, don't mess with these ports
I/O ports at 4080 [size=16] - for DMA access, don't mess with these ports

The 2-port controller works the same way except the secondary controller will always give results of no drives attached.

_________________
http://www.sdcomputingservice.com
Home of HDDSuperClone and HDDSuperTool


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 14th, 2015, 17:35 
Offline

Joined: April 28th, 2015, 9:15
Posts: 5
Location: United States
You know, you don't have to use ASM just to do direct IO.
You can use C as well using "io.h" with "inb_p()", "outb_p()", etc.

You can also do this with Windows. I did this with an old DOS version of a Microsoft C/C++ compiler.
And also for PC platform using real (16bit segment mode) or 32bit flat mode using the Watcom compiler (now open source).
Just need to boot into FreeDOS or similar.

Just a suggestion, maybe easier to use C, and, or C++..


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 19th, 2015, 0:36 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
i started programming in c it was lot easier than asm. I have written a program to send identify cmd and display the device information. But i am trying to read he data using PIO and DMA mode and i have got stuck. Can some one please point me to code examples with good commenting.


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: May 19th, 2015, 18:02 
Offline

Joined: January 29th, 2012, 1:43
Posts: 642
Location: United States
I personally do not know of any good code examples to help you, as I never found any myself. But if you have written code to send the identify command and get the device information, then you are already achieving PIO mode and reading data. You just have to adjust it for reading sectors.

But I will say this. Considering the context of the situation and conditions you have provided so far, you need to understand that DMA is about 1000 times harder than PIO. Stick with PIO. If you master PIO then maybe you can attempt DMA in the future.

_________________
http://www.sdcomputingservice.com
Home of HDDSuperClone and HDDSuperTool


Top
 Profile  
 
 Post subject: Re: Accesing hardisk from asm
PostPosted: June 2nd, 2015, 9:35 
Offline

Joined: April 17th, 2015, 2:05
Posts: 33
Location: India
i was able to read sectors using PIO mode.
The data transfer speed is around 3MB/s. I programmed the timing registers still no change in speed.
So i am trying to code using AHCI mode. My abar register is at location 0xc1617000. I am trying to access the PI register at offset 0x0c to detect the presence of hardriive. Well i tried using inb,inw instruction but not working. This registers are memory mapped IO. I to deal with this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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