From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 17 14:11:34 2007 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 5B89D16A419 for ; Mon, 17 Dec 2007 14:11:34 +0000 (UTC) (envelope-from m.girish.rao@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.180]) by mx1.freebsd.org (Postfix) with ESMTP id 4525113C46A for ; Mon, 17 Dec 2007 14:11:34 +0000 (UTC) (envelope-from m.girish.rao@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so3535427waf.3 for ; Mon, 17 Dec 2007 06:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; bh=jyDCaIKiFXygldX4y/aWY45C1Sq4f4CwjEi1V/+JYI8=; b=dPMmGiQQodc8sMVvkC5PL/qKYx8s3+SWnXuz/UtFc6t6obmvQWTmK2OOMlJMxCv8y1aFOEQs8QqQlgq9bNWuypzID/jWjJQ6Pjf2Gzc2RKHvPmdNPNgBjK+TnjTyFczPbFcpR2vb4BlvNEv16Lm95LWJUfahSxBAJ/JkMsYwdbE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=MBjfiXRgTMswc9dMVdy5cTj1l3HfyYPtVCh2R3kxqrgwATPL7z+DfjpzPfmAO3wMY8mH88XAA1ZkAVTiE+reONxllxvG6R9G95cQ8yckOmy9AUgfvsPRagtlEGUvVptAiItUniG2x5HSGX51qDrjVZh9V8s8AuX40npbRCpUWNg= Received: by 10.114.152.17 with SMTP id z17mr2171378wad.128.1197899181155; Mon, 17 Dec 2007 05:46:21 -0800 (PST) Received: from ?192.168.1.2? ( [122.162.157.214]) by mx.google.com with ESMTPS id v25sm18196288wah.2007.12.17.05.46.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 17 Dec 2007 05:46:20 -0800 (PST) Message-ID: <47667D9A.8070300@gmail.com> Date: Mon, 17 Dec 2007 19:16:02 +0530 From: "M.Girish Rao" User-Agent: Thunderbird 2.0.0.6 (X11/20071101) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Mon, 17 Dec 2007 14:19:34 +0000 Subject: boot0 code mystery 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, 17 Dec 2007 14:11:34 -0000 Hi, I am reading the code for boot0 (/usr/src/sys/boot/i386/boot0/boot0.S). This is the part i am trying to understand: -------------------------------------------------------------------------------------------------------- /* * Initialise segments and registers to known values. * segments start at 0. * The stack is immediately below the address we were loaded to. */ 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 /* * Copy this code to the address it was linked for */ movw %sp,%si # Source movw $start,%di # Destination movw $0x100,%cx # Word count rep # Relocate movsw # code /* * Set address for variable space beyond code, and clear it. * Notice that this is also used to point to the values embedded in the block, * by using negative offsets. */ movw %di,%bp # Address variables movb $0x8,%cl # Words to clear rep # Zero stosw # them /* * Relocate to the new copy of the code. */ incb -0xe(%di) # Sector number jmp main-LOAD+ORIGIN # To relocated code ---------------------------------------------------------------------------------------------------------------- This is all the information I could gather: From this first disk's first sector, 512 bytes are read into the memory location of 0x7C00. After that, the BIOS will check for the number 0xAA55 at the memory location of 0x7DFE (the last two bytes of the boot block code). After the boot0 program is loaded and control is transferred to it, it will set up its registers and stack information. Then, boot0 relocates itself into a lower memory location and jumps to the new address offset to its main routine. Whats the memory location of start? what's this for incb -0xe(%di) ? where are we jumping to in jmp main-LOAD+ORIGIN? whats ORIGIN? I would really appreciate if some could kindly help me out with this.