OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 9:37 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: LBA / CHS confusion !
PostPosted: Sun Jun 22, 2008 6:20 am 
Offline

Joined: Sun Jun 22, 2008 6:04 am
Posts: 13
Hello there !
I am new to operating system development, and before learning about the kernel, I decided to write a small (2 stage) bootloader;
I have read about CHS and LBA, but after looking at GRub Stage1 I was confused. And here are my questions:
a. Is LBA just a method of expressing blocks in a linear mode ? (you still have to convert lba address to chs in order to read from a device)
b. Whose extension is INT 0x13 AH=41 checking ? (BIOS extension AH=42 for reading blocks using LBA addressing mode ?!)
c. Is GRub loading stage2 from a well known-place and implementing FS i/o in stage2 ? ... or it searches the device for a file named " ... "


Top
 Profile  
 
 Post subject: Re: LBA / CHS confusion !
PostPosted: Sun Jun 22, 2008 7:54 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 3:40 am
Posts: 179
Location: Arad, Romania
deph wrote:
Hello there !
I am new to operating system development, and before learning about the kernel, I decided to write a small (2 stage) bootloader;
I have read about CHS and LBA, but after looking at GRub Stage1 I was confused. And here are my questions:
a. Is LBA just a method of expressing blocks in a linear mode ? (you still have to convert lba address to chs in order to read from a device)
Yes, LBA is a way of addressing the disk in a linear way, but for any modern drive there is no need to convert the value to CHS before sending it to the drive. The drive will happily accept, and properly work with a LBA address.

Also, Grub's stage 2 is loaded from a known sector. Stage 1 is told which sector when Grub is installed on the hard drive.

_________________
~[Fluidium]~


Top
 Profile  
 
 Post subject: Re: LBA / CHS confusion !
PostPosted: Sun Jun 22, 2008 8:15 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
deph wrote:
Hello there !
I am new to operating system development, and before learning about the kernel, I decided to write a small (2 stage) bootloader;
I have read about CHS and LBA, but after looking at GRub Stage1 I was confused. And here are my questions:
a. Is LBA just a method of expressing blocks in a linear mode ? (you still have to convert lba address to chs in order to read from a device)
b. Whose extension is INT 0x13 AH=41 checking ? (BIOS extension AH=42 for reading blocks using LBA addressing mode ?!)
c. Is GRub loading stage2 from a well known-place and implementing FS i/o in stage2 ? ... or it searches the device for a file named " ... "


Hi,

(a) LBA stands for Logical Block Addressing - it's a method of expressing the location of a sector on disk. The three currently (normally) supported methods are CHS, LBA24 and LBA48 - the two latter being variations on the same scheme that merely use a different number of bits to represent an address (28 and 48 bits, respectively).

Most hard disk controllers support LBA28 - you can tell if a bit is set in the HDD's response to the ATA IDENTIFY command. To address in LBA you actually use the same registers as CHS (lba address >> 16 goes in the "head" register, address >> 8 goes in "cylinder", etc) so to someone looking at LBA code it could look like CHS is actually being used, and I assume this is what's confusing you.

(b) I'm not qualified to comment on - I've never used BIOS functions.

(c) Again, I'm not fully qualified to comment but I believe that GRUB uses a three-stage bootload - stage1 (in the MBR), stage1.5 then finally stage2. I'll let someone else take over from here ... ;)

Cheers,

James

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: LBA / CHS confusion !
PostPosted: Sun Jun 22, 2008 11:54 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
deph wrote:
a-1. Is LBA just a method of expressing blocks in a linear mode?

As said above, yes.

deph wrote:
a-2. (you still have to convert lba address to chs in order to read from a device)

It depends. Maybe. Not necessarily. (Insert your weaselword of choice.) See answer to b.

deph wrote:
b. Whose extension is INT 0x13 AH=41 checking ? (BIOS extension AH=42 for reading blocks using LBA addressing mode ?!)

Originally, there was no LBA ... disks only had CHS mode. You used CHS mode by calling standardized BIOS INT13h functions with CHS values. This worked for 10 years, until disks outgrew CHS addressing. So disk manufacturers invented LBA28. The different BIOS manufacturers all created different ways of handling LBA. It took a few years for the BIOS industry to settle on a standard for LBA addressing, but eventually they did. They created a new standardized set of INT13h functions called "The INT13h Extensions". After not too long, all the BIOSes on all the PCs supported the Extensions. This was in the mid-1990's. The AH=41 BIOS call is simply checking itself to verify that this extended set of BIOS function calls is supported by the BIOS. And really, if the AH=41 call even exists, then all the Extensions exist -- but you can't know until you make the call. :wink:

So, the answer really is: if the BIOS of your target PC is older than the mid-1990's, then LBA mode will not be supported by the BIOS, and the INT13h Extensions will not be supported by the BIOS, and the AH=41 and AH=42 calls will return errors, and you will need to calculate CHS conversions for any LBA of any drive you want to access through the BIOS.

If all your target machines are newer than mid-1990's, then the INT13h Extensions are always supported, and you can access LBAs directly with no conversions ever.

So: do you really want to kill yourself trying to support 80486 machines that are 15 or more years old?


Top
 Profile  
 
 Post subject: Re: LBA / CHS confusion !
PostPosted: Mon Jun 23, 2008 12:50 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
It should be mentioned that it is possible that, if the drive does not support LBA, that the BIOS will automatically convert the LBA address into a CHS address that the drive can use. You can also do this in your own drivers (it's the main reason for my ATA drivers I always write 3 read/write functions, one for CHS, one for LBA28, and one for LBA48).

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Thanks !
PostPosted: Mon Jun 23, 2008 3:58 am 
Offline

Joined: Sun Jun 22, 2008 6:04 am
Posts: 13
Thank you all for your replies;
One more (noob) question on this topic:
- How do I read form HDD in protected mode ? ... Is this done by using in/out from mapped software ports (and if I have ports, when hard disk interrupts <irqs> come handy ?)
- Do I have to implement functions for I/O with ATA and S-ATA devices ? Where can I get docs on I/O with ATA/S-ATA devices (some simple "HOW TO" articles, which can explain how to do I/O with such devices without BIOS support <since I'm planning to run in PMode, and Long mode maybe>).


Top
 Profile  
 
 Post subject: Re: LBA / CHS confusion !
PostPosted: Mon Jun 23, 2008 3:59 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
I highly suggest finding the ATA specification, it has all the information you need. Also, try ATA_PIO_Mode on the wiki.

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 224 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group