Author: avg
Date: Wed May  9 08:04:29 2012
New Revision: 235154
URL: http://svn.freebsd.org/changeset/base/235154

Log:
  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

Added:
  head/sys/boot/i386/btx/lib/btxcsu.S
     - copied, changed from r235152, head/sys/boot/i386/btx/lib/btxcsu.s
  head/sys/boot/i386/common/bootargs.h   (contents, props changed)
Deleted:
  head/sys/boot/i386/btx/lib/btxcsu.s
Modified:
  head/sys/boot/i386/btx/btx/Makefile
  head/sys/boot/i386/btx/btx/btx.S
  head/sys/boot/i386/btx/btxldr/Makefile
  head/sys/boot/i386/btx/btxldr/btxldr.S
  head/sys/boot/i386/btx/lib/Makefile
  head/sys/boot/i386/loader/main.c
  head/sys/boot/i386/zfsboot/zfsboot.c

Modified: head/sys/boot/i386/btx/btx/Makefile
==============================================================================
--- head/sys/boot/i386/btx/btx/Makefile Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/btx/btx/Makefile Wed May  9 08:04:29 2012        
(r235154)
@@ -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

Modified: head/sys/boot/i386/btx/btx/btx.S
==============================================================================
--- head/sys/boot/i386/btx/btx/btx.S    Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/btx/btx/btx.S    Wed May  9 08:04:29 2012        
(r235154)
@@ -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

Modified: head/sys/boot/i386/btx/btxldr/Makefile
==============================================================================
--- head/sys/boot/i386/btx/btxldr/Makefile      Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/btx/btxldr/Makefile      Wed May  9 08:04:29 2012        
(r235154)
@@ -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

Modified: head/sys/boot/i386/btx/btxldr/btxldr.S
==============================================================================
--- head/sys/boot/i386/btx/btxldr/btxldr.S      Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/btx/btxldr/btxldr.S      Wed May  9 08:04:29 2012        
(r235154)
@@ -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 argumen
                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

Modified: head/sys/boot/i386/btx/lib/Makefile
==============================================================================
--- head/sys/boot/i386/btx/lib/Makefile Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/btx/lib/Makefile Wed May  9 08:04:29 2012        
(r235154)
@@ -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>

Copied and modified: head/sys/boot/i386/btx/lib/btxcsu.S (from r235152, 
head/sys/boot/i386/btx/lib/btxcsu.s)
==============================================================================
--- head/sys/boot/i386/btx/lib/btxcsu.s Wed May  9 04:54:50 2012        
(r235152, copy source)
+++ head/sys/boot/i386/btx/lib/btxcsu.S Wed May  9 08:04:29 2012        
(r235154)
@@ -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

Added: head/sys/boot/i386/common/bootargs.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/boot/i386/common/bootargs.h        Wed May  9 08:04:29 2012        
(r235154)
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2012 Andriy Gapon <a...@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_ */

Modified: head/sys/boot/i386/loader/main.c
==============================================================================
--- head/sys/boot/i386/loader/main.c    Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/loader/main.c    Wed May  9 08:04:29 2012        
(r235154)
@@ -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;

Modified: head/sys/boot/i386/zfsboot/zfsboot.c
==============================================================================
--- head/sys/boot/i386/zfsboot/zfsboot.c        Wed May  9 07:55:42 2012        
(r235153)
+++ head/sys/boot/i386/zfsboot/zfsboot.c        Wed May  9 08:04:29 2012        
(r235154)
@@ -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"
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to