Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mmeye/stand COFF's /sbin/osloader



details:   https://anonhg.NetBSD.org/src/rev/aba56aacef62
branches:  trunk
changeset: 483917:aba56aacef62
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Mar 20 21:24:54 2000 +0000

description:
COFF's /sbin/osloader

diffstat:

 sys/arch/mmeye/stand/Makefile            |    4 +-
 sys/arch/mmeye/stand/bootcoff/Makefile   |    7 +
 sys/arch/mmeye/stand/bootcoff/osloader.c |  583 +++++++++++++++++++++++++++++++
 sys/arch/mmeye/stand/bootcoff/osloader.h |  135 +++++++
 4 files changed, 727 insertions(+), 2 deletions(-)

diffs (truncated from 748 to 300 lines):

diff -r 3d31c69b678f -r aba56aacef62 sys/arch/mmeye/stand/Makefile
--- a/sys/arch/mmeye/stand/Makefile     Mon Mar 20 21:10:03 2000 +0000
+++ b/sys/arch/mmeye/stand/Makefile     Mon Mar 20 21:24:54 2000 +0000
@@ -1,5 +1,5 @@
-#      $NetBSD: Makefile,v 1.1 1999/09/13 10:31:04 itojun Exp $
+#      $NetBSD: Makefile,v 1.2 2000/03/20 21:24:54 msaitoh Exp $
 
-SUBDIR= bootelf
+SUBDIR= bootelf bootcoff
 
 .include <bsd.subdir.mk>
diff -r 3d31c69b678f -r aba56aacef62 sys/arch/mmeye/stand/bootcoff/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mmeye/stand/bootcoff/Makefile    Mon Mar 20 21:24:54 2000 +0000
@@ -0,0 +1,7 @@
+#      $NetBSD: Makefile,v 1.1 2000/03/20 21:24:55 msaitoh Exp $
+
+PROG=  osloader
+SRCS=  osloader.c
+NOMAN=
+
+.include <bsd.prog.mk>
diff -r 3d31c69b678f -r aba56aacef62 sys/arch/mmeye/stand/bootcoff/osloader.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mmeye/stand/bootcoff/osloader.c  Mon Mar 20 21:24:54 2000 +0000
@@ -0,0 +1,583 @@
+/*********************************************************************
+ *      NetBSD(SH3) boot loader 
+ * 
+ *                1998.11.10
+ *                     By T.Horiuchi (Brains, Corp.)
+ *********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <sys/gmon.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <sys/file.h>
+#include <vm/vm_param.h>
+#include <machine/cpu.h>
+#include "osloader.h"
+
+#define vm_page_size (1<<12)
+
+char *netbsd = "/netbsd";
+struct coff_filehdr FileHdr;
+struct coff_aouthdr AoutHdr;
+
+static int coff_find_section __P((FILE *, struct coff_filehdr *,
+                            struct coff_scnhdr *, int));
+
+void LoadAndReset __P((char *));
+
+/*
+ * coff_find_section - load specified section header
+ *
+ * TODO - optimize by reading all section headers in at once
+ */
+
+static int
+coff_find_section( fd, fp, sh, s_type)
+       FILE *fd;
+       struct coff_filehdr *fp;
+       struct coff_scnhdr *sh;
+       int s_type;
+{
+       int i, pos, siz;
+       
+       pos = COFF_HDR_SIZE;
+       for (i = 0; i < fp->f_nscns; i++, pos += sizeof(struct coff_scnhdr)) {
+               siz = sizeof(struct coff_scnhdr);
+               if( fread(sh, 1, siz, fd ) != siz ){
+                       perror("osloader");
+                       exit( 1 );
+               }
+
+               if (sh->s_flags == s_type)
+                       return 0;
+       }
+       return -1;
+}
+
+void
+LoadAndReset( char *osimage )
+{
+       int mib[2];
+       u_long val;
+       int len;
+
+       mib[0] = CTL_MACHDEP;
+       mib[1] = CPU_LOADANDRESET;
+       val = (u_long)osimage;
+       len = sizeof( val );
+
+       sysctl(mib, 2, NULL, NULL, &val, len);
+}
+
+int 
+main(int argc, char *argv[] )
+{
+       FILE *fp;
+       int error;
+       long dsize;
+       struct coff_scnhdr sh;
+       u_long ep_taddr;
+       u_long ep_tsize;
+       u_long toffset;
+       u_long ep_daddr;
+       u_long ep_dsize;
+       u_long doffset;
+       char *osimage;
+       char *p;
+       int i;
+       u_long cksum;
+       u_long size;
+
+#if 0
+       printf("osloader: start\n");
+#endif
+
+       fp = fopen( netbsd, "r" );
+       if( fp == NULL ){
+               perror("osloader");
+               exit( 1 );
+       }
+
+       if( fread( &FileHdr, 1, sizeof( FileHdr ), fp ) != sizeof(FileHdr)){
+               perror("osloader");
+               exit( 1 );
+       }
+
+       if(fread( &AoutHdr, 1, sizeof( AoutHdr ), fp ) != sizeof(AoutHdr)){
+               perror("osloader");
+               exit( 1 );
+       }
+
+       /* set up command for text segment */
+       error = coff_find_section(fp, &FileHdr, &sh, COFF_STYP_TEXT);
+       if (error) {            
+               printf("can't find text section: %d\n", error);
+               exit( 1 );
+       }
+
+       ep_taddr = COFF_ALIGN(sh.s_vaddr);
+       toffset = sh.s_scnptr - (sh.s_vaddr - ep_taddr);
+       ep_tsize = sh.s_size + (sh.s_vaddr - ep_taddr);
+
+       printf("VMCMD: addr %lx size 0x%lx offset 0x%lx\n", ep_taddr,
+              ep_tsize, toffset); 
+
+       /* set up command for data segment */
+       error = coff_find_section(fp, &FileHdr, &sh, COFF_STYP_DATA);
+       if (error) {
+               printf("can't find data section: %d\n", error);
+               exit( 1 );
+       }
+
+       ep_daddr = COFF_ALIGN(sh.s_vaddr);
+       doffset = sh.s_scnptr - (sh.s_vaddr - ep_daddr);
+       dsize = sh.s_size + (sh.s_vaddr - ep_daddr);
+       ep_dsize = round_page(dsize) + AoutHdr.a_bsize;
+
+       printf("VMCMD: addr 0x%lx size 0x%lx offset 0x%lx\n", ep_daddr,
+                dsize, doffset); 
+
+       osimage = malloc( ep_tsize+dsize+sizeof(u_long)*2 );
+       if( osimage == NULL){
+               printf("osloader:no memory\n");
+               exit( 1 );
+       }
+
+       *(u_long *)osimage = ep_tsize+dsize;
+       p = osimage + 2*sizeof( u_long );
+       
+       /* load text area */
+       fseek( fp, toffset, SEEK_SET );
+       if( fread(p, 1, ep_tsize, fp) != ep_tsize ){
+               perror("osloader:");
+               exit( 1 );
+       }
+
+       /* load data area */
+       fseek( fp, doffset, SEEK_SET );
+       if( fread(p+ep_daddr-ep_taddr, 1, dsize, fp) != dsize ){
+               perror("osloader:");
+               exit( 1 );
+       }
+
+       fclose( fp );
+
+       cksum = 0;
+       size = (ep_tsize + dsize) >> 2;
+
+       for( i = 0; i < size; i++){
+               cksum += *(u_long *)p;
+               p += sizeof(u_long );
+       }
+
+       *(u_long *)(osimage+sizeof(u_long)) = cksum ;
+
+#if 0
+       printf("osimage = %p\n", osimage );
+#endif
+
+       LoadAndReset( osimage );
+
+       return (0);     /* NOT REACHED */
+}
+
+
+#ifdef NOTDEF
+
+/*
+ * exec_coff_makecmds(): Check if it's an coff-format executable.
+ *
+ * Given a proc pointer and an exec package pointer, see if the referent
+ * of the epp is in coff format.  Check 'standard' magic numbers for
+ * this architecture.  If that fails, return failure.
+ *
+ * This function is  responsible for creating a set of vmcmds which can be
+ * used to build the process's vm space and inserting them into the exec
+ * package.
+ */
+
+int
+exec_coff_makecmds(p, epp)
+       struct proc *p;
+       struct exec_package *epp;
+{
+       int error;
+       struct coff_filehdr *fp = epp->ep_hdr;
+       struct coff_aouthdr *ap;
+
+       if (epp->ep_hdrvalid < COFF_HDR_SIZE)
+               return ENOEXEC;
+
+       if (COFF_BADMAG(fp))
+               return ENOEXEC;
+       
+       ap = epp->ep_hdr + sizeof(struct coff_filehdr);
+       switch (ap->a_magic) {
+       case COFF_OMAGIC:
+               error = exec_coff_prep_omagic(p, epp, fp, ap);
+               break;
+       case COFF_NMAGIC:
+               error = exec_coff_prep_nmagic(p, epp, fp, ap);
+               break;
+       case COFF_ZMAGIC:
+               error = exec_coff_prep_zmagic(p, epp, fp, ap);
+               break;
+       default:
+               return ENOEXEC;
+       }
+
+#ifdef TODO
+       if (error == 0)
+               error = cpu_exec_coff_hook(p, epp );
+#endif
+
+       if (error)
+               kill_vmcmds(&epp->ep_vmcmds);
+
+       return error;
+}
+
+/*
+ * exec_coff_setup_stack(): Set up the stack segment for a coff
+ * executable.
+ *
+ * Note that the ep_ssize parameter must be set to be the current stack
+ * limit; this is adjusted in the body of execve() to yield the
+ * appropriate stack segment usage once the argument length is
+ * calculated.
+ *
+ * This function returns an int for uniformity with other (future) formats'
+ * stack setup functions.  They might have errors to return.
+ */
+
+int
+exec_coff_setup_stack(p, epp)
+       struct proc *p;
+       struct exec_package *epp;
+{
+       /* DPRINTF(("enter exec_coff_setup_stack\n")); */
+
+       epp->ep_maxsaddr = USRSTACK - MAXSSIZ;
+       epp->ep_minsaddr = USRSTACK;
+       epp->ep_ssize = p->p_rlimit[RLIMIT_STACK].rlim_cur;
+
+       /*
+        * set up commands for stack.  note that this takes *two*, one to
+        * map the part of the stack which we can access, and one to map
+        * the part which we can't.
+        *
+        * arguably, it could be made into one, but that would require the
+        * addition of another mapping proc, which is unnecessary
+        *



Home | Main Index | Thread Index | Old Index