most Basic ATA/ATAPI Driver

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.
Post Reply
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

most Basic ATA/ATAPI Driver

Post by GLneo »

hello everyone, i just want to read some sectors from a cd-rom drive the easyest way, does anyone have a simple driver or a simple tutorial? i've looked at a lot of drivers and they are more than i need.

thx
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

You can take a look at my code for CdPod, its got a basic ATAPI driver, it does not have a read function, but you just need to send the right commands etc.
http://www.dex4u.com/cdpod/cdpod.zip

Note: to fit it in 512bytes, the address were hard coded in, you may need to change theres.
Last edited by Dex on Thu Jan 04, 2007 6:10 pm, edited 2 times in total.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

@Dex, You like assuming everyone uses pure ASM.. :wink:

You might want to peek at one of the OSDev members projects..

Or just look at these sites :)

http://www.ata-atapi.com/
http://www.t13.org/
Last edited by Brynet-Inc on Thu Jan 04, 2007 6:21 pm, edited 1 time in total.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

Brynet-Inc wrote:@Dex, You like assuming everyone uses pure ASM.. :wink:
I dunno, if you can't figure out that out and in are the same as outp and inp in C, then I don't think you should be doing OS dev ;). Code supplied in asm is as good as any in my books, especially for something low level like atapi interfacing, as it's mostly in's and out's, it shouldn't be to hard to figure out what's going on. Anyways, those sites you listed are also good places to look, just wanted to point out that pure ASM isn't a bad thing, and if someone can't understand assembly, they might not want to do to much OS dev until they understand more about the hardware and low level stuff like assembly. could you imagine writing an entire OS without assembly? You couldn't install a timer interrupt, or any other interrupt for that matter, nor could you setup a GDT or paging, forget virtual memory, you can't handle the page fault interrupt. Of course you could get grub to set some of this up for you, but still no multi-tasking, or any such stuff ;).
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Ready4Dis wrote:I dunno, if you can't figure out that out and in are the same as outp and inp in C, then I don't think you should be doing OS dev ;). Code supplied in asm is as good as any in my books, especially for something low level like atapi interfacing, as it's mostly in's and out's, it shouldn't be to hard to figure out what's going on. Anyways, those sites you listed are also good places to look, just wanted to point out that pure ASM isn't a bad thing, and if someone can't understand assembly, they might not want to do to much OS dev until they understand more about the hardware and low level stuff like assembly. could you imagine writing an entire OS without assembly? You couldn't install a timer interrupt, or any other interrupt for that matter, nor could you setup a GDT or paging, forget virtual memory, you can't handle the page fault interrupt. Of course you could get grub to set some of this up for you, but still no multi-tasking, or any such stuff ;).
Alright, Back down sparky..

I was saying in a convenience sense, Can be a bit annoying to see a large uncommented assembly-mess compared to a fairly decent implementation in C.

I'm not writing an OS... I just like bothering people like you who are ;)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

@Brynet-Inc, Why do you not help me out here and point me to a small simple ATAPI driver coded in C with commands, from a hobby OS :wink: .
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

Brynet-Inc wrote:
Ready4Dis wrote:I dunno, if you can't figure out that out and in are the same as outp and inp in C, then I don't think you should be doing OS dev ;). Code supplied in asm is as good as any in my books, especially for something low level like atapi interfacing, as it's mostly in's and out's, it shouldn't be to hard to figure out what's going on. Anyways, those sites you listed are also good places to look, just wanted to point out that pure ASM isn't a bad thing, and if someone can't understand assembly, they might not want to do to much OS dev until they understand more about the hardware and low level stuff like assembly. could you imagine writing an entire OS without assembly? You couldn't install a timer interrupt, or any other interrupt for that matter, nor could you setup a GDT or paging, forget virtual memory, you can't handle the page fault interrupt. Of course you could get grub to set some of this up for you, but still no multi-tasking, or any such stuff ;).
Alright, Back down sparky..

I was saying in a convenience sense, Can be a bit annoying to see a large uncommented assembly-mess compared to a fairly decent implementation in C.

I'm not writing an OS... I just like bothering people like you who are ;)
Yeah, I know, hence the smileys/winks, just like giving people a hard time that like to give others a hard time :P.
User avatar
Combuster
Member
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:

Post by Combuster »

Brynet-Inc wrote:@Dex, You like assuming everyone uses pure ASM.. :wink:
He probably isn't, and even if he is it shouldn't be a problem. IMO Assembly can be easier to read than C, if its documented properly. If one can understand what the code does then it doesnt matter in which language it is written. A good documenter may even be able to make brainfuck understandable for me. Putting up links to poorly commented sources is a Don't unless there isn't anything else to be found. (try reading the video card drivers in the X.org sources)

Now, lets stop this off-topic discussion before we end up with antother locked topic
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
octavio
Member
Member
Posts: 94
Joined: Wed Oct 25, 2006 5:12 am
Location: Barcelona España
Contact:

Post by octavio »

Brynet-Inc wrote:@Dex, You like assuming everyone uses pure ASM.. :wink:
It is correct to assume it ,you can write a OS without using :C, Pascasl,C++
but not without using assembly.So everybody here must be familiar with assembly.Also the first poster did not specified any programing language.
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

I was beginning to think that I was the only one who didn't have an allergic reaction to asm; given the posts you frequently see around OS development forums.
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

i would like a c example, but i did understand Dex's code, it just doesnt do much(turn on cd player) but thx anyway :wink:

hence the smileys/winks
:-({|= :-& O:) :-k \:D/ :-# :^o [-X [-o< theres a lot here FUN!
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Here's how it works, to do anything with the CD, you need to send it a command, These command's are in the form of 12 byte packets, now what packet you send does differant things.
Now one of the first and most important parts of any ATAPI driver is
"Send_Atapi_Packet", as with out it you can do nothing.
That what in the code, but in that example it sends command play cd or stop playing cd.
You need to look up ATAPI commands for things like "Read_disk"
Heres what you will find:

Code: Select all

PacketBuffer:
db 28h             ; Operation Code
db 0                  ; Byte 1- Reserved
dd 10000000h  ; Logical Block Address (16= ISO9660 Primary Volume Descriptor)
db 0                 ; Byte 6 - Reserved
dw 0100h         ; Transfer Lengt (1 sector)
db 3 dup(0)     ; Byte 9 to 11 are Reserved
Post Reply