From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 29 04:36:45 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CAAB21065672 for ; Mon, 29 Mar 2010 04:36:45 +0000 (UTC) (envelope-from sergio.g.delreal@gmail.com) Received: from mail-ew0-f226.google.com (mail-ew0-f226.google.com [209.85.219.226]) by mx1.freebsd.org (Postfix) with ESMTP id 5F0E88FC0A for ; Mon, 29 Mar 2010 04:36:45 +0000 (UTC) Received: by ewy26 with SMTP id 26so746716ewy.3 for ; Sun, 28 Mar 2010 21:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:received:message-id :subject:from:to:content-type; bh=fvOsCCh87lIh1fOtIVp56PNYNrylhZ23ufrtzA1iCtY=; b=J3XUkebBFagjNaDgRskpGeAu69QFMkCOwiL+8FTtZCF5ZbByX1mlYFJQCAOJgIXLkf kKOMoxfruao7gil/qc1iPEYxYWL9tPaJqNqYyWoKP/MliNZLQntM9BSJBNBqKs9nKcQh XyrxxatsOW9Zo2gsH43AoCXOhrqhAm+GOswLc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=hhc+wXs6Ix/iAXG8HCvlfeT+tAaYpMdGtMZ4Tn0rNJp/WRTzEPqFcXjVbaRs0/lYks pkeRyOrtrA7hsJGYgckDUkcujbDpDEuw3kzyclgrVruosVmIpHnUNKQsKZ9E5jb/N29q flR+Ja60iEBq6/wfowCkWmGKhKed4D9ZoRM4U= MIME-Version: 1.0 Received: by 10.213.4.65 with HTTP; Sun, 28 Mar 2010 21:06:49 -0700 (PDT) Date: Mon, 29 Mar 2010 00:06:49 -0400 Received: by 10.213.50.195 with SMTP id a3mr77841ebg.19.1269835609970; Sun, 28 Mar 2010 21:06:49 -0700 (PDT) Message-ID: From: =?ISO-8859-1?Q?Sergio_Andr=E9s_G=F3mez_del_Real?= To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: Problems understanding this piece of code... X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Mar 2010 04:36:45 -0000 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