Author: avg
Date: Fri Jun 29 10:01:56 2012
New Revision: 237756
URL: http://svn.freebsd.org/changeset/base/237756

Log:
  MFC r235154,r235158: btxldr: future-proof argument passing from
  boot1/2-ish to loader

Added:
  stable/9/sys/boot/i386/btx/lib/btxcsu.S
     - copied unchanged from r235154, head/sys/boot/i386/btx/lib/btxcsu.S
  stable/9/sys/boot/i386/common/bootargs.h
     - copied unchanged from r235154, head/sys/boot/i386/common/bootargs.h
Deleted:
  stable/9/sys/boot/i386/btx/lib/btxcsu.s
Modified:
  stable/9/sys/boot/i386/btx/btx/Makefile
  stable/9/sys/boot/i386/btx/btx/btx.S
  stable/9/sys/boot/i386/btx/btxldr/Makefile
  stable/9/sys/boot/i386/btx/btxldr/btxldr.S
  stable/9/sys/boot/i386/btx/lib/Makefile
  stable/9/sys/boot/i386/loader/main.c
  stable/9/sys/boot/i386/zfsboot/zfsboot.c
Directory Properties:
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)

Modified: stable/9/sys/boot/i386/btx/btx/Makefile
==============================================================================
--- stable/9/sys/boot/i386/btx/btx/Makefile     Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/btx/btx/Makefile     Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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: stable/9/sys/boot/i386/btx/btx/btx.S
==============================================================================
--- stable/9/sys/boot/i386/btx/btx/btx.S        Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/btx/btx/btx.S        Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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: stable/9/sys/boot/i386/btx/btxldr/Makefile
==============================================================================
--- stable/9/sys/boot/i386/btx/btxldr/Makefile  Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/btx/btxldr/Makefile  Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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: stable/9/sys/boot/i386/btx/btxldr/btxldr.S
==============================================================================
--- stable/9/sys/boot/i386/btx/btxldr/btxldr.S  Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/btx/btxldr/btxldr.S  Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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: stable/9/sys/boot/i386/btx/lib/Makefile
==============================================================================
--- stable/9/sys/boot/i386/btx/lib/Makefile     Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/btx/lib/Makefile     Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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: stable/9/sys/boot/i386/btx/lib/btxcsu.S (from r235154, 
head/sys/boot/i386/btx/lib/btxcsu.S)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/boot/i386/btx/lib/btxcsu.S     Fri Jun 29 10:01:56 2012        
(r237756, copy of r235154, head/sys/boot/i386/btx/lib/btxcsu.S)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 1998 Robert Nordier
+# 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$
+
+#include <bootargs.h>
+
+#
+# BTX C startup code (ELF).
+#
+
+#
+# Globals.
+#
+               .global _start
+#
+# Client entry point.
+#
+_start:        cld
+               pushl %eax
+               movl $_edata,%edi 
+               movl $_end,%ecx 
+               subl %edi, %ecx
+               xorb %al, %al
+               rep
+               stosb
+               popl __base
+               movl %esp,%eax                  # Set
+               addl $ARGADJ,%eax               #  argument
+               movl %eax,__args                #  pointer
+               call main                       # Invoke client main()
+               call exit                       # Invoke client exit()
+#
+# Data.
+#
+               .comm __base,4                  # Client base address
+               .comm __args,4                  # Client arguments

Copied: stable/9/sys/boot/i386/common/bootargs.h (from r235154, 
head/sys/boot/i386/common/bootargs.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/boot/i386/common/bootargs.h    Fri Jun 29 10:01:56 2012        
(r237756, copy of r235154, head/sys/boot/i386/common/bootargs.h)
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2012 Andriy Gapon <[email protected]>
+ * 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: stable/9/sys/boot/i386/loader/main.c
==============================================================================
--- stable/9/sys/boot/i386/loader/main.c        Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/loader/main.c        Fri Jun 29 10:01:56 2012        
(r237756)
@@ -33,34 +33,24 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <stand.h>
+#include <stddef.h>
 #include <string.h>
 #include <machine/bootinfo.h>
 #include <machine/psl.h>
 #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: stable/9/sys/boot/i386/zfsboot/zfsboot.c
==============================================================================
--- stable/9/sys/boot/i386/zfsboot/zfsboot.c    Fri Jun 29 10:01:52 2012        
(r237755)
+++ stable/9/sys/boot/i386/zfsboot/zfsboot.c    Fri Jun 29 10:01:56 2012        
(r237756)
@@ -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"
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "[email protected]"

Reply via email to