Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Mar 2010 00:06:49 -0400
From:      =?ISO-8859-1?Q?Sergio_Andr=E9s_G=F3mez_del_Real?= <sergio.g.delreal@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Problems understanding this piece of code...
Message-ID:  <ee48a9121003282106t291e047dpef18f31824541cd3@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi.
I can't seem to understand this piece of i386 boot code:
What I understand is that BIOS loads MBR at 0x7c00, then jumps to the
code there, code that relocates itself to and jumps to 0x600, but what
does movw $main-EXEC+LOAD,%si mean? if it's the source address to copy
from, why is it $main (0x7c00) - EXEC (0x600) + LOAD (0x7c00) above
main? then, movw $main,%di is the address to copy to... wasn't 0x600
the address to copy to? then jump to jmp main-LOAD+EXEC (0x600)?

I guess I am really missing something here, but I can't get to
understand what's happening.

start:		cld				# String ops inc
		xorw %ax,%ax			# Zero
		movw %ax,%es			# Address
		movw %ax,%ds			#  data
		movw %ax,%ss			# Set up
		movw $LOAD,%sp			#  stack
#
# Relocate ourself to a lower address so that we are out of the way when
# we load in the bootstrap from the partition to boot.
#
		movw $main-EXEC+LOAD,%si	# Source
		movw $main,%di			# Destination
		movw $0x200-(main-start),%cx	# Byte count
		rep				# Relocate
		movsb				#  code
#
# Jump to the relocated code.
#
		jmp main-LOAD+EXEC		# To relocated code



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ee48a9121003282106t291e047dpef18f31824541cd3>