LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reading from the disk via bios (https://www.linuxquestions.org/questions/programming-9/reading-from-the-disk-via-bios-757171/)

smeezekitty 09-23-2009 01:09 AM

reading from the disk via bios
 
hello, its me again
this time i need to read a sector on a diskette with a bios
in a real mode code i know about int 13h but 2 questions
will it work without dos loaded?
i have know ideas what a track or head is
how do i just read sectors?
for example
Code:

char buffer[513];
readsector(500, buffer);

would load sector 500
i hope so much that somone knows

theNbomr 09-23-2009 10:01 AM

BIOS calls are completely independent of DOS or any other OS. Parameters are passed in registers, and most BIOS level programming is therefore done in assembly language. You will probably need an OS as a development platform, and DOS works fine as a way of launching your program, once it is built.
Disks/diskettes are divided into tracks (cylinders), heads, and sectors. For diskettes, there are two heads, one to read each side of the media. The tracks are concentric, and numbered starting at zero, from the outermost edge of the diskette. Each track is broken into sectors, and a sector (512 bytes) is the fundamental quantum for reading & writing to the disk. You identify the sector of interest by specifying on which side/head of the diskette it exists, which track, and which sector number. These parameters are passed to the BIOS in the appropriate registers, along with a pointer to the place you want the read data to be stored.
On a diskette, there is no such thing as 'sector 500'. Hard disks can use something called Logical Block Addressing or Linear Block Addressing (LBA), where the drive internally maps heads/cylinders/sectors to a linear address scheme, such as you are suggesting. Diskettes do not use this. Your own code may perform this abstraction, but it is not a low-level service provided by the BIOS.

--- rod.

smeezekitty 09-23-2009 12:20 PM

i will have my code loaded with a bootloader.
i need to do a quick read from the disk at bootup.
i know that the bios doesnt translate the data but how do you write a code to do it?
i'd rather not drop to ASM, maybe ASM inside c(?)

theNbomr 09-23-2009 12:52 PM

What do you mean by translate? In your Int 13h read call, you will specify (in ES : DI, IIRC) the address of the buffer to receive the disk data. The one or more disk sectors requested will be concatenated there, verbatim from the disk. It is up to your code to interpret the data according to the requirements of your application.
--- rod.

smeezekitty 09-23-2009 12:57 PM

how many sectors per track is on a floppy?

theNbomr 09-23-2009 01:15 PM

Depends on the floppy. Each type has a different capacity, as a result of differing disk geometries. The number of sectors per track is typically in the range of 10 to 40. It is possible to format a diskette using non-standard geometries, as well.
--- rod.

smeezekitty 09-23-2009 01:36 PM

1.4 MB double sided -- does that help?

theNbomr 09-23-2009 03:12 PM

Wikipedia says.... 18.
--- rod.

cicorino 09-25-2009 02:30 AM

I wrote a bootloader, a bootcode and an os protected mode initcode for fun and I got the most useful information from three sources:
- a small useful text collection named 'helppc'
- the enormous ralph brown interrupt list
- the lilo code and the linux boot code for at least one i/o trick

I expect you'll just need to look at the bootcode of linux and at the way the kernel is composed (in the makefile) during the link phase to allow you to write your asm code beside your c code to "boot them". I think it is a fantastic occasion for you to learn a lot of important information.

Sorry, I have no time to help more


All times are GMT -5. The time now is 08:53 PM.