# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.18 2008/09/13 11:45:45 corecode Exp $
-PROG= boot2
-NOMAN=
-STRIP=
BINDIR?= /boot
BINMODE= 444
-CLEANFILES= boot boot1 boot1.out boot1.o \
- boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
- boot2.s sio.o
+CLEANFILES= boot \
+ sio.o
NM?= nm
NXCFLAGS=
#
ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
-# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
-
-# BOOT2_UFS?= UFS2_ONLY
-#BOOT2_UFS?= UFS1_AND_UFS2
-BOOT2_UFS?= UFS1_ONLY
-#BOOT2_UFS?= HAMMERFS
-
# gcc3.x
# -fno-guess-branch-probability
# -mno-align-long-strings
-fomit-frame-pointer \
-std=c99 \
-DBOOT2 \
- -D${BOOT2_UFS} \
-I${.CURDIR}/../../common \
-I${.CURDIR}/../../../../lib/libstand \
-I${.CURDIR}/../btx/lib -I. \
CFLAGS+= -fno-stack-protector
.endif
-NSECT?= 16
-CFLAGS+= -DNSECT=${NSECT}
-
+NSECT_32?= 16
+NSECT_64?= 18
LDFLAGS=-nostdlib -static -N --gc-sections
-all: boot1 boot2 boot
+all: boot
+
+boot: boot1_32 boot2_32
+ cat ${.ALLSRC} > boot
+
+.for s in _32 _64
+
+_ADDCFLAGS$s:= -DNSECT=${NSECT$s}
+_ts= $s
+.if ${_ts} == "_64"
+_ADDCFLAGS$s+= -DDISKLABEL64
+_ADDCFLAGS$s+= -DHAMMERFS
+.else
+_ADDCFLAGS$s+= -DUFS1_ONLY
+.endif
-boot: boot1 boot2
- cat boot1 boot2 > boot
+all: boot1$s boot2$s
-boot1: boot1.out
- objcopy -S -O binary boot1.out ${.TARGET}
+boot1$s: boot1$s.out
+ objcopy -S -O binary boot1$s.out ${.TARGET}
-boot1.out: boot1.o bootasmdef.nx
- ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
+boot1$s.out: boot1$s.o bootasmdef.nx
+ ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
-boot1.o: boot1.S
- ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} \
- ${.IMPSRC} -o ${.TARGET} -c
+boot1$s.o: boot1.S
+ ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
+ ${.ALLSRC} -o ${.TARGET} -c
-boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
- ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
- sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
- rm -f boot2.s.tmp
- ${AS} ${AFLAGS} -o boot2.o boot2.s
+boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
+ ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp boot2.c
+ sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
+ rm -f boot2$s.s.tmp
+ ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
-boot2.h: boot1.out bootasmdef.nx
+boot2$s.h: boot1$s.out bootasmdef.nx
@echo "NOTE: boot2 using xread from boot1 at ${REL1}"
${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
{ x = $$1 - ORG1; \
printf("#define XREADORG %#x\n", REL1 + x) }' \
- ORG1=${ORG1D} REL1=${REL1D} > boot2.h
+ ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
-boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
- btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
- -o boot2.ld -P 1 boot2.bin
- stat boot2.ld | awk '{ x = (${NSECT} - 1) * 512 - $$8; \
+boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
+ btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
+ -o boot2$s.ld -P 1 boot2$s.bin
+ stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
print x " bytes available"; if (x < 0) exit 1 }'
- dd if=boot2.ld of=${.TARGET} obs=$$(( (${NSECT} - 1) * 512)) conv=osync 2>/dev/null
+ dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
-boot2.ldr:
+boot2$s.ldr:
dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
-boot2.bin: boot2.out
- objcopy -S -O binary boot2.out ${.TARGET}
+boot2$s.bin: boot2$s.out
+ objcopy -S -O binary boot2$s.out ${.TARGET}
-boot2.out: boot2.o sio.o
+boot2$s.out: boot2$s.o sio.o
${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
${BTX}/lib/crt0.o ${.ALLSRC}
-boot2.o: boot2.h
+boot2$s.o: boot2$s.h
+
+CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
+ boot2$s boot2$s.ldr boot2$s.bin boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s
+
+.endfor
sio.o: sio.S
${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
- ${.IMPSRC} -o ${.TARGET} -c
+ ${.ALLSRC} -o ${.TARGET} -c
install:
${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
boot ${DESTDIR}${BINDIR}/boot
${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- boot1 ${DESTDIR}${BINDIR}/boot1
+ boot1_32 ${DESTDIR}${BINDIR}/boot1
+ ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ boot2_32 ${DESTDIR}${BINDIR}/boot2
+ ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ boot1_64 ${DESTDIR}${BINDIR}/boot1_64
${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- boot2 ${DESTDIR}${BINDIR}/boot2
+ boot2_64 ${DESTDIR}${BINDIR}/boot2_64
.include <bsd.prog.mk>
//
main.5: pushw %dx // Save args
movb $NSECT,%dh // Sector count
+#ifdef DISKLABEL64
+ // In disklabel64 boot2 starts
+ addl $7,0x8(%si) // offset 0x1000.
+#endif
callw nread // Read disk
mov $MEM_BTX_ORG,%bx // Base of BTX header
mov 0xa(%bx),%si // Get BTX text length (btx.S)
#endif
#include <sys/param.h>
+#ifdef DISKLABEL64
+#include <sys/disklabel64.h>
+#else
#include <sys/disklabel32.h>
+#endif
#include <sys/diskslice.h>
#include <sys/diskmbr.h>
#include <sys/dtype.h>
#include <btxv86.h>
-#include "boot2.h"
+#ifdef DISKLABEL64
+#include "boot2_64.h"
+#else
+#include "boot2_32.h"
+#endif
+
#include "lib.h"
#include "../bootasm.h"
dskread(void *buf, unsigned lba, unsigned nblk)
{
struct dos_partition *dp;
+#ifdef DISKLABEL64
+ struct disklabel64 *d;
+#else
struct disklabel32 *d;
+#endif
char *sec;
unsigned sl, i;
}
dsk.start = dp->dp_start;
}
+#ifdef DISKLABEL64
+ if (drvread(sec, dsk.start, (sizeof(struct disklabel64) + 511) / 512))
+ return -1;
+ d = (void *)sec;
+ if (d->d_magic != DISKMAGIC64) {
+ printf(INVALID_S, "label");
+ return -1;
+ } else {
+ if (dsk.part >= d->d_npartitions || d->d_partitions[dsk.part].p_bsize == 0) {
+ printf(INVALID_S, "partition");
+ return -1;
+ }
+ dsk.start += d->d_partitions[dsk.part].p_boffset / 512;
+ }
+#else
if (drvread(sec, dsk.start + LABELSECTOR32, 1))
return -1;
d = (void *)(sec + LABELOFFSET32);
dsk.start += d->d_partitions[dsk.part].p_offset;
dsk.start -= d->d_partitions[RAW_PART].p_offset;
}
+#endif
}
return drvread(buf, dsk.start + lba, nblk);
}
* This is the origin of boot2.bin relative to the BTX user address space
* (e.g. physical address would be MEM_BTX_USR+BOOT2_VORIGIN).
*/
-#define BOOT2_VORIGIN 0x2000
+#define BOOT2_VORIGIN 0x4000
/*
* NOTE: BOOT0_ORIGIN is extracted from this file and used in boot0/Makefile
#include <stand.h>
#include <sys/disklabel32.h>
+#include <sys/disklabel64.h>
#include <sys/diskmbr.h>
#include <sys/dtype.h>
#include <machine/bootinfo.h>
#define BIOS_NUMDRIVES 0x475
#define BIOSDISK_SECSIZE 512
-#define BUFSIZE (1 * BIOSDISK_SECSIZE)
+#define BUFSIZE (4 * BIOSDISK_SECSIZE)
#define MAXBDDEV MAXDEV
#define DT_ATAPI 0x10 /* disk type for ATAPI floppies */
#define BD_FLOPPY 0x0004
#define BD_LABELOK 0x0008
#define BD_PARTTABOK 0x0010
- struct disklabel32 od_disklabel;
+ union {
+ struct disklabel32 od_disklabel;
+ struct disklabel64 od_disklabel64;
+ };
int od_nslices; /* slice count */
struct dos_partition od_slicetab[NEXTDOSPART];
};
{
struct dos_partition *dptr;
struct disklabel32 *lp;
+ struct disklabel64 *lp64;
struct open_disk *od;
int sector, slice, i;
int error;
- char buf[BUFSIZE];
+ static char buf[BUFSIZE];
if (dev->d_kind.biosdisk.unit >= nbdinfo) {
DEBUG("attempt to open nonexistent disk");
DEBUG("copy %d bytes of label from %p to %p", sizeof(struct disklabel32), buf + LABELOFFSET32, &od->od_disklabel);
bcopy(buf + LABELOFFSET32, &od->od_disklabel, sizeof(struct disklabel32));
lp = &od->od_disklabel;
- od->od_flags |= BD_LABELOK;
- if (lp->d_magic != DISKMAGIC32) {
- DEBUG("no disklabel");
- error = ENOENT;
+ if (lp->d_magic == DISKMAGIC32) {
+ od->od_flags |= BD_LABELOK;
+
+ if (dev->d_kind.biosdisk.partition >= lp->d_npartitions) {
+ DEBUG("partition '%c' exceeds partitions in table (a-'%c')",
+ 'a' + dev->d_kind.biosdisk.partition, 'a' + lp->d_npartitions);
+ error = EPART;
+ goto out;
+
+ }
+
+#ifdef DISK_DEBUG
+ /* Complain if the partition is unused unless this is a floppy. */
+ if ((lp->d_partitions[dev->d_kind.biosdisk.partition].p_fstype == FS_UNUSED) &&
+ !(od->od_flags & BD_FLOPPY))
+ DEBUG("warning, partition marked as unused");
+#endif
+
+ od->od_boff =
+ lp->d_partitions[dev->d_kind.biosdisk.partition].p_offset -
+ lp->d_partitions[RAW_PART].p_offset +
+ sector;
+
goto out;
}
- if (dev->d_kind.biosdisk.partition >= lp->d_npartitions) {
- DEBUG("partition '%c' exceeds partitions in table (a-'%c')",
- 'a' + dev->d_kind.biosdisk.partition, 'a' + lp->d_npartitions);
- error = EPART;
- goto out;
+ /* else maybe DISKLABEL64? */
+
+ if (bd_read(od, sector, (sizeof(od->od_disklabel64) + 511) / 512, buf)) {
+ DEBUG("error reading disklabel");
+ error = EIO;
+ goto out;
}
+ DEBUG("copy %d bytes of label from %p to %p", sizeof(od->od_disklabel64), buf, &od->od_disklabel64);
+ bcopy(buf, &od->od_disklabel64, sizeof(od->od_disklabel64));
+ lp64 = &od->od_disklabel64;
-#ifdef DISK_DEBUG
- /* Complain if the partition is unused unless this is a floppy. */
- if ((lp->d_partitions[dev->d_kind.biosdisk.partition].p_fstype == FS_UNUSED) &&
- !(od->od_flags & BD_FLOPPY))
- DEBUG("warning, partition marked as unused");
-#endif
-
- od->od_boff =
- lp->d_partitions[dev->d_kind.biosdisk.partition].p_offset -
- lp->d_partitions[RAW_PART].p_offset +
- sector;
+ if (lp64->d_magic == DISKMAGIC64) {
+ od->od_flags |= BD_LABELOK;
+
+ if (dev->d_kind.biosdisk.partition >= lp64->d_npartitions ||
+ lp64->d_partitions[dev->d_kind.biosdisk.partition].p_bsize == 0) {
+ DEBUG("partition '%c' exceeds partitions in table (a-'%c')",
+ 'a' + dev->d_kind.biosdisk.partition, 'a' + lp64->d_npartitions);
+ error = EPART;
+ goto out;
+
+ }
+
+ od->od_boff =
+ lp64->d_partitions[dev->d_kind.biosdisk.partition].p_boffset / 512 +
+ sector;
+
+ DEBUG("disklabel64 slice at %d", od->od_boff);
+
+ } else {
+ DEBUG("no disklabel");
+ error = ENOENT;
+ }
}
-
+
out:
if (error) {
free(od);
};
struct fs_ops *file_system[] = {
+ &hammer_fsops,
&ufs_fsops,
&ext2fs_fsops,
&dosfs_fsops,