home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plbin.zip / pl / src / m-model.c < prev    next >
C/C++ Source or Header  |  1993-02-08  |  2KB  |  88 lines

  1. /*  m-model.c,v 1.2 1993/02/08 11:01:44 jan Exp
  2.  
  3.     Copyright (c) 1991 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Determine machines memory-model
  7. */
  8.  
  9. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  10. This program   was written  to  determine the  memory  model   of your
  11. machine.  It may be used when writing a new md-machine.h file.
  12.  
  13. Compile this file using:
  14.  
  15.     % cc -o m-model m-model.c
  16.     % ./m-model
  17.     Memory layout:
  18.  
  19.         Text at 0x2290
  20.         Global variable at 0x40d0
  21.         Local variable at 0xeffff938
  22.         malloc() at 0x61a0
  23.         C-Stack grows Downward
  24.  
  25.     No special declarations needed in "md.h"
  26.  
  27.     %
  28. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  29.  
  30. #include <stdio.h>
  31.  
  32. #define K * 1024
  33. #define MAX_DECL 100
  34.  
  35. int    global_var;
  36.  
  37. char *
  38. sub()
  39. { char buf[10];
  40.  
  41.   return buf;
  42. }
  43.  
  44. main(argc, argv)
  45. int argc;
  46. char *argv[];
  47. { char buf[10];
  48.   unsigned long gva = (unsigned long) &global_var;
  49.   int stack_up = (sub() > buf);
  50.   char *decl[MAX_DECL];
  51.   int ndecl = 0;
  52.  
  53.   printf("Memory layout:\n\n");
  54.   printf("\tText at 0x%x\n", sub);
  55.   printf("\tGlobal variable at 0x%x\n", gva);
  56.   printf("\tLocal variable at 0x%x\n", buf);
  57.   printf("\tmalloc() at 0x%x\n", malloc(10));
  58.   printf("\tC-Stack grows %sward\n", stack_up ? "Up" : "Down");
  59.      
  60.   if      ( (gva & 0xf0000000L) == 0x40000000L )
  61.     decl[ndecl++] = "#define O_DATA_AT_0X4    1";
  62.   else if ( (gva & 0xf0000000L) == 0x20000000L )
  63.     decl[ndecl++] = "#define O_DATA_AT_0X2    1";
  64.   else if ( (gva & 0xf0000000L) == 0x10000000L )
  65.     decl[ndecl++] = "#define O_DATA_AT_0X1    1";
  66.   else if ( (gva & 0xf0000000L) )
  67.     printf("PROBLEM: Memory model not supported; see \"pl-incl.h\"\n");
  68.   
  69.   if ( stack_up )
  70.     decl[ndecl++] = "#define O_C_STACK_GROWS_UP    1";
  71.   if ( (long) sub > 64 K )
  72.     decl[ndecl++] = "#define O_VMCODE_IS_ADDRESS 0";
  73.  
  74.   if ( !malloc(200000) )
  75.     printf("PROBLEM: malloc(200000) fails; see \"pl-os.c\"\n");
  76.  
  77.   if ( ndecl > 0 )
  78.   { int n;
  79.  
  80.     printf("\nRequired declarations in \"md.h\":\n\n");
  81.     for(n=0; n<ndecl; n++)
  82.       printf("%s\n", decl[n]);
  83.   } else
  84.     printf("\nNo special declarations needed in \"md.h\"\n\n");
  85.  
  86.   exit(0);
  87. }
  88.