summaryrefslogtreecommitdiffstats
path: root/tools/cpu/unix/gensize.c
blob: 2d848e0a942d364c1ca5fc11d2240b9daa8e9ccf (plain) (blame)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *  gensize.c
 *
 *  This file generates the file unixsize.h
 *
 *  NOTE:  It only prints the minimal information required.
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 *
 */

/* 
 *  This feels like a very crude way to determine if we are on a Solaris
 *  host but it does work.
 */

#if defined(__sun__) && defined(__sparc__) && \
    defined(__unix__) && defined(__svr4__)
#undef  _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 3
#undef  __STRICT_ANSI__
#endif

#include <stdio.h>
#include <unistd.h>
#include <setjmp.h>
#include <signal.h>

typedef struct {
  jmp_buf     regs;
  int         isr_level;
  int         pad[4]; /* just in case */
} Context_Control;

int main(
  int argc,
  char **argv
)
{
  Context_Control *cc = 0;

  /*
   * Print the file header
   */

printf(
  "/*  unixsize.h\n"
  " *\n"
  " *  This include file contans the size of the context control block\n"
  " *  C data structure.  This structure must be defined in such a way\n"
  " *  that files NOT including the native header files can work.\n"
  " *\n"
  " *  NOTE:  THIS FILE IS AUTOMATICALLY GENERATED!!!!\n"
  " *         DO NOT EDIT THIS BY HAND!!!!\n"
  " *\n"
  " *  COPYRIGHT (c) 1989-1999.\n"
  " *  On-Line Applications Research Corporation (OAR).\n"
  " *\n"
  " *  The license and distribution terms for this file may be\n"
  " *  found in the file LICENSE in this distribution or at\n"
  " *  http://www.OARcorp.com/rtems/license.html.\n"
  " */\n"
  "\n"
  "#ifndef __UNIXSIZE_h\n"
  "#define __UNIXSIZE_h\n"
  "\n"
);

#define PRINT_IT( STRING, NUMBER ) \
  printf( "#define\t%s\t0x%x\t\t/* %d */\n", \
          STRING, \
          NUMBER, \
          NUMBER );

#define PRINT_SIZE( STRING, NUMBER ) \
  printf( "#define\t%s\t0x%x\t\t/* %d */\n", \
          STRING, \
          NUMBER, \
          NUMBER );

#define PRINT_COMMENT( STRING ) \
  printf(       \
    "\n"        \
    "/*\n"      \
    " * " STRING "\n" \
    " */\n"     \
    "\n"        \
  );

  PRINT_COMMENT("Context_Control information");

  PRINT_SIZE("CPU_CONTEXT_SIZE_IN_BYTES", sizeof( Context_Control ) );
  PRINT_SIZE("CPU_CONTEXT_REGISTERS_OFFSET_IN_BYTES", (int) &cc->regs );
  PRINT_SIZE("CPU_CONTEXT_SIGNALS_OFFSET_IN_BYTES", (int) &cc->isr_level );

  /*
   *  Print the end of file stuff
   */

   printf(
    "\n"
    "#endif    /* __UNIXSIZE_h  */\n"
    "\n"
    "/* end of include file */\n"
  );

  return 0;
}