Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-25 Thread Eric Auer

Hi Christian,

>> As far as I remember, the MS DOS 7.x / Windows 9x boot
>> sectors did use it and it is in fact intentional there.
> 
> Almost entirely certain that you are wrong.
> 
> Superficially checked both boot sectors in the MS-DOS 7.10 SYS.COM now  
> (one's for FAT12 and FAT16, the other for FAT32) and they both load ds:si  
> with a different pointer pretty early on without saving the previous  
> value. Concluding that I am right and neither uses the partition table  
> left in memory by the MBR code.

Checking again, the web tells me:

http://thestarman.pcministry.com/asm/mbr/STDMBR.htm#CODE

http://thestarman.pcministry.com/asm/mbr/95BMEMBR.htm#CODE

The MBR of FDISK of MS DOS 3.30 to Win95 and of Win95b to WinME all
make sure to set SI before jumping to the boot sector, which leads
to the question why they do it if it would be unintentional ;-) It
does at least mean that many MBRs out there do set this pointer.

http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#CODE

The FAT32 Win9x boot sector seems to ignore SI, as you say,
but instead it scans the MBR for a primary partition that
starts at the same LBA position as specified in the FAT32
boot sector in the partition offset / hidden sectors field
to then use the partition type info in the partition table
to check whether CHS or LBA should be used (call 7d30 etc)
by checking the partition type. If MS likes it that way...

If you get bored, you can read more MBRs and boot sectors at:

www.rayknights.org/pc_boot/pc_boot.htm

Eric


--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-25 Thread C. Masloch
> As far as I remember, the MS DOS 7.x / Windows 9x boot
> sectors did use it and it is in fact intentional there.

Almost entirely certain that you are wrong.

Superficially checked both boot sectors in the MS-DOS 7.10 SYS.COM now  
(one's for FAT12 and FAT16, the other for FAT32) and they both load ds:si  
with a different pointer pretty early on without saving the previous  
value. Concluding that I am right and neither uses the partition table  
left in memory by the MBR code.

Regards,
C.

--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-25 Thread Decheng Fan
Hi,

On Sat, Sep 24, 2011 at 2:16 AM, Eric Auer  wrote:

>
> As far as I remember, the MS DOS 7.x / Windows 9x boot
> sectors did use it and it is in fact intentional there.
>
> > In a boot sector, you could attempt to use that information; if so,
> > verifying that the byte at address ds:si contains the value 80h (or at
> the
>
> Which is, again as far as I remember, what Win9x did. If you
> really want to know, you can certainly find an annotated list
> of the machine code of that very widespread boot sector ;-)
>
> > very least has the highest bit set; that is, a value >= 80h) helps with
> > finding out whether the MBR supports this "interface". MBRs are expected
> > to relocate to 60:0 or linear 600h, so another verification would be to
> > check that ds:si then points to one of the entries in the partition table
> > copy there.
>
> Not all MBRs do that, but it is yet another popular convention.
>
>
Yes after reading your e-mail, and after re-checking Minix masterboot.s
code, it also keeps SI pointing to the partition table entry. Meanwhile,
another article talking about MS-DOS MBR also mentions this:

http://www.ata-atapi.com/hiwmbr.html

So I guess this is also a convention, or at least a de-facto standard?

Best regards,

Robbie
--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-23 Thread Eric Auer

Hi,

>> 22:23 <@aljen> you mean ds:si pointing to selected partition entry in
>> mbr when jumping into vbr's code ?
>> 22:23 < mmu_man> yup
> 
> Could have told you about that. At least some MBRs leave ds:si to point to  
> the entry, which seems a random occurrence rather than an intentional  
> interface. I think almost no one uses it.

As far as I remember, the MS DOS 7.x / Windows 9x boot
sectors did use it and it is in fact intentional there.

> In a boot sector, you could attempt to use that information; if so,  
> verifying that the byte at address ds:si contains the value 80h (or at the

Which is, again as far as I remember, what Win9x did. If you
really want to know, you can certainly find an annotated list
of the machine code of that very widespread boot sector ;-)

> very least has the highest bit set; that is, a value >= 80h) helps with  
> finding out whether the MBR supports this "interface". MBRs are expected  
> to relocate to 60:0 or linear 600h, so another verification would be to  
> check that ds:si then points to one of the entries in the partition table  
> copy there.

Not all MBRs do that, but it is yet another popular convention.

Eric


--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-23 Thread C. Masloch

> 22:23 <@aljen> you mean ds:si pointing to selected partition entry in
> mbr when jumping into vbr's code ?
> 22:23 < mmu_man> yup

Could have told you about that. At least some MBRs leave ds:si to point to  
the entry, which seems a random occurrence rather than an intentional  
interface. I think almost no one uses it.

In a boot sector, you could attempt to use that information; if so,  
verifying that the byte at address ds:si contains the value 80h (or at the  
very least has the highest bit set; that is, a value >= 80h) helps with  
finding out whether the MBR supports this "interface". MBRs are expected  
to relocate to 60:0 or linear 600h, so another verification would be to  
check that ds:si then points to one of the entries in the partition table  
copy there.

Regards,

--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-21 Thread Decheng Fan
Hi,
On Thu, Sep 22, 2011 at 4:43 AM, François Revol  wrote:

> Le 21/09/2011 21:25, François Revol a écrit :
> >
> > IIRC there is a convention that the MBR partition info (somewhere in the
> > sector buffer it just read) that the MBR handed control to is passed
> > over to the partition boot sector in a specific register.
>
> Replying to myself, we just had this discussion on IRC about it:
>
> 22:17 < phcoder> mmu_man: nearly no bootloader uses this info
> 22:18 < mmu_man> yeah, I know, I need to use it in Haiku someday :)
> 22:19 < mmu_man> would get rid of makebootable
> 22:19 < phcoder> mmu_man: beware that (a) in case of logical partition
> the info is difficult to use
> 22:19 < mmu_man> oh right
> 22:19 < mmu_man> :(
> 22:20 < phcoder> (b) some boot managers omit this information
> (especially some proprietary recovery stuff)
> 22:21 < mmu_man> and likely Haiku's bootman MBR
> 22:21 < mmu_man> how does DOS do it ?
> 22:21 < mmu_man> or does SYS.COM add the partition offset ?
> 22:21 < phcoder> mmu_man: there is a field in FAT BPB for this
> 22:22 < phcoder> it's misnamed "hidden sectors"
> 22:22 < mmu_man> aw
> 22:23 <@aljen> you mean ds:si pointing to selected partition entry in
> mbr when jumping into vbr's code ?
> 22:23 < mmu_man> yup
>
> Just so you know, seems not usable.
>
> François.
>
>
Thanks. I also agree. Though the MBR partition table contains the offset, in
the MBR code I read, it is not passed to the boot sector code of DOS. Thus
the boot sector of DOS needs to figure out where the partition locates on
the drive on its own. Usually the drive code originally set in DL by BIOS is
passed on by the MBR code. Please correct me if I'm wrong.

Best regards,

Robbie
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-21 Thread François Revol
Le 21/09/2011 21:25, François Revol a écrit :
> Le 21/09/2011 06:48, Decheng Fan a écrit :
>> Hi,
>>
>> Thank you for so detailed explanation! This helps me a lot! I'll take time
>> to read it more carefully and search through the Web for clearer
>> understanding. Thanks again.
>>
> 
> IIRC there is a convention that the MBR partition info (somewhere in the
> sector buffer it just read) that the MBR handed control to is passed
> over to the partition boot sector in a specific register.

Replying to myself, we just had this discussion on IRC about it:

22:17 < phcoder> mmu_man: nearly no bootloader uses this info
22:18 < mmu_man> yeah, I know, I need to use it in Haiku someday :)
22:19 < mmu_man> would get rid of makebootable
22:19 < phcoder> mmu_man: beware that (a) in case of logical partition
the info is difficult to use
22:19 < mmu_man> oh right
22:19 < mmu_man> :(
22:20 < phcoder> (b) some boot managers omit this information
(especially some proprietary recovery stuff)
22:21 < mmu_man> and likely Haiku's bootman MBR
22:21 < mmu_man> how does DOS do it ?
22:21 < mmu_man> or does SYS.COM add the partition offset ?
22:21 < phcoder> mmu_man: there is a field in FAT BPB for this
22:22 < phcoder> it's misnamed "hidden sectors"
22:22 < mmu_man> aw
22:23 <@aljen> you mean ds:si pointing to selected partition entry in
mbr when jumping into vbr's code ?
22:23 < mmu_man> yup

Just so you know, seems not usable.

François.

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-21 Thread François Revol
Le 21/09/2011 06:48, Decheng Fan a écrit :
> Hi,
> 
> Thank you for so detailed explanation! This helps me a lot! I'll take time
> to read it more carefully and search through the Web for clearer
> understanding. Thanks again.
> 

IIRC there is a convention that the MBR partition info (somewhere in the
sector buffer it just read) that the MBR handed control to is passed
over to the partition boot sector in a specific register.
I'm not exactly sure how much this is valid.
Some GRUB developer told me this, I'd trust it but didn't check myself.
For Haiku for example, we don't use it and have to manually update the
partition offset in the partition bootsector (makebootable CLI tool),
which is a hassle.
And I don't think our own MBR chooser implements it either (but it
chainloads windows correctly though).
So I should probably look it up someday.
Try to ask phcoder on irc.freenode.net, he's usually on #grub of course.

François.

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-20 Thread Decheng Fan
Hi,

Thank you for so detailed explanation! This helps me a lot! I'll take time
to read it more carefully and search through the Web for clearer
understanding. Thanks again.

Best regards,

Robbie
On Tue, Sep 20, 2011 at 10:30 PM, C. Masloch  wrote:

> Hi,
>
> This doesn't seem to have received any answers yet.
>
> > I see the MBR code essentially loads the boot sector of the active
> > partition and puts it at address :7c00. Then the boot code is
> > executed by jumping to that address.
>
> This is correct.
>
> > 1. INT 0x13 with AH=0x42 does extended read operation. But what if the
> > BIOS is old? Will it do nothing and set an error flag in CF?
>
> Yes, BIOSes not supporting (LBA) extended functions should flag an error.
> However, the boot sector or MBR can/should test whether the BIOS supports
> (LBA) extended functions via the detection function first. That's 13.40 or
> something, look it up in your reference. As opposed to only checking CF,
> you should check for both NC and the signature value (in bx I believe) to
> verify that the detection function is supported.
>
> MBRs and boot sectors depending on LBA support are easier to write;
> specifically as you do not have to write handling for two interfaces and
> as calculating CHS addresses from linear sector numbers is then
> unnecessary. (LBA addresses are the same as linear sector numbers.)
> (Getting rid of the LBA support and always using the CHS interface is a
> bad idea though, because CHS is limited to the first 8 GiB or so of the
> disk.)
>
> > 2. Compared to the MBR, does the boot sector also contain partition
> > location
> > information? I searched the Web and looked at some pages about it, but
> > didn't find any. Then, how does it call INT 13 and boot the kernel? Maybe
> > I'm not understanding this correctly, so please correct me if I'm wrong.
>
> This is how it's usually done for FAT partitions, yes. In the FAT "BIOS
> Parameter Block" (BPB, it contains informations about the file system)
> there is one field often called "hidden sectors". This is simply the
> number of sectors on the disk that are in front of the boot sector; in
> other words, the (LBA) address of this partition.
>
> This information is virtually useless: if you know where you read the
> sector from, you shouldn't need that information in the sector itself.
> However, as you must have noticed, there is no interface for how to pass
> the sector address from the MBR code to the boot sector code, so this
> field is necessary as it isn't communicated to the boot sector code.
>
> Knowledge of the file system can be read and calculated from the BPB,
> including the position of the FATs, the root directory (FAT12/16 special
> area or FAT32 cluster) and the data area. The boot sector code parses as
> much of that as necessary, then scans through the root directory. (Some
> loaders expect the first root directory entry to be the one for their
> kernel.) The loader then reads either the first few sectors of the
> first/only kernel file or that entire file. (In the former case, the first
> few sectors contain a more advanced file system driver.) On FAT32, some
> systems use secondary boot code sectors behind the first one to store more
> code. (This is similar to the loading scheme which stores a more advanced
> driver at the beginning of the kernel file.)
>
> Regards,
>
>
> --
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel
>
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] How does the boot sector know the partition start

2011-09-20 Thread C. Masloch
Hi,

This doesn't seem to have received any answers yet.

> I see the MBR code essentially loads the boot sector of the active
> partition and puts it at address :7c00. Then the boot code is
> executed by jumping to that address.

This is correct.

> 1. INT 0x13 with AH=0x42 does extended read operation. But what if the  
> BIOS is old? Will it do nothing and set an error flag in CF?

Yes, BIOSes not supporting (LBA) extended functions should flag an error.
However, the boot sector or MBR can/should test whether the BIOS supports
(LBA) extended functions via the detection function first. That's 13.40 or
something, look it up in your reference. As opposed to only checking CF,
you should check for both NC and the signature value (in bx I believe) to
verify that the detection function is supported.

MBRs and boot sectors depending on LBA support are easier to write;
specifically as you do not have to write handling for two interfaces and
as calculating CHS addresses from linear sector numbers is then
unnecessary. (LBA addresses are the same as linear sector numbers.)
(Getting rid of the LBA support and always using the CHS interface is a
bad idea though, because CHS is limited to the first 8 GiB or so of the
disk.)

> 2. Compared to the MBR, does the boot sector also contain partition  
> location
> information? I searched the Web and looked at some pages about it, but
> didn't find any. Then, how does it call INT 13 and boot the kernel? Maybe
> I'm not understanding this correctly, so please correct me if I'm wrong.

This is how it's usually done for FAT partitions, yes. In the FAT "BIOS
Parameter Block" (BPB, it contains informations about the file system)
there is one field often called "hidden sectors". This is simply the
number of sectors on the disk that are in front of the boot sector; in
other words, the (LBA) address of this partition.

This information is virtually useless: if you know where you read the
sector from, you shouldn't need that information in the sector itself.
However, as you must have noticed, there is no interface for how to pass
the sector address from the MBR code to the boot sector code, so this
field is necessary as it isn't communicated to the boot sector code.

Knowledge of the file system can be read and calculated from the BPB,
including the position of the FATs, the root directory (FAT12/16 special
area or FAT32 cluster) and the data area. The boot sector code parses as
much of that as necessary, then scans through the root directory. (Some
loaders expect the first root directory entry to be the one for their
kernel.) The loader then reads either the first few sectors of the
first/only kernel file or that entire file. (In the former case, the first
few sectors contain a more advanced file system driver.) On FAT32, some
systems use secondary boot code sectors behind the first one to store more
code. (This is similar to the loading scheme which stores a more advanced
driver at the beginning of the kernel file.)

Regards,

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


[Freedos-devel] How does the boot sector know the partition start

2011-09-17 Thread Decheng Fan
Hello everybody,

Recently I read about two examples of MBR boot code. One is Windows 98 MBR
(not yet finished reading), another is Minix MBR (almost finished reading).
The Minix MBR seems more advanced, but let me skip this for now. I see the
MBR code essentially loads the boot sector of the active partition and puts
it at address :7c00. Then the boot code is executed by jumping to that
address.

I have the following questions:

1. INT 0x13 with AH=0x42 does extended read operation. But what if the BIOS
is old? Will it do nothing and set an error flag in CF?

2. Compared to the MBR, does the boot sector also contain partition location
information? I searched the Web and looked at some pages about it, but
didn't find any. Then, how does it call INT 13 and boot the kernel? Maybe
I'm not understanding this correctly, so please correct me if I'm wrong.

Thanks and best regards,

Robbie (Decheng) Fan
--
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel