Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/i386/stand/boot Add files for 2nd stage boot loader



details:   https://anonhg.NetBSD.org/src/rev/049e119bd1c7
branches:  trunk
changeset: 545837:049e119bd1c7
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Apr 16 22:36:14 2003 +0000

description:
Add files for 2nd stage boot loader

diffstat:

 sys/arch/i386/stand/boot/Makefile          |    5 +
 sys/arch/i386/stand/boot/Makefile.boot     |  157 ++++++++++++
 sys/arch/i386/stand/boot/biosboot.S        |  148 +++++++++++
 sys/arch/i386/stand/boot/biosboot/Makefile |    5 +
 sys/arch/i386/stand/boot/boot2.c           |  372 +++++++++++++++++++++++++++++
 sys/arch/i386/stand/boot/conf.c            |   66 +++++
 sys/arch/i386/stand/boot/devopen.c         |  115 ++++++++
 sys/arch/i386/stand/boot/devopen.h         |    3 +
 sys/arch/i386/stand/boot/version           |   33 ++
 9 files changed, 904 insertions(+), 0 deletions(-)

diffs (truncated from 940 to 300 lines):

diff -r e8274cd3786c -r 049e119bd1c7 sys/arch/i386/stand/boot/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/boot/Makefile Wed Apr 16 22:36:14 2003 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1 2003/04/16 22:36:14 dsl Exp $
+
+SUBDIR= biosboot
+
+.include <bsd.subdir.mk>
diff -r e8274cd3786c -r 049e119bd1c7 sys/arch/i386/stand/boot/Makefile.boot
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/boot/Makefile.boot    Wed Apr 16 22:36:14 2003 +0000
@@ -0,0 +1,157 @@
+# $NetBSD: Makefile.boot,v 1.1 2003/04/16 22:36:14 dsl Exp $
+
+S=     ${.CURDIR}/../../../../../
+
+NOMAN=
+STRIPFLAG=
+PROG= boot
+NEWVERSWHAT= BIOS
+VERSIONFILE?= ${.CURDIR}/../version
+
+SOURCES= biosboot.S boot2.c conf.c devopen.c exec.c
+SRCS= ${SOURCES}
+.if !make(depend)
+SRCS+= vers.c
+.endif
+
+.include <bsd.own.mk>
+
+LIBCRT0=       # nothing
+LIBCRTBEGIN=   # nothing
+LIBCRTEND=     # nothing
+LIBC=          # nothing
+
+BINDIR=/usr/mdec
+BINMODE=444
+
+.PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib
+
+LDFLAGS+= -N -e boot_start
+# CPPFLAGS+= -D__daddr_t=int32_t
+CPPFLAGS+= -I ${.CURDIR}/..  -I ${.CURDIR}/../../lib -I ${S}/lib/libsa
+CPPFLAGS+= -I ${.OBJDIR}
+CPPFLAGS+= -DDEBUG_MEMSIZE
+CPPFLAGS+= -DX86_BOOT_MAGIC_1="('x' << 24 | 0x86b << 12 | 'm' << 4 | 1)"
+CPPFLAGS+= -DX86_BOOT_MAGIC_2="('x' << 24 | 0x86b << 12 | 'm' << 4 | 2)"
+
+# Make sure we override any optimization options specified by the user
+COPTS=  -Os
+
+.if ${MACHINE} == "x86_64"
+LDFLAGS+=  -m elf_i386
+AFLAGS+=   -m32
+COPTS+=    -m32
+LIBKERN_ARCH=i386
+KERNMISCMAKEFLAGS="LIBKERN_ARCH=i386"
+.else
+COPTS+=    -mcpu=i386
+.endif
+
+COPTS+=    -ffreestanding
+CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
+CPPFLAGS+= -nostdinc -D_STANDALONE
+CPPFLAGS+= -I$S
+
+CPPFLAGS+= -DSUPPORT_PS2
+CPPFLAGS+= -DDIRECT_SERIAL
+CPPFLAGS+= -DSUPPORT_SERIAL=boot_params.bp_consdev
+
+CPPFLAGS+= -DCONSPEED=boot_params.bp_conspeed
+
+CPPFLAGS+= -DSUPPORT_USTARFS
+#CPPFLAGS+= -DSUPPORT_DOSFS
+CPPFLAGS+= -DPASS_BIOSGEOM
+CPPFLAGS+= -DPASS_MEMMAP
+#CPPFLAGS+= -DBOOTPASSWD
+
+# The biosboot code is linked to 'virtual' address of zero and is
+# loaded at physical address 0x10000.
+# XXX The heap values should be determined from _end.
+SAMISCCPPFLAGS+= -DHEAP_START=0x20000 -DHEAP_LIMIT=0x50000
+SAMISCMAKEFLAGS+= SA_USE_CREAD=yes     # Read compressed kernels
+SAMISCMAKEFLAGS+= SA_INCLUDE_NET=no    # Netboot via TFTP, NFS
+
+
+# CPPFLAGS+= -DBOOTXX_RAID1_SUPPORT
+
+I386_STAND_DIR?= $S/arch/i386/stand
+
+.if !make(obj) && !make(clean) && !make(cleandir)
+.BEGIN: machine
+.NOPATH: machine
+.endif
+
+realdepend realall: machine
+CLEANFILES+= machine
+
+machine::
+       -rm -f $@
+       ln -s $S/arch/i386/include $@
+
+${OBJS}: machine
+
+### find out what to use for libi386
+I386DIR= ${I386_STAND_DIR}/lib
+I386DST= ${.OBJDIR}/../lib/i386
+.include "${I386DIR}/Makefile.inc"
+LIBI386= ${I386LIB}
+
+### find out what to use for libsa
+SA_AS= library
+SADST= ${.OBJDIR}/../lib/libsa
+SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
+.include "${S}/lib/libsa/Makefile.inc"
+LIBSA= ${SALIB}
+
+### find out what to use for libkern
+KERN_AS= library
+KERNDST= ${.OBJDIR}/../lib/libkern
+.include "${S}/lib/libkern/Makefile.inc"
+LIBKERN= ${KERNLIB}
+
+### find out what to use for libz
+Z_AS= library
+ZDST= ${.OBJDIR}/../lib/libz
+.include "${S}/lib/libz/Makefile.inc"
+LIBZ= ${ZLIB}
+
+
+cleandir distclean: cleanlibdir
+
+cleanlibdir:
+       rm -rf lib
+
+LIBLIST= ${LIBI386} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBI386} ${LIBSA}
+# LIBLIST= ${LIBSA} ${LIBKERN} ${LIBI386} ${LIBSA} ${LIBZ} ${LIBKERN}
+
+CLEANFILES+= ${PROG}.tmp ${PROG}.map vers.c
+
+vers.c: ${VERSIONFILE} ${SOURCES} ${LIBLIST} ${.CURDIR}/../Makefile.boot
+       sh ${S}conf/newvers_stand.sh ${VERSIONFILE} ${MACHINE} ${NEWVERSWHAT}
+
+# Anything that calls 'real_to_prot' must have a %pc < 0x10000.
+# We link the program, find the callers (all in libi386), then
+# explicitely pull in the required objects before any other library code.
+${PROG}: ${OBJS} ${LIBLIST} ${.CURDIR}/../Makefile.boot
+       bb="$$( ${LD} -o ${PROG}.tmp ${LDFLAGS} -Ttext 0 -cref \
+           ${OBJS} ${LIBLIST} | ( \
+               while read symbol file; do \
+                       [ -z "$$file" ] && continue; \
+                       [ "$$symbol" = real_to_prot ] && break; \
+               done; \
+               while \
+                       oifs="$$IFS"; \
+                       IFS='()'; \
+                       set -- $$file; \
+                       IFS="$$oifs"; \
+                       [ -n "$$2" ] && echo "${I386DST}/$$2"; \
+                       read file rest && [ -z "$$rest" ]; \
+               do :; \
+               done; \
+       ) )"; \
+       ${LD} -o ${PROG}.tmp ${LDFLAGS} -Ttext 0 \
+               -Map ${PROG}.map -cref ${OBJS} $$bb ${LIBLIST}
+       ${OBJCOPY} -O binary ${PROG}.tmp ${PROG}
+       rm -f ${PROG}.tmp
+
+.include <bsd.prog.mk>
diff -r e8274cd3786c -r 049e119bd1c7 sys/arch/i386/stand/boot/biosboot.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/boot/biosboot.S       Wed Apr 16 22:36:14 2003 +0000
@@ -0,0 +1,148 @@
+/*     $NetBSD: biosboot.S,v 1.1 2003/04/16 22:36:14 dsl Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by David Laight.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+#include <sys/disklabel_mbr.h>
+
+/*
+ * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
+ *
+ * On entry:
+ *     %dl                     BIOS drive number
+ *     %ebx                    Sector number of netbsd partition
+ *     %ds:%esi                Boot parameter block (patched by installboot)
+ *     %cs                     0x1000
+ *     %ds, %es, %ss           All zero
+ *     %sp                     near 0xfffc
+ */
+
+       .text
+       .code16
+ENTRY(boot_start)
+       jmp     boot_start_1
+       .align  4
+ENTRY(boot_magic)
+       .long   X86_BOOT_MAGIC_2        /* checked for by bootxx code */
+ENTRY(boot_params)
+       .long   boot_start_1 - boot_params
+#include "../bootxx/boot_params.S"
+       . = boot_start + 0x80           /* space for patchable variables */
+boot_start_1:
+
+#if 0
+       /* Allow for boot_start not being %cs:0 */
+       call    2f
+2:     pop     %cx
+       sub     $2b, %cx                /* %ax is offset */
+       test    $0xf, %cx               /* check code seg aligned */
+       jz      3f
+       lret                            /* not playing if not */
+3:     mov     %cs, %ax
+       shr     $4, %cx
+       add     %cx, %ax                /* segment staring at boot_start */
+       push    %ax
+       push    $4f
+       lret
+4:
+#endif
+
+       mov     %cs, %ax
+       mov     %ax, %es
+
+       /* Grab bootparams patched into bootxx by installboot */
+       cmpl    $X86_BOOT_MAGIC_1,-4(%si)       /* sanity check ptr */
+       jne     2f
+       mov     $boot_params, %di
+       movl    (%si),%ecx
+       cmp     $boot_start_1 - boot_params, %cx
+       jbe     1f
+       mov     $boot_start_1 - boot_params, %cx
+1:     cld
+       rep
+       movsb
+2:
+
+       mov     %ax, %ds
+       movl    $_end, %eax             /* top of bss */
+       shr     $4, %eax                /* as a segment */
+       add     $0x1001, %ax            /* and + 64k */
+       mov     %ax, %ss                /* for stack */
+       mov     $0xfffc, %sp            /* %sp at top of it */
+
+       call    gdt_fixup
+
+       calll   real_to_prot
+       .code32
+
+       movl    $_end, %ecx             /* zero bss */
+       movl    $__bss_start, %edi
+       subl    %edi, %ecx
+       shr     $2, %ecx                /* _end and __bss_start are aligned */
+       xor     %eax, %eax
+       rep
+       stosl
+
+       and     $0xff, %edx
+       push    %ebx                    /* first sector of bios partition */
+       push    %edx                    /* bios disk */
+       call    _C_LABEL(boot2)         /* C bootstrap code */
+       add     $8, %esp
+       call    prot_to_real
+       .code16



Home | Main Index | Thread Index | Old Index