199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2007 Yahoo!, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Written by: John Baldwin <jhb@FreeBSD.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3. Neither the name of the author nor the names of any co-contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Partly from: src/sys/boot/i386/boot2/boot1.S 1.31
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Memory Locations */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Misc. Constants */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set COPY_BLK_SZ,0x8000 # Copy in 32k blocks; must be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copy BTX and boot2 to the right locations and start it all up.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Setup the segment registers to flat addressing (segment 0) and setup the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stack to end just below the start of our code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BTX is right after us at 'end'. We read the length of BTX out of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * its header to find boot2. We need to copy boot2 to MEM_USR and BTX
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to MEM_BTX. Since those might overlap, we have to copy boot2
199767f8919635c4928607450d9e0abb932109ceToomas Soome * backwards first and then copy BTX. We aren't sure exactly how long
199767f8919635c4928607450d9e0abb932109ceToomas Soome * boot2 is, but it's currently under 128kB so we'll copy 4 blocks of 32kB
199767f8919635c4928607450d9e0abb932109ceToomas Soome * each; this can be adjusted via COPY_BLK and COPY_BLK_SZ above.
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $(COPY_BLKS*COPY_BLK_SZ/16),%ax # small as possible.
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $(COPY_BLKS*COPY_BLK_SZ/16),%ax # the last byte we
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $COPY_BLK_SZ,%si # Adjust %ds:%si to point at
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $COPY_BLK_SZ-1,%di # Adjust %es:%di to point at
199767f8919635c4928607450d9e0abb932109ceToomas Soome sub $COPY_BLK_SZ/16,%ax # which we want boot2 copied
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Enable A20 so we can access memory above 1 meg.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Use the zero-valued %cx as a timeout for embedded hardware which do not
199767f8919635c4928607450d9e0abb932109ceToomas Soome * have a keyboard controller.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Save drive number from BIOS so boot2 can see it and start BTX.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * make sure the end is aligned for concatenated next module