Re: Help on understanding mbr.S

2011-09-25 Thread Alan Cheng
On Fri, Sep 23, 2011 at 11:24 AM, Daniel Dickman didick...@gmail.comwrote:

 What are you trying to do though? Working with x86 in real mode and dealing
 with ancient PC conventions is probably not the easiest place to start.


I'm trying to learn how kernel (or OS) works.
I went through a couple of books on OS design and implementation and think I
know some general rules on OS, now I'm reading the source code to learn the
details.

Thanks Daniel for the explanation.
I went over the links you posted, and that gives me a better understanding
of what the 1:  is and local labels in general.

A follow up question, though:
So ljmp $BOOTSEC, $1f is used to set seg:offset to 07C0:. While
$BOOTSEC is defined to be 07C0, why $1f is guaranteed to be , isn't
it something volatile?



Re: Help on understanding mbr.S

2011-09-25 Thread Alan Cheng
Thanks Bryan. Your explanation makes things a lot clearer to me.
As mentioned in my reply to Daniel, I not cannot figure out why $1f will
be .


On Fri, Sep 23, 2011 at 12:05 PM, Brynet bry...@gmail.com wrote:

 One of the first things an MBR does is do a long jump from where the BIOS
 loaded it.

 The thing is, often you can't trust the BIOS to do the right thing, the x86
 in
 16-bit real mode uses segmented memory, so you may be at :07C0 or
 7C00:
 depending on the implementation. If you read the comment higher up you'll
 see
 they perform a long jump to normalize the Code Segment to 07C0, offset 0.

 :07C0 and 7C00: technically resolve to the same address, but
 enforcing
 segment:offset (cs:ip) just makes things consistent.

 The references to :1 is a local label, used for relative addressing, 'f'
 meaning forward and 'b' meaning backward.

 http://sourceware.org/binutils/docs/as/Symbol-Names.html

 Most MBR's are OS-independent, they relocate, parse partition table, load
 the
 PBR/VBR to 7C00 and perform a ljmp to it.

 Hope that helps,
 -Bryan.



Help on understanding mbr.S

2011-09-22 Thread Alan Cheng
Hello,

Not sure if this is the right place to request help for this, but I'm
reading mbr.S file (i386 arch), but could not figure out what the function
is for the line that reads 1:.
The code below that line is setting up statck, but why do we need this line?
and there are more than one line that reads 1: in the mbr.S file, which
confues me even more.

Could someone help expain it a little a bit, or point me to some links that
helps? thanks.


... ...

 .text
.code16

.globl start
start:
/* Adjust %cs to be right */
ljmp $BOOTSEG, $1f

1:   /* what is this, a label? */


/* Set up stack */
movw %cs, %ax

/*
* We don't need to disable and re-enable interrupts around the
* the load of ss and sp.

... ...


Complete mbr.S file I'm refering to:
http://www.openbsd.org/cgi-bin/cvsweb/src/sys/arch/i386/stand/mbr/mbr.S?rev=1.21;content-type=text%2Fx-cvsweb-markup


I'm still working on my ATT assembly learning, googled around but could not
find anything related.

Thanks,
Alan



Re: Help on understanding mbr.S

2011-09-22 Thread Daniel Dickman
The 1: is the target for the preceding ljmp instruction. This is a local
label. Reference here:
http://sourceware.org/binutils/docs/as/Symbol-Names.html#Symbol-Names

The reason the ljmp is needed in the first place is because In real mode there
are multiple ways to refer to the same memory address. The mbr does a ljmp
early on to set the real mode segment:offset to known values. See:
http://wiki.osdev.org/MBR_%28x86%29#Initial_Environment

What are you trying to do though? Working with x86 in real mode and dealing
with ancient PC conventions is probably not the easiest place to start.



Re: Help on understanding mbr.S

2011-09-22 Thread Brynet
One of the first things an MBR does is do a long jump from where the BIOS 
loaded it.

The thing is, often you can't trust the BIOS to do the right thing, the x86 in 
16-bit real mode uses segmented memory, so you may be at :07C0 or 7C00: 
depending on the implementation. If you read the comment higher up you'll see 
they perform a long jump to normalize the Code Segment to 07C0, offset 0.

:07C0 and 7C00: technically resolve to the same address, but enforcing 
segment:offset (cs:ip) just makes things consistent.

The references to :1 is a local label, used for relative addressing, 'f' 
meaning forward and 'b' meaning backward.
 
http://sourceware.org/binutils/docs/as/Symbol-Names.html

Most MBR's are OS-independent, they relocate, parse partition table, load the 
PBR/VBR to 7C00 and perform a ljmp to it.

Hope that helps,
-Bryan.