Page 1 of 1

most Basic ATA/ATAPI Driver

Posted: Thu Jan 04, 2007 5:48 pm
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

Posted: Thu Jan 04, 2007 6:06 pm
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.

Posted: Thu Jan 04, 2007 6:08 pm
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/

Posted: Thu Jan 04, 2007 6:20 pm
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 ;).

Posted: Thu Jan 04, 2007 6:25 pm
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 ;)

Posted: Thu Jan 04, 2007 7:04 pm
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: .

Posted: Thu Jan 04, 2007 7:22 pm
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.

Posted: Fri Jan 05, 2007 3:11 am
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

Posted: Fri Jan 05, 2007 6:04 am
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.

Posted: Fri Jan 05, 2007 11:31 am
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.

Posted: Fri Jan 05, 2007 12:32 pm
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!

Posted: Fri Jan 05, 2007 1:22 pm
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