Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/sys/arch/sun68k/stand/tapeboot Pull up revision 1.2 (re...



details:   https://anonhg.NetBSD.org/src/rev/c634e6ac74cd
branches:  netbsd-1-6
changeset: 530665:c634e6ac74cd
user:      tron <tron%NetBSD.org@localhost>
date:      Tue Sep 09 19:11:09 2003 +0000

description:
Pull up revision 1.2 (requested by fredette in ticket #1402):
Added seek support for tape files.  Before, seeking a tape file
would silently fail, causing loadfile to load file contents into
the wrong addresses.
On the sun3/sun3x, MARK_START was incorrectly set too.  Also
added support for booting a sun2.

diffstat:

 sys/arch/sun68k/stand/tapeboot/boot.c  |  28 ++++++++++++++++++---
 sys/arch/sun68k/stand/tapeboot/rawfs.c |  44 ++++++++++++++++++++++++++++++---
 2 files changed, 63 insertions(+), 9 deletions(-)

diffs (152 lines):

diff -r 245beddc39d0 -r c634e6ac74cd sys/arch/sun68k/stand/tapeboot/boot.c
--- a/sys/arch/sun68k/stand/tapeboot/boot.c     Sun Sep 07 13:11:18 2003 +0000
+++ b/sys/arch/sun68k/stand/tapeboot/boot.c     Tue Sep 09 19:11:09 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.1 2001/06/14 12:57:16 fredette Exp $ */
+/*     $NetBSD: boot.c,v 1.1.18.1 2003/09/09 19:11:09 tron Exp $ */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -50,8 +50,9 @@
  *   segment 1:  netbsd.sun3  (RAMDISK3)
  *   segment 2:  netbsd.sun3x (RAMDISK3X)
  *   segment 3:  miniroot image
- * Therefore, the default name is "1" or "2"
- * for sun3 and sun3x respectively.
+ *   segment 4:  netbsd.sun2  (RAMDISK)
+ * Therefore, the default name is "1" or "2" or "4"
+ * for sun3, sun3x, and sun2, respectively.
  */
 
 char   defname[32] = "1";
@@ -63,6 +64,7 @@
        char *cp, *file;
        void *entry;
        u_long marks[MARK_MAX];
+       u_long mark_start;
        int fd;
 
        printf(">> %s tapeboot [%s]\n", bootprog_name, bootprog_rev);
@@ -74,9 +76,23 @@
         * its position-to-segment on open.
         */
 
+       /* Assume the Sun3/Sun3x load start. */
+       memset(marks, 0, sizeof(marks));
+       mark_start = 0;
+
        /* If running on a Sun3X, use segment 2. */
        if (_is3x)
                defname[0] = '2';
+
+       /*
+        * If running on a Sun2, use segment 4 and
+        * do the special MMU setup.
+        */
+       else if (_is2) {
+               defname[0] = '4';
+               mark_start = sun2_map_mem_load();
+       }
+
        file = defname;
 
        cp = prom_bootfile;
@@ -94,7 +110,7 @@
                } else
                        printf("tapeboot: loading segment %s\n", file);
 
-               marks[MARK_START] = KERN_LOADADDR;
+               marks[MARK_START] = mark_start;
                if ((fd = loadfile(file, marks, LOAD_KERNEL)) != -1) {
                        break;
                }
@@ -104,6 +120,10 @@
        close(fd);
 
        entry = (void *)marks[MARK_ENTRY];
+       if (_is2) {
+               printf("relocating program...");
+               entry = sun2_map_mem_run(entry);
+       }
        printf("Starting program at 0x%x\n", entry);
        chain_to(entry);
 }
diff -r 245beddc39d0 -r c634e6ac74cd sys/arch/sun68k/stand/tapeboot/rawfs.c
--- a/sys/arch/sun68k/stand/tapeboot/rawfs.c    Sun Sep 07 13:11:18 2003 +0000
+++ b/sys/arch/sun68k/stand/tapeboot/rawfs.c    Tue Sep 09 19:11:09 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rawfs.c,v 1.1 2001/06/14 12:57:17 fredette Exp $       */
+/*     $NetBSD: rawfs.c,v 1.1.18.1 2003/09/09 19:11:09 tron Exp $      */
 
 /*
  * Copyright (c) 1995 Gordon W. Ross
@@ -53,6 +53,7 @@
  */
 struct file {
        daddr_t         fs_nextblk;     /* block number to read next */
+       off_t           fs_off;         /* seek offset in file */
        int                     fs_len;         /* amount left in f_buf */
        char *          fs_ptr;         /* read pointer into f_buf */
        char            fs_buf[RAWFS_BSIZE];
@@ -73,6 +74,7 @@
         */
        fs = alloc(sizeof(struct file));
        fs->fs_nextblk = 0;
+       fs->fs_off = 0;
        fs->fs_len = 0;
        fs->fs_ptr = fs->fs_buf;
 
@@ -132,6 +134,7 @@
                        csize = fs->fs_len;
 
                bcopy(fs->fs_ptr, addr, csize);
+               fs->fs_off += csize;
                fs->fs_ptr += csize;
                fs->fs_len -= csize;
                addr += csize;
@@ -161,10 +164,41 @@
        off_t offset;
        int where;
 {
-#ifdef DEBUG_RAWFS
-       panic("rawfs_seek");
-#endif
-       return (EFTYPE);
+       struct file *fs = (struct file *)f->f_fsdata;
+       off_t csize;
+
+       switch (where) {
+       case SEEK_SET:
+               offset -= fs->fs_off;
+               /* FALLTHROUGH */
+       case SEEK_CUR:
+               if (offset >= 0)
+                       break;
+               /* FALLTHROUGH */
+       case SEEK_END:
+       default:
+               return (-1);
+       }
+
+       while (offset != 0) {
+
+               if (fs->fs_len == 0)
+                       if (rawfs_get_block(f) != 0)
+                               return (-1);
+
+               if (fs->fs_len <= 0)
+                       break;  /* EOF */
+
+               csize = offset;
+               if (csize > fs->fs_len)
+                       csize = fs->fs_len;
+
+               fs->fs_off += csize;
+               fs->fs_ptr += csize;
+               fs->fs_len -= csize;
+               offset -= csize;
+       }
+       return (fs->fs_off);
 }
 
 int



Home | Main Index | Thread Index | Old Index