File: m-model.c

package info (click to toggle)
swi-prolog 3.1.0-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 8,772 kB
  • ctags: 12,869
  • sloc: ansic: 43,657; perl: 12,577; lisp: 4,359; sh: 1,534; makefile: 798; awk: 14
file content (87 lines) | stat: -rw-r--r-- 2,177 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*  $Id: m-model.c,v 1.4 1993/04/28 15:25:01 jan Exp $

    Copyright (c) 1991 Jan Wielemaker. All rights reserved.
    jan@swi.psy.uva.nl

    Purpose: Determine machines memory-model
*/

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This program   was written  to  determine the  memory  model   of your
machine.  It may be used when writing a new md-machine.h file.

Compile this file using:

	% cc -o m-model m-model.c
	% ./m-model
	Memory layout:

		Text at 0x2290
		Global variable at 0x40d0
		Local variable at 0xeffff938
		malloc() at 0x61a0
		C-Stack grows Downward

	No special declarations needed in "md.h"

	%
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#include <stdio.h>

#define K * 1024
#define MAX_DECL 100

int	global_var;

char *
sub()
{ char buf[10];

  return buf;
}

main(argc, argv)
int argc;
char *argv[];
{ char buf[10];
  unsigned long gva = (unsigned long) &global_var;
  int stack_up = (sub() > buf);
  char *decl[MAX_DECL];
  int ndecl = 0;

  printf("Memory layout:\n\n");
  printf("\tText at 0x%x\n", sub);
  printf("\tGlobal variable at 0x%x\n", gva);
  printf("\tLocal variable at 0x%x\n", buf);
  printf("\tmalloc() at 0x%x\n", malloc(10));
  printf("\tC-Stack grows %sward\n", stack_up ? "Up" : "Down");
	 
  if      ( (gva & 0xf0000000L) == 0x40000000L )
    decl[ndecl++] = "#define O_DATA_AT_0X4	1";
  else if ( (gva & 0xf0000000L) == 0x20000000L )
    decl[ndecl++] = "#define O_DATA_AT_0X2	1";
  else if ( (gva & 0xf0000000L) == 0x10000000L )
    decl[ndecl++] = "#define O_DATA_AT_0X1	1";
  else if ( (gva & 0xf0000000L) )
    printf("PROBLEM: Memory model not supported; see \"pl-incl.h\"\n");
  
  if ( stack_up )
    decl[ndecl++] = "#define O_C_STACK_GROWS_UP	1";
  if ( (long) sub > 64 K )
    decl[ndecl++] = "#define O_VMCODE_IS_ADDRESS 0";

  if ( !malloc(200000) )
    printf("PROBLEM: malloc(200000) fails; see \"pl-os.c\"\n");

  if ( ndecl > 0 )
  { int n;

    printf("\nRequired declarations in \"md.h\":\n\n");
    for(n=0; n<ndecl; n++)
      printf("%s\n", decl[n]);
  } else
    printf("\nNo special declarations needed in \"md.h\"\n\n");

  exit(0);
}