CD-Rom Drive
CD-Rom Drive
what ATA/ATAPI Port should I use to open a cd drive?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: CD-Rom Drive
There's no single port for this. Ejecting a CD-ROM requires an ATAPI command like all others.
The specific command you need is 0x1B, which you'll find documented as LOAD UNLOAD or START STOP depending on the source. Apparently they considered unloading mechanically friendlier terminology than ejecting so the latter is probably not going to help out with other search queries.
The specific command you need is 0x1B, which you'll find documented as LOAD UNLOAD or START STOP depending on the source. Apparently they considered unloading mechanically friendlier terminology than ejecting so the latter is probably not going to help out with other search queries.
Re: CD-Rom Drive
Thanks Combuster
further qusestion. At first i write the adress of the device in the port (0x1f6) then I write the command in the command port.
Is the first port correct?
And is there something missing?
further qusestion. At first i write the adress of the device in the port (0x1f6) then I write the command in the command port.
Is the first port correct?
And is there something missing?
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: CD-Rom Drive
To send an ATAPI command, first select the drive by writing to port 0x1F6. Only select the slave bit, and you can leave the rest cleared.
Then, if you are going to use PIO, write 0x00 to port 0x1F1. If you are going to use DMA, construct the PRD in memory and write 0x01 to port 0x1F1.
Then determine how many bytes you'll need to send/receive from/to the ATAPI drive. This has a maximum of 65535 bytes (it's 16-bit). Write the low byte to port 0x1F4 and the high byte to port 0x1F5. And then send the ATAPI PACKET command, which is 0xA0, to port 0x1F7. Then poll for BSY to clear and DRQ to set, or wait for an IRQ.
Then, construct the ATAPI command in memory. ATAPI commands are 6 words (12 bytes) in size. The first byte is the command byte, in this case 0x1B as you wanted. The other 11 bytes are data bytes. I'm not sure what parameters does command 0x1B require, but you can search for that easily.
Then, send the 6 word ATAPI command using REP OUTSW to port 0x1F0. Then wait for an IRQ -- you cannot poll.
If this was a DMA transfer, it is now complete. If it was PIO, read/write from/to port 0x1F0.
Then, if you are going to use PIO, write 0x00 to port 0x1F1. If you are going to use DMA, construct the PRD in memory and write 0x01 to port 0x1F1.
Then determine how many bytes you'll need to send/receive from/to the ATAPI drive. This has a maximum of 65535 bytes (it's 16-bit). Write the low byte to port 0x1F4 and the high byte to port 0x1F5. And then send the ATAPI PACKET command, which is 0xA0, to port 0x1F7. Then poll for BSY to clear and DRQ to set, or wait for an IRQ.
Then, construct the ATAPI command in memory. ATAPI commands are 6 words (12 bytes) in size. The first byte is the command byte, in this case 0x1B as you wanted. The other 11 bytes are data bytes. I'm not sure what parameters does command 0x1B require, but you can search for that easily.
Then, send the 6 word ATAPI command using REP OUTSW to port 0x1F0. Then wait for an IRQ -- you cannot poll.
If this was a DMA transfer, it is now complete. If it was PIO, read/write from/to port 0x1F0.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: CD-Rom Drive
Thanks omarrx024.
and sry Combuster. I have overlooked the link in your post.
and sry Combuster. I have overlooked the link in your post.