BootLoader 4

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
wererabit
Posts:30
Joined:Wed Sep 03, 2008 2:50 am
BootLoader 4

Post by wererabit » Mon Mar 08, 2010 8:20 pm

Hi,

I have a question. In the tutorial 6, the section where we only want to print out a message for our 2nd stage boot loader. I see this

Code: Select all

;*************************************************;
;	Second Stage Loader Entry Point
;************************************************;

main:
			cli		; clear interrupts
			push	cs	; Insure DS=CS
			pop	ds

			mov	si, Msg
			call	Print

			cli		; clear interrupts to prevent triple faults
			hlt		; hault the system
My question is why do we have to ensure cs = ds? Do we always have to do this for the second stage bootloader?

Thanks

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: BootLoader 4

Post by Mike » Mon Mar 08, 2010 10:40 pm

Hello,

You dont need to insure ds==cs, the software does that to insure they share the same segment so memory references are the same. ie, ds:Msg points to the right linear address.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

wererabit
Posts:30
Joined:Wed Sep 03, 2008 2:50 am

Re: BootLoader 4

Post by wererabit » Tue Mar 09, 2010 5:23 am

Thanks, Mike. My question is what happens if we don't do that?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: BootLoader 4

Post by Andyhhp » Tue Mar 09, 2010 7:02 pm

They dont have to be the same, but almost all code assumes that they are.

When you jump to the second stage, the cs segment will be updated ( so relative jumps will work as intended ) but ds wont be updated. If ds isnt updated, then all references to data in stage2 will actually be references to data from the bootloader, which is not a good situation.

When you assemble stage2.asm, the compiler will assume (if you dont provide an ORG directive) that the program is starting at 0x0:0x0 in memory, so all references are relative to offset 0. Then, if you load stage2 elsewhere (e.g. to 0x500 linear address), you can change the segment to 0x50 and the offset to 0, and all the relative references will work.

I hope that explains a bit

~Andrew
Image

wererabit
Posts:30
Joined:Wed Sep 03, 2008 2:50 am

Re: BootLoader 4

Post by wererabit » Thu Mar 11, 2010 8:49 pm

Thanks for the reply.

Post Reply