summaryrefslogtreecommitdiffstats
path: root/sys/boot/i386
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2012-05-09 08:04:29 +0000
committeravg <avg@FreeBSD.org>2012-05-09 08:04:29 +0000
commita5d68259c2d9ee2ae1d901e393c549f79274ba13 (patch)
tree64f3913b8394e9df98b044ee301d7200d7c6cbaf /sys/boot/i386
parentc4c31a507d2ada4ae55e23d07381c15a834cbc0c (diff)
downloadFreeBSD-src-a5d68259c2d9ee2ae1d901e393c549f79274ba13.zip
FreeBSD-src-a5d68259c2d9ee2ae1d901e393c549f79274ba13.tar.gz
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
Diffstat (limited to 'sys/boot/i386')
-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 2b4abe6..236d269 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 e762e4b..bf4400e 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 56333e7..b76468b 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 d4176eb..848b930 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 8fab66a..856d868 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 6a00659..c46f809 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 0000000..4768d68
--- /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 75d5dbc..2202c73 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 a6be3ee..17881dd 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"
OpenPOWER on IntegriCloud