Add checksumming code.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Fri, 5 Oct 1990 18:58:30 +0000 (18:58 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Fri, 5 Oct 1990 18:58:30 +0000 (18:58 +0000)
v7/src/microcode/dump.c
v7/src/microcode/fasload.c
v7/src/microcode/load.c

index cdc8ce50c4197c5e034aa592ae274d4c5e06dfbf..768d3af7e5e3d5e3728f11e93577027e80876078 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dump.c,v 9.30 1989/11/30 03:03:51 jinx Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dump.c,v 9.31 1990/10/05 18:58:04 jinx Exp $
 
 Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology
 
@@ -38,11 +38,11 @@ extern SCHEME_OBJECT compiler_utilities;
 extern long compiler_interface_version, compiler_processor_type;
 
 void
-prepare_dump_header(Buffer, Dumped_Object,
-                   Heap_Count, Heap_Relocation,
-                   Constant_Count, Constant_Relocation,
-                   table_length, table_size,
-                   cc_code_p, band_p)
+prepare_dump_header (Buffer, Dumped_Object,
+                    Heap_Count, Heap_Relocation,
+                    Constant_Count, Constant_Relocation,
+                    table_length, table_size,
+                    cc_code_p, band_p)
      SCHEME_OBJECT
        *Buffer, *Dumped_Object,
        *Heap_Relocation, *Constant_Relocation;
@@ -119,10 +119,10 @@ prepare_dump_header(Buffer, Dumped_Object,
 }
 \f
 Boolean
-Write_File(Dumped_Object, Heap_Count, Heap_Relocation,
-           Constant_Count, Constant_Relocation,
-          table_start, table_length, table_size,
-          cc_code_p, band_p)
+Write_File (Dumped_Object, Heap_Count, Heap_Relocation,
+           Constant_Count, Constant_Relocation,
+           table_start, table_length, table_size,
+           cc_code_p, band_p)
      SCHEME_OBJECT
        *Dumped_Object,
        *Heap_Relocation, *Constant_Relocation,
@@ -133,12 +133,39 @@ Write_File(Dumped_Object, Heap_Count, Heap_Relocation,
      Boolean cc_code_p, band_p;
 {
   SCHEME_OBJECT Buffer[FASL_HEADER_LENGTH];
-
-  prepare_dump_header(Buffer, Dumped_Object,
-                     Heap_Count, Heap_Relocation,
-                     Constant_Count, Constant_Relocation,
-                     table_length, table_size, cc_code_p, band_p);
-  if (Write_Data(FASL_HEADER_LENGTH, ((char *) Buffer)) !=
+  unsigned long checksum, checksum_area ();
+
+  prepare_dump_header (Buffer, Dumped_Object,
+                      Heap_Count, Heap_Relocation,
+                      Constant_Count, Constant_Relocation,
+                      table_length, table_size, cc_code_p, band_p);
+
+  /* This is not done in prepare_dump_header because it doesn't
+     work when prepare_dump_header is invoked from bchdmp.
+     The areas don't really have these values.
+     For the time being, bchdmp does not dump checksums.
+   */
+
+  checksum = (checksum_area (((unsigned long *) (&Buffer[0])),
+                            ((long) FASL_Offset_Check_Sum),
+                            ((unsigned long) 0L)));
+  checksum = (checksum_area (((unsigned long *)
+                             (&Buffer[FASL_Offset_Check_Sum + 1])),
+                            ((long) ((FASL_HEADER_LENGTH - 1) -
+                                     FASL_Offset_Check_Sum)),
+                            checksum));
+  checksum = (checksum_area (((unsigned long *) Heap_Relocation),
+                            Heap_Count,
+                            checksum));
+  checksum = (checksum_area (((unsigned long *) Constant_Relocation),
+                            Constant_Count,
+                            checksum));
+  checksum = (checksum_area (((unsigned long *) table_start),
+                            table_size,
+                            checksum));
+  Buffer[FASL_Offset_Check_Sum] = checksum;
+
+  if (Write_Data (FASL_HEADER_LENGTH, ((char *) Buffer)) !=
       FASL_HEADER_LENGTH)
   {
     return (false);
@@ -168,3 +195,22 @@ Write_File(Dumped_Object, Heap_Count, Heap_Relocation,
   }
   return (true);
 }
+\f
+extern unsigned long checksum_area ();
+
+unsigned long
+checksum_area (start, count, initial_value)
+     register unsigned long *start;
+     register long count;
+     unsigned long initial_value;
+{
+  register unsigned long value;
+
+  value = initial_value;
+  while ((--count) >= 0)
+  {
+    value = (value ^ (*start++));
+  }
+  return (value);
+}
+     
index d710c75ce950372d0bcf4c00c0804792ec6a4134..f9f8ef68f661b13a9c242409b6e81cae9f751cfd 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/fasload.c,v 9.56 1990/08/16 23:36:51 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/fasload.c,v 9.57 1990/10/05 18:58:30 jinx Exp $
 
 Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology
 
@@ -156,12 +156,17 @@ static SCHEME_OBJECT *
 DEFUN_VOID (read_file_end)
 {
   SCHEME_OBJECT *table;
+  extern unsigned long checksum_area ();
 
   if ((Load_Data(Heap_Count, ((char *) Free))) != Heap_Count)
   {
     OS_channel_close_noerror (load_channel);
     signal_error_from_primitive (ERR_IO_ERROR);
   }
+  computed_checksum =
+    (checksum_area (((unsigned long *) Free),
+                   Heap_Count,
+                   computed_checksum));
   NORMALIZE_REGION(((char *) Free), Heap_Count);
   Free += Heap_Count;
 
@@ -170,6 +175,10 @@ DEFUN_VOID (read_file_end)
     OS_channel_close_noerror (load_channel);
     signal_error_from_primitive (ERR_IO_ERROR);
   }
+  computed_checksum =
+    (checksum_area (((unsigned long *) Free_Constant),
+                   Const_Count,
+                   computed_checksum));
   NORMALIZE_REGION(((char *) Free_Constant), Const_Count);
   Free_Constant += Const_Count;
 
@@ -180,10 +189,20 @@ DEFUN_VOID (read_file_end)
     OS_channel_close_noerror (load_channel);
     signal_error_from_primitive (ERR_IO_ERROR);
   }
+  computed_checksum =
+    (checksum_area (((unsigned long *) Free),
+                   Primitive_Table_Size,
+                   computed_checksum));
   NORMALIZE_REGION(((char *) table), Primitive_Table_Size);
   Free += Primitive_Table_Size;
 
   OS_channel_close_noerror (load_channel);
+
+  if ((computed_checksum != ((unsigned long) 0)) &&
+      (dumped_checksum != SHARP_F))
+  {
+    signal_error_from_primitive (ERR_IO_ERROR);
+  }
   return (table);
 }
 \f
index 8ccfc6b3f5d9114dbc403ca2bf72ada1527078e4..79e673cbb3d88b18429a3f630140420d6e375fa9 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/load.c,v 9.28 1989/09/20 23:09:52 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/load.c,v 9.29 1990/10/05 18:58:18 jinx Exp $
 
 Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology
 
@@ -74,54 +74,58 @@ static long
   Primitive_Table_Size, Primitive_Table_Length,
   dumped_processor_type, dumped_interface_version;
 
+static unsigned long
+  dumped_checksum, computed_checksum;
+
 static SCHEME_OBJECT
   Ext_Prim_Vector,
   dumped_utilities;
 \f
 void
-print_fasl_information()
+print_fasl_information ()
 {
-  printf("FASL File Information:\n\n");
-  printf("Machine = %ld; Version = %ld; Subversion = %ld\n",
-        Machine_Type, Version, Sub_Version);
+  printf ("FASL File Information:\n\n");
+  printf ("Machine = %ld; Version = %ld; Subversion = %ld\n",
+         Machine_Type, Version, Sub_Version);
   if ((dumped_processor_type != 0) || (dumped_interface_version != 0))
   {
-    printf("Compiled code interface version = %ld; Processor type = %ld\n",
-          dumped_interface_version, dumped_processor_type);
+    printf ("Compiled code interface version = %ld; Processor type = %ld\n",
+           dumped_interface_version, dumped_processor_type);
   }
   if (band_p)
   {
-    printf("The file contains a dumped image (band).\n");
+    printf ("The file contains a dumped image (band).\n");
   }
 
-  printf("\nRelocation Information:\n\n");
-  printf("Heap Count = %ld; Heap Base = 0x%lx; Heap Top = 0x%lx\n",
-        Heap_Count, Heap_Base, Dumped_Heap_Top);
-  printf("Const Count = %ld; Const Base = 0x%lx; Const Top = 0x%lx\n",
-        Const_Count, Const_Base, Dumped_Constant_Top);
-  printf("Stack Top = 0x%lx\n", Dumped_Stack_Top);
+  printf ("\nRelocation Information:\n\n");
+  printf ("Heap Count = %ld; Heap Base = 0x%lx; Heap Top = 0x%lx\n",
+         Heap_Count, Heap_Base, Dumped_Heap_Top);
+  printf ("Const Count = %ld; Const Base = 0x%lx; Const Top = 0x%lx\n",
+         Const_Count, Const_Base, Dumped_Constant_Top);
+  printf ("Stack Top = 0x%lx\n", Dumped_Stack_Top);
 
-  printf("\nDumped Objects:\n\n");
-  printf("Dumped object at 0x%lx (as read from file)\n", Dumped_Object);
-  printf("Compiled code utilities vector = 0x%lx\n", dumped_utilities);
+  printf ("\nDumped Objects:\n\n");
+  printf ("Dumped object at 0x%lx (as read from file)\n", Dumped_Object);
+  printf ("Compiled code utilities vector = 0x%lx\n", dumped_utilities);
   if (Ext_Prim_Vector != SHARP_F)
   {
-    printf("External primitives vector = 0x%lx\n", Ext_Prim_Vector);
+    printf ("External primitives vector = 0x%lx\n", Ext_Prim_Vector);
   }
   else
   {
-    printf("Length of primitive table = %ld\n", Primitive_Table_Length);
+    printf ("Length of primitive table = %ld\n", Primitive_Table_Length);
   }
+  printf ("Checksum = 0x%lx\n", dumped_checksum);
   return;
 }
 \f
 long
-Read_Header()
+Read_Header ()
 {
   SCHEME_OBJECT Buffer[FASL_HEADER_LENGTH];
   SCHEME_OBJECT Pointer_Heap_Base, Pointer_Const_Base;
 
-  if (Load_Data(FASL_HEADER_LENGTH, ((char *) Buffer)) !=
+  if (Load_Data (FASL_HEADER_LENGTH, ((char *) Buffer)) !=
       FASL_HEADER_LENGTH)
   {
     return (FASL_FILE_TOO_SHORT);
@@ -130,10 +134,10 @@ Read_Header()
   {
     return (FASL_FILE_NOT_FASL);
   }
-  NORMALIZE_HEADER(Buffer,
-                  (sizeof(Buffer) / sizeof(SCHEME_OBJECT)),
-                  Buffer[FASL_Offset_Heap_Base],
-                  Buffer[FASL_Offset_Heap_Count]);
+  NORMALIZE_HEADER (Buffer,
+                   (sizeof(Buffer) / sizeof(SCHEME_OBJECT)),
+                   Buffer[FASL_Offset_Heap_Base],
+                   Buffer[FASL_Offset_Heap_Count]);
   Heap_Count = OBJECT_DATUM (Buffer[FASL_Offset_Heap_Count]);
   Pointer_Heap_Base = Buffer[FASL_Offset_Heap_Base];
   Heap_Base = OBJECT_DATUM (Pointer_Heap_Base);
@@ -185,7 +189,6 @@ Read_Header()
   }
 \f
 #ifndef INHIBIT_FASL_VERSION_CHECK
-
   /* The error messages here should be handled by the runtime system! */
 
   if ((Version != FASL_READ_VERSION) ||
@@ -224,13 +227,13 @@ Read_Header()
        ((dumped_interface_version != 0) &&
         (dumped_interface_version != compiler_interface_version)))
     {
-      fprintf(stderr, "\nread_file:\n");
-      fprintf(stderr,
-             "FASL File: compiled code interface %4d; processor %4d.\n",
-             dumped_interface_version, dumped_processor_type);
-      fprintf(stderr,
-             "Expected:  compiled code interface %4d; processor %4d.\n",
-             compiler_interface_version, compiler_processor_type);
+      fprintf (stderr, "\nread_file:\n");
+      fprintf (stderr,
+              "FASL File: compiled code interface %4d; processor %4d.\n",
+              dumped_interface_version, dumped_processor_type);
+      fprintf (stderr,
+              "Expected:  compiled code interface %4d; processor %4d.\n",
+              compiler_interface_version, compiler_processor_type);
       return (((dumped_processor_type != 0) &&
               (dumped_processor_type != compiler_processor_type))      ?
              FASL_FILE_BAD_PROCESSOR                                   :
@@ -240,6 +243,22 @@ Read_Header()
 
 #endif /* INHIBIT_COMPILED_VERSION_CHECK */
 
+  dumped_checksum = (Buffer [FASL_Offset_Check_Sum]);
+
+#ifndef INHIBIT_CHECKSUMS
+
+  {
+    extern unsigned long checksum_area ();
+
+    computed_checksum =
+      (checksum_area (((unsigned long *) &Buffer[0]),
+                     ((unsigned long) (FASL_HEADER_LENGTH)),
+                     ((unsigned long) 0)));
+
+  }
+
+#endif /* INHIBIT_CHECKSUMS */
+
   return (FASL_FILE_FINE);
 }
 \f