Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/fdisk Add and build a bootselecting MBR (i386).
details: https://anonhg.NetBSD.org/src/rev/947b9c908b94
branches: trunk
changeset: 471942:947b9c908b94
user: fvdl <fvdl%NetBSD.org@localhost>
date: Thu Apr 15 22:31:23 1999 +0000
description:
Add and build a bootselecting MBR (i386).
diffstat:
sbin/fdisk/Makefile | 4 +-
sbin/fdisk/mbr/Makefile | 5 +-
sbin/fdisk/mbr_bootsel/Makefile | 26 +
sbin/fdisk/mbr_bootsel/mbr_bootsel.S | 516 +++++++++++++++++++++++++++++++++++
4 files changed, 547 insertions(+), 4 deletions(-)
diffs (truncated from 587 to 300 lines):
diff -r 8189282fbdb8 -r 947b9c908b94 sbin/fdisk/Makefile
--- a/sbin/fdisk/Makefile Thu Apr 15 22:31:16 1999 +0000
+++ b/sbin/fdisk/Makefile Thu Apr 15 22:31:23 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 1998/10/15 15:23:23 ws Exp $
+# $NetBSD: Makefile,v 1.11 1999/04/15 22:31:23 fvdl Exp $
.if (${MACHINE} == "i386" || ${MACHINE} == "powerpc")
@@ -9,7 +9,7 @@
.endif
.if ${MACHINE} == "i386"
-SUBDIR= mbr
+SUBDIR= mbr mbr_bootsel
.endif
MAN= fdisk.8
diff -r 8189282fbdb8 -r 947b9c908b94 sbin/fdisk/mbr/Makefile
--- a/sbin/fdisk/mbr/Makefile Thu Apr 15 22:31:16 1999 +0000
+++ b/sbin/fdisk/mbr/Makefile Thu Apr 15 22:31:23 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 1999/03/24 16:02:41 christos Exp $
+# $NetBSD: Makefile,v 1.4 1999/04/15 22:31:23 fvdl Exp $
BINDIR= /usr/mdec
BINMODE=444
@@ -7,7 +7,8 @@
PROG= mbr
SRCS= mbr.S
-MKMAN= no
+
+MAN= mbr.8
.include <bsd.own.mk>
diff -r 8189282fbdb8 -r 947b9c908b94 sbin/fdisk/mbr_bootsel/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/fdisk/mbr_bootsel/Makefile Thu Apr 15 22:31:23 1999 +0000
@@ -0,0 +1,26 @@
+# $NetBSD: Makefile,v 1.1 1999/04/15 22:31:23 fvdl Exp $
+
+BINDIR= /usr/mdec
+BINMODE=444
+
+STRIPFLAG=
+
+PROG= mbr_bootsel
+SRCS= mbr_bootsel.S
+MKMAN= no
+
+.include <bsd.own.mk>
+
+.if ${OBJECT_FMT} == "ELF"
+LDFLAGS+= -e start
+.else
+LDFLAGS+= -e _start -N
+.endif
+
+${PROG}: ${OBJS}
+ ${LD} -o ${PROG}.tmp ${LDFLAGS} -Ttext 0x600 ${OBJS}
+ ${STRIPPROG} ${PROG}.tmp
+ objcopy -O binary ${PROG}.tmp ${PROG}
+ rm -f ${PROG}.tmp
+
+.include <bsd.prog.mk>
diff -r 8189282fbdb8 -r 947b9c908b94 sbin/fdisk/mbr_bootsel/mbr_bootsel.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/fdisk/mbr_bootsel/mbr_bootsel.S Thu Apr 15 22:31:23 1999 +0000
@@ -0,0 +1,516 @@
+/* $NetBSD: mbr_bootsel.S,v 1.1 1999/04/15 22:31:23 fvdl Exp $ */
+
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Frank van der Linden.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (C) 1998 Wolfgang Solfrank.
+ * Copyright (C) 1998 TooLs GmbH.
+ * All rights reserved.
+ *
+ * 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 TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+/*
+ * i386 master boot code
+ */
+
+#include <machine/asm.h>
+
+#define data32 .byte 0x66
+
+/*
+ * Gas can't emit 16 bit code. Define each instruction that we need where
+ * a 32-bit value (either data or addr) may be inserted in the generated
+ * code, or where we would need a prefix but can do without (saving some
+ * space).
+ */
+
+/*
+ * Register values used in the i386 instruction set
+ */
+#define AL 0
+#define BL 3
+#define CL 1
+#define DL 2
+#define AH 4
+#define BH 7
+#define CH 5
+#define DH 6
+
+#define AX 0
+#define BX 3
+#define CX 1
+#define DX 2
+#define SP 4
+#define BP 5
+#define SI 6
+#define DI 7
+
+#define SI_INDEX 4
+#define DI_INDEX 5
+#define BP_INDEX 7
+
+
+/*
+ * .. and the 16 bit instruction defines.
+ */
+#define call16(label) .byte 0xe8 ; .word label - . - 2
+#define jmp16(label) .byte 0xe9 ; .word label - . - 2
+#define jmpfar(segval,addr) .byte 0xea ; .word addr ; .word segval
+
+#define movb_mem_al(mem) .byte 0xa0 ; .word mem
+#define movb_al_mem(mem) .byte 0xa2 ; .word mem
+
+#define movw_mem_ax(mem) .byte 0xa1 ; .word mem
+#define movw_ax_mem(mem) .byte 0xa3 ; .word mem
+
+#define movw_mem_reg(mem,reg) \
+ .byte 0x8b ; .byte (0x06 | ((reg) << 3) ; .word mem
+
+#define movw_imm_reg(imm,reg) \
+ .byte 0xb8 | reg ; .word imm
+
+#define movb_ireg0_reg(ireg,reg) .byte 0x8a ; .byte (reg << 3) | ireg
+#define movb_iregoff_reg(ireg,off,reg) \
+ .byte 0x8a ; .byte 0x40 | (reg << 3) | ireg ; .byte off
+#define movw_iregoff_reg(ireg,off,reg) \
+ .byte 0x8b ; .byte 0x40 | (reg << 3) | ireg ; .byte off
+
+#define movb_reg_mem(reg,mem) \
+ .byte 0x88 ; .byte 0x6 | (reg << 3) ; .word mem
+#define movb_mem_reg(mem,reg) \
+ .byte 0x8a ; .byte 0x6 | (reg << 3) ; .word mem
+
+#define movl_imm_ireg0(imm,ireg) \
+ .byte 0x66 ; .byte 0xc7 ; .byte ireg ; .long imm
+#define movl_imm_iregoff(imm,ireg,off) \
+ .byte 0x66 ; .byte 0xc7 ; .byte 0x40 | ireg ; .byte off ; .long imm
+
+#define cmp_imm_ax(imm) .byte 0x3d ; .word imm
+
+#define cmpb_imm_ireg0(imm,reg) \
+ .byte 0x80 ; .byte 0x38 + reg ; .byte imm
+
+#define cmpb_imm_iregoff(imm,reg,off) \
+ .byte 0x80 ; .byte 0x78 + reg ; .byte off ; .byte imm
+
+#define cmpb_mem_reg(mem,reg) .byte 0x3a ; .byte 0x06 | (reg << 3) ; .word mem
+#define cmpw_imm_reg(imm,reg) .byte 0x81 ; .byte 0xf8 + reg ; .word imm
+
+#define and_imm_ax(imm) .byte 0x25 ; .word imm
+
+
+
+#define BOOTADDR 0x7c00
+
+/*
+ * Each entry in the boot select table is a nul-terminated string
+ * of 8 bytes (not including the 0). A zero-length string (i.e.
+ * the first char is 0) indicates an unused entry.
+ */
+#define PARTNAMESIZE 8
+#define TABENTRYSIZE (PARTNAMESIZE + 1)
+#define NAMETABSIZE 4 * TABENTRYSIZE
+
+/*
+ * Flag defines. Currently only used to make the boot selector active
+ * or inactive. There may never be more because of space constraints.
+ */
+#define BFL_SELACTIVE 0x01
+
+/*
+ * Scan values for the various keys we use, as returned by the BIOS
+ */
+#define SCAN_ENTER 0x1c
+#define SCAN_F1 0x3b
+#define SCAN_F5 0x3f
+#define SCAN_F10 0x44
+
+/*
+ * Minimum and maximum drive number that is considered to be valid.
+ */
+#define MINDRV 0x80
+#define MAXDRV 0x88
+
+/*
+ * Error codes. Done this way to save space.
+ */
+#define ERR_INVPART '1' /* Invalid partition table */
+#define ERR_READ '2' /* Read error */
+#define ERR_NOOS '3' /* Magic no. check failed for part. */
+
+ .text
+/*
+ * Move ourselves out of the way first.
+ */
+ENTRY(start)
+ data32
+ xorl %eax, %eax
+ movl %ax, %ss
+ movl $BOOTADDR, %sp
+ movl %ax, %es
+ movl %ax, %ds
+ xorl %si,%si
+ movl %sp, %si
+ movw_imm_reg(_C_LABEL(start),DI)
+ movw_imm_reg(0x100,CX)
+ rep
+ movsl
+ jmpfar(0,1f)
+/*
+ * Sanity check the drive number passed by the BIOS. Some BIOSs may not
+ * do this and pass garbage.
+ */
+1:
+ cmpb $MINDRV,%dl
+ jb 2f
+ cmpb $MAXDRV,%dl
+ jbe 3f
+2:
+ movb $0x80,%dl
+3:
Home |
Main Index |
Thread Index |
Old Index