Not able to read ATAPI sector

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.
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Not able to read ATAPI sector

Post by amaneureka »

Hello, I'm very much new to this forum.
I'm working on ATAPI driver, I do all code what the osdev wiki says.
I'm able to detect and eject disk. But the issue is i'm not able to read sector on ATAPI device.

It is written in c# =P

Code: Select all

//Reading Function
        public void ReadSector(UInt64 SectorNo, uint SectorCount, byte[] xData)
        {
        }
SCSI Packet Sending Code

Code: Select all

        private void Send_SCSI_Package()
        {
        }
Regards
Aman Priyadarshi
Last edited by amaneureka on Wed Jul 16, 2014 1:37 pm, edited 1 time in total.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

Welcome to the OSDev forums.

Your code looks correct from what I can tell, but there are a few functions and classes that are not included, so it could be a problem with the code that you didn't include. It could also have something to do with the #warning lines above, although I have no idea what those lines are there for.

I am curious how you are writing an ATAPI driver in C#. I assume that this is for your own C# based OS. If the rest of the code is online somewhere, I'd be happy to take a look and see if I could figure out what is going on.

You could also try running this code in Bochs, which will usually notify you if you send the wrong information to the CDROM drive (or any other device, for that matter).
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

Those warning lines are just for mine sake of convenience. So that VS list that line in message box, And i don't have to search those line.

Yes Atomos is c# managed operating system. Almost written in C# and had its own compiler to compile the kernel =D
The source is closed so i can't provide you link. Can you give me idea how i can use bochs for investigate the issue ?


And very thanx for reply
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

Yep. Just download Bochs here: http://sourceforge.net/projects/bochs/files/

Install it and run either bochs.exe if you want to run your OS, or bochsdbg.exe if you want to step through it one instruction at a time.

You will need to tell bochs where your CD Image (.iso), Hard drive image (.hdd) or Floppy image (.img) is, and after you get everything set up, you are probably going to want to save your settings so that you don't have to set everything up every time. Then you can start the VM, and if you are using bochsdbg.exe, you can step through every instruction, even the BIOS. You can set a breakpoint at the start of your boot loader (I assume 0x7c00), and start stepping through your code from there.

Code: Select all

<bochs:1> b 0x7c00     // sets a breakpoint
<bochs:2> c       // continue - starts the virtual machine
<bochs:3> s       // steps through your code one instruction at a time
But either way, bochs will give you a console showing everything that is happening behind the scenes, and will notify you if there are any problems -- CPU errors, hardware errors, etc. It's very helpful for troubleshooting hardware issues.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

amaneureka wrote:Those warning lines are just for mine sake of convenience. So that VS list that line in message box, And i don't have to search those line.
Wow, I didn't know that was there. I'm going to have to remember that...

But, back to your problem, you may have an IRQ issue, if your interrupt handlers aren't working yet. I assume that is why the warnings are there.
amaneureka wrote:Yes Atomos is c# managed operating system. Almost written in C# and had its own compiler to compile the kernel =D
Well, if it helps, my OS is open source and posted up on codeplex: http://ozone.codeplex.com

The "compiler" is written in C#, but most of the "code" is actually written in XML, so it should, hopefully, be fairly easy to follow. One of the reasons that I chose XML was so that it would be easy to read, and easy to translate to other languages.

Check out this code to read a block from a IDE ATAPI CDROM: http://ozone.codeplex.com/SourceControl ... erator.xml

Just let me know if you have any questions, or if there is anything that I can do to help.
Last edited by SpyderTL on Wed Jul 16, 2014 9:54 am, edited 2 times in total.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

IRQ's are working fine, but the issue is when i submit SCSI packet command, I got IRQ..fine
but after reading of data from IO/Port than i didn't get any IRQ...but as mention in docs that cd-rom will send an IRQ of setting up disk for next command
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

One thing i forget to mention, The variable "Size" (Which i'm also printing to console) after sending SCSI command is giving out value zero
The variable which is send by controller telling that how many words it is sending and available to IO/Port reading.
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

For now, you might want to ignore the size value returned by the controller, and just assume that it will return 2048 bytes. You can probably ignore the missing IRQ, as well, until you figure out what is going on.

Also, you might want to try resetting the IDE controller before sending each ATA command, just to make sure that it is in a known state.

You might also want to hard-code the length to 1 block, and the LBA to zero, just to eliminate those variables, and to make sure everything else is working properly.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: Not able to read ATAPI sector

Post by dansmahajan »

amaneureka wrote: SCSI Packet Sending Code

Code: Select all

            //Send SCSI-Packet command to controller
            DataReg.Write16(xATAPI_Packet);
What about this area is it working fine ??? Is Write16() converting bytes to words before sending them over ??
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

yes this area is fine. I convert byte to words and sending it to IO/Port
Okay i mention code here

Code: Select all

        public void Write16(byte[] xData)
        {
            for (int i = 0; i < xData.Length; i+=2)
            {
                this.Outw((ushort)(xData[i + 1] >> 8 | xData[i]));
            }
        }
As i said Eject of disc is working fine. So there can be of no issue in sending SCSI packet as i assume
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

Ah! I tested in bochs and it is fine there, mean able to read ATAPI sector No change in source code.

Thanx everybody for lighting up my way. Now i'll investigate and FIX it...Again thanx =D
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

amaneureka wrote:yes this area is fine. I convert byte to words and sending it to IO/Port
Okay i mention code here

Code: Select all

        public void Write16(byte[] xData)
        {
            for (int i = 0; i < xData.Length; i+=2)
            {
                this.Outw((ushort)(xData[i + 1] >> 8 | xData[i]));
            }
        }
As i said Eject of disc is working fine. So there can be of no issue in sending SCSI packet as i assume
Ummm... Shouldn't that be a left shift? :)
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

hehe...yeah correct =D

One more thing to ask, take a look at below code

Code: Select all

        public IDE(bool aSecondary)
        {
            xBAR0 = (ushort)(aSecondary ? 0x0170 : 0x01F0);
            xBAR1 = (ushort)(aSecondary ? 0x0376 : 0x03F6);
            
            Channel = (aSecondary ? Channel.ATA_SECONDARY : Channel.ATA_PRIMARY);
            
            Init();
        }
I have a doubt in "xBAR1" somewhere i find it ( 0x0376, 0x0376 ) while somewhere (0x0374, 0x0374) and from bochs config file i got it (0x0370, 0x0370)

Which value is in real correct?

And That was the only issue with code that you highlighted now it is working fine in vmware...Thanx =D
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
amaneureka
Posts: 13
Joined: Mon Feb 11, 2013 10:29 am
Libera.chat IRC: amaneureka
Location: India
Contact:

Re: Not able to read ATAPI sector

Post by amaneureka »

A lot thanx...it is awesomely working =D

Image


Have a nice day
Regards
Aman Priyadarshi
http://atomixos.com/
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Not able to read ATAPI sector

Post by SpyderTL »

amaneureka wrote:hehe...yeah correct =D

One more thing to ask, take a look at below code

Code: Select all

        public IDE(bool aSecondary)
        {
            xBAR0 = (ushort)(aSecondary ? 0x0170 : 0x01F0);
            xBAR1 = (ushort)(aSecondary ? 0x0376 : 0x03F6);
            
            Channel = (aSecondary ? Channel.ATA_SECONDARY : Channel.ATA_PRIMARY);
            
            Init();
        }
I have a doubt in "xBAR1" somewhere i find it ( 0x0376, 0x0376 ) while somewhere (0x0374, 0x0374) and from bochs config file i got it (0x0370, 0x0370)

Which value is in real correct?
It depends on how you are doing your offsets. I think the first (or only) register you will need from xBAR1 is located at 0x03F6 for IDE1 and 0x376 for IDE2. If you want to change that to 0x3F0, and then add 6 to that, that is up to you. :)

So the short answer is, it doesn't matter, as long as you end up with 0x03F6 and 0x376.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply