aboutsummaryrefslogtreecommitdiff
path: root/sys/boot
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2012-05-09 08:04:29 +0000
committerAndriy Gapon <avg@FreeBSD.org>2012-05-09 08:04:29 +0000
commit29c8c4b0f5d3021f511cfca6fbe370fb8e8e8842 (patch)
tree64f3913b8394e9df98b044ee301d7200d7c6cbaf /sys/boot
parent5ef10e566c901c75b39e09f3c0151d28b46e630b (diff)
downloadsrc-29c8c4b0f5d3021f511cfca6fbe370fb8e8e8842.tar.gz
src-29c8c4b0f5d3021f511cfca6fbe370fb8e8e8842.zip
btxldr: future-proof argument passing from boot1/2-ish to loader
Place the arguments at a fixed offset of 0x800 withing the argument area (of size 0x1000). Allow variable size extended arguments first of which should be a size of the extended arguments (including the size parameter). Consolidate all related definitions in a new i386/common/bootargs.h header. Many thanks to jhb and bde for their guidance and reviews. Reviewed by: jhb, bde Approved by: jhb MFC after: 1 month
Notes
Notes: svn path=/head/; revision=235154
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/i386/btx/btx/Makefile1
-rw-r--r--sys/boot/i386/btx/btx/btx.S4
-rw-r--r--sys/boot/i386/btx/btxldr/Makefile1
-rw-r--r--sys/boot/i386/btx/btxldr/btxldr.S22
-rw-r--r--sys/boot/i386/btx/lib/Makefile3
-rw-r--r--sys/boot/i386/btx/lib/btxcsu.S (renamed from sys/boot/i386/btx/lib/btxcsu.s)6
-rw-r--r--sys/boot/i386/common/bootargs.h69
-rw-r--r--sys/boot/i386/loader/main.c23
-rw-r--r--sys/boot/i386/zfsboot/zfsboot.c4
9 files changed, 99 insertions, 34 deletions
diff --git a/sys/boot/i386/btx/btx/Makefile b/sys/boot/i386/btx/btx/Makefile
index 2b4abe6ab120..236d2693e1e1 100644
--- a/sys/boot/i386/btx/btx/Makefile
+++ b/sys/boot/i386/btx/btx/Makefile
@@ -12,6 +12,7 @@ BOOT_BTX_FLAGS=0x0
.endif
CFLAGS+=-DBTX_FLAGS=${BOOT_BTX_FLAGS}
+CFLAGS+=-I${.CURDIR}/../../common
.if defined(BTX_SERIAL)
BOOT_COMCONSOLE_PORT?= 0x3f8
diff --git a/sys/boot/i386/btx/btx/btx.S b/sys/boot/i386/btx/btx/btx.S
index e762e4baab56..bf4400e62e74 100644
--- a/sys/boot/i386/btx/btx/btx.S
+++ b/sys/boot/i386/btx/btx/btx.S
@@ -15,6 +15,8 @@
* $FreeBSD$
*/
+#include <bootargs.h>
+
/*
* Memory layout.
*/
@@ -205,7 +207,7 @@ init.8: xorl %ecx,%ecx # Zero
movl $MEM_USR,%edx # User base address
movzwl %ss:BDA_MEM,%eax # Get free memory
shll $0xa,%eax # To bytes
- subl $0x1000,%eax # Less arg space
+ subl $ARGSPACE,%eax # Less arg space
subl %edx,%eax # Less base
movb $SEL_UDATA,%cl # User data selector
pushl %ecx # Set SS
diff --git a/sys/boot/i386/btx/btxldr/Makefile b/sys/boot/i386/btx/btxldr/Makefile
index 56333e7f35e2..b76468be018d 100644
--- a/sys/boot/i386/btx/btxldr/Makefile
+++ b/sys/boot/i386/btx/btxldr/Makefile
@@ -6,6 +6,7 @@ NO_MAN=
SRCS= btxldr.S
CFLAGS+=-DLOADER_ADDRESS=${LOADER_ADDRESS}
+CFLAGS+=-I${.CURDIR}/../../common
.if defined(BTXLDR_VERBOSE)
CFLAGS+=-DBTXLDR_VERBOSE
diff --git a/sys/boot/i386/btx/btxldr/btxldr.S b/sys/boot/i386/btx/btxldr/btxldr.S
index d4176eb9c3b9..848b930b7907 100644
--- a/sys/boot/i386/btx/btxldr/btxldr.S
+++ b/sys/boot/i386/btx/btxldr/btxldr.S
@@ -15,6 +15,8 @@
* $FreeBSD$
*/
+#include <bootargs.h>
+
#define RBX_MUTE 0x10 /* -m */
#define OPT_SET(opt) (1 << (opt))
@@ -89,7 +91,7 @@ start: cld # String ops inc
call hexout # stack
call putstr # pointer
movl $m_args,%esi # Format string
- leal 0x4(%esp,1),%ebx # First argument
+ leal 0x4(%esp),%ebx # First argument
movl $0x6,%ecx # Count
start.1: movl (%ebx),%eax # Get argument and
addl $0x4,%ebx # bump pointer
@@ -97,24 +99,28 @@ start.1: movl (%ebx),%eax # Get argument and
loop start.1 # Till done
call putstr # End message
#endif
- movl $0x48,%ecx # Allocate space
- subl %ecx,%ebp # for bootinfo
- movl 0x18(%esp,1),%esi # Source: bootinfo
+ movl BA_BOOTINFO+4(%esp),%esi # Source: bootinfo
cmpl $0x0, %esi # If the bootinfo pointer
je start_null_bi # is null, don't copy it
+ movl BI_SIZE(%esi),%ecx # Allocate space
+ subl %ecx,%ebp # for bootinfo
movl %ebp,%edi # Destination
rep # Copy
movsb # it
- movl %ebp,0x18(%esp,1) # Update pointer
+ movl %ebp,BA_BOOTINFO+4(%esp) # Update pointer
+ movl %edi,%ebp # Restore base pointer
#ifdef BTXLDR_VERBOSE
movl $m_rel_bi,%esi # Display
movl %ebp,%eax # bootinfo
call hexout # relocation
call putstr # message
#endif
-start_null_bi: movl $0x18,%ecx # Allocate space
- subl %ecx,%ebp # for arguments
- leal 0x4(%esp,1),%esi # Source
+start_null_bi: movl $BOOTARGS_SIZE,%ecx # Fixed size of arguments
+ testl $KARGS_FLAGS_EXTARG, BA_BOOTFLAGS+4(%esp) # Check for extra data
+ jz start_fixed # Skip if the flag is not set
+ addl BOOTARGS_SIZE+4(%esp),%ecx # Add size of variable args
+start_fixed: subl $ARGOFF,%ebp # Place args at fixed offset
+ leal 0x4(%esp),%esi # Source
movl %ebp,%edi # Destination
rep # Copy
movsb # them
diff --git a/sys/boot/i386/btx/lib/Makefile b/sys/boot/i386/btx/lib/Makefile
index 8fab66a541af..856d86806bcd 100644
--- a/sys/boot/i386/btx/lib/Makefile
+++ b/sys/boot/i386/btx/lib/Makefile
@@ -3,7 +3,8 @@
PROG= crt0.o
INTERNALPROG=
NO_MAN=
-SRCS= btxcsu.s btxsys.s btxv86.s
+SRCS= btxcsu.S btxsys.s btxv86.s
+CFLAGS+=-I${.CURDIR}/../../common
LDFLAGS=-Wl,-r
.include <bsd.prog.mk>
diff --git a/sys/boot/i386/btx/lib/btxcsu.s b/sys/boot/i386/btx/lib/btxcsu.S
index 6a006596295f..c46f8097dbe3 100644
--- a/sys/boot/i386/btx/lib/btxcsu.s
+++ b/sys/boot/i386/btx/lib/btxcsu.S
@@ -15,6 +15,8 @@
# $FreeBSD$
+#include <bootargs.h>
+
#
# BTX C startup code (ELF).
#
@@ -24,10 +26,6 @@
#
.global _start
#
-# Constants.
-#
- .set ARGADJ,0xfa0 # Argument adjustment
-#
# Client entry point.
#
_start: cld
diff --git a/sys/boot/i386/common/bootargs.h b/sys/boot/i386/common/bootargs.h
new file mode 100644
index 000000000000..4768d68ae181
--- /dev/null
+++ b/sys/boot/i386/common/bootargs.h
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2012 Andriy Gapon <avg@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _BOOT_I386_ARGS_H_
+#define _BOOT_I386_ARGS_H_
+
+#define KARGS_FLAGS_CD 0x1
+#define KARGS_FLAGS_PXE 0x2
+#define KARGS_FLAGS_ZFS 0x4
+#define KARGS_FLAGS_EXTARG 0x8 /* variably sized extended argument */
+
+#define BOOTARGS_SIZE 24 /* sizeof(struct bootargs) */
+#define BA_BOOTFLAGS 8 /* offsetof(struct bootargs, bootflags) */
+#define BA_BOOTINFO 20 /* offsetof(struct bootargs, bootinfo) */
+#define BI_SIZE 48 /* offsetof(struct bootinfo, bi_size) */
+
+/*
+ * We reserve some space above BTX allocated stack for the arguments
+ * and certain data that could hang off them. Currently only struct bootinfo
+ * is supported in that category. The bootinfo is placed at the top
+ * of the arguments area and the actual arguments are placed at ARGOFF offset
+ * from the top and grow towards the top. Hopefully we have enough space
+ * for bootinfo and the arguments to not run into each other.
+ * Arguments area below ARGOFF is reserved for future use.
+ */
+#define ARGSPACE 0x1000 /* total size of the BTX args area */
+#define ARGOFF 0x800 /* actual args offset within the args area */
+#define ARGADJ (ARGSPACE - ARGOFF)
+
+#ifndef __ASSEMBLER__
+
+struct bootargs
+{
+ uint32_t howto;
+ uint32_t bootdev;
+ uint32_t bootflags;
+ union {
+ struct {
+ uint32_t pxeinfo;
+ uint32_t reserved;
+ };
+ uint64_t zfspool;
+ };
+ uint32_t bootinfo;
+
+ /*
+ * If KARGS_FLAGS_EXTARG is set in bootflags, then the above fields
+ * are followed by a uint32_t field that specifies a size of the
+ * extended arguments (including the size field).
+ */
+};
+
+#endif /*__ASSEMBLER__*/
+
+#endif /* !_BOOT_I386_ARGS_H_ */
diff --git a/sys/boot/i386/loader/main.c b/sys/boot/i386/loader/main.c
index 75d5dbcb6ec5..2202c73d169c 100644
--- a/sys/boot/i386/loader/main.c
+++ b/sys/boot/i386/loader/main.c
@@ -39,28 +39,17 @@ __FBSDID("$FreeBSD$");
#include <sys/reboot.h>
#include "bootstrap.h"
+#include "common/bootargs.h"
#include "libi386/libi386.h"
#include "btxv86.h"
-#define KARGS_FLAGS_CD 0x1
-#define KARGS_FLAGS_PXE 0x2
-#define KARGS_FLAGS_ZFS 0x4
+CTASSERT(sizeof(struct bootargs) == BOOTARGS_SIZE);
+CTASSERT(offsetof(struct bootargs, bootinfo) == BA_BOOTINFO);
+CTASSERT(offsetof(struct bootargs, bootflags) == BA_BOOTFLAGS);
+CTASSERT(offsetof(struct bootinfo, bi_size) == BI_SIZE);
/* Arguments passed in from the boot1/boot2 loader */
-static struct
-{
- u_int32_t howto;
- u_int32_t bootdev;
- u_int32_t bootflags;
- union {
- struct {
- u_int32_t pxeinfo;
- u_int32_t res2;
- };
- uint64_t zfspool;
- };
- u_int32_t bootinfo;
-} *kargs;
+static struct bootargs *kargs;
static u_int32_t initial_howto;
static u_int32_t initial_bootdev;
diff --git a/sys/boot/i386/zfsboot/zfsboot.c b/sys/boot/i386/zfsboot/zfsboot.c
index a6be3ee3a9aa..17881ddcaa3b 100644
--- a/sys/boot/i386/zfsboot/zfsboot.c
+++ b/sys/boot/i386/zfsboot/zfsboot.c
@@ -41,9 +41,7 @@ __FBSDID("$FreeBSD$");
#include "drv.h"
#include "util.h"
#include "cons.h"
-
-/* Hint to loader that we came from ZFS */
-#define KARGS_FLAGS_ZFS 0x4
+#include "bootargs.h"
#define PATH_DOTCONFIG "/boot.config"
#define PATH_CONFIG "/boot/config"