home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / assembly / hdw3_s / checkout.c next >
Encoding:
C/C++ Source or Header  |  1991-09-26  |  2.0 KB  |  90 lines

  1. static char *rcsid = "$Id: checkout.c,v 1.2 1991/09/17 15:12:12 mario Exp $";
  2.  
  3. /* $Log: checkout.c,v $
  4.  * Revision 1.2  1991/09/17  15:12:12  mario
  5.  * Let the header be done by the assembler.
  6.  *
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <tos.h>
  12.  
  13. #define    IMAGE        "hdw3.tos"
  14.  
  15. #define    SIZE        8096L
  16. #define    SECSIZE        512
  17.  
  18. void main(void)
  19. {
  20.     char *text_p;
  21.     int i, copy_image=1;
  22.     BASPAG *baspag;
  23.     unsigned char *buffer;
  24. #if !defined(WR)
  25.     void (*funct)(void);
  26. #endif
  27. #if defined(R_CHECK)
  28.     int fd;
  29.     size_t rbytes;
  30.     char *ram;
  31. #endif
  32.     
  33.     buffer = malloc(SECSIZE);
  34. #if defined(R_CHECK)
  35.     /* For tests if relocation errors occurr */
  36.     ram = malloc(SIZE);
  37.     
  38.     if ((fd = open(IMAGE, O_RDONLY)) < 0) {
  39.         fputs("Open error", stderr);
  40.         exit(1);
  41.     }
  42.     
  43.     rbytes = read(fd, ram, SIZE);
  44.  
  45.     fprintf(stdout, "Read %ld Bytes\n", rbytes);
  46. #endif
  47.     /* Tends to fail, if the image has to be relocated
  48.        Debug/trace this on "ram" (with R_CHECK defined) */
  49.     baspag = (BASPAG *)Pexec(3, IMAGE, NULL, NULL);
  50.     if ((long)baspag < 0) {
  51.         if ((long)baspag == -33) {    /* Not found */
  52.             copy_image = 0;
  53.         } else {
  54.             fprintf(stderr, "Pexec failed\n");
  55.         }
  56.     }
  57. #if !defined(WR)
  58.     funct = baspag->p_tbase;
  59. #endif
  60.     Rwabs(2, buffer, 1, 0, 0);
  61.  
  62.     if (copy_image) {
  63.         text_p = baspag->p_tbase;
  64.         if (baspag->p_dlen) {
  65.             fprintf(stderr, "Warning! Data segment should not contain data\n");
  66.         }
  67.         if (baspag->p_tlen+2 > SECSIZE) {
  68.             fprintf(stderr, "Program too big for bootsector\n");
  69.             exit(1);
  70.         }
  71.         for (i=0; i<8; i++) buffer[i] = text_p[i];
  72.         for (i=0x1e; i<(baspag->p_tlen); i++) buffer[i] = text_p[i];
  73.     } else {
  74.         fprintf(stderr, "No bootsector image %s!\n", IMAGE);
  75.         fprintf(stderr, "Adjusting checksum to executable\n");
  76.     }
  77.     Protobt(buffer, -1, -1, 1);
  78. #if defined(WR)
  79.     Rwabs(3, buffer, 1, 0, 0);
  80. #else
  81.     /* expect bootsector to be executed in supervisor mode */
  82.     Super(0L);
  83.     (*funct)();    /* Check it out with debugger */
  84.     /* Registers might be lost, just exit now! */
  85. #endif
  86.     exit(0);
  87. }
  88.  
  89. #pragma warn -use
  90.