LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2009, 01:09 AM   #1
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
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
 
Old 09-23-2009, 10:01 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 09-23-2009, 12:20 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
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(?)
 
Old 09-23-2009, 12:52 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

Last edited by theNbomr; 09-23-2009 at 03:16 PM.
 
Old 09-23-2009, 12:57 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
how many sectors per track is on a floppy?
 
Old 09-23-2009, 01:15 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 09-23-2009, 01:36 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
1.4 MB double sided -- does that help?
 
Old 09-23-2009, 03:12 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Wikipedia says.... 18.
--- rod.
 
Old 09-25-2009, 02:30 AM   #9
cicorino
Member
 
Registered: May 2006
Location: Italy
Distribution: Slackware, Slackware64
Posts: 31

Rep: Reputation: 16
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GRUB reading BIOS date / time for conditional boot preferences Al_ Linux - Software 6 12-02-2010 12:17 PM
Is booting usb disk possible despite old BIOS? hilltownboy Linux - Software 26 04-05-2008 11:08 AM
Slow disk detection by BIOS MQMan Linux - Hardware 3 09-15-2007 06:50 PM
After blackout, BIOS doesn't see hard disk simopal6 General 8 07-31-2007 11:44 AM
Hard disk bios support BigDanny Linux - Newbie 2 06-08-2004 04:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration