OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [dejagnu/] [testglue.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#include <stdio.h>
2
#include <string.h>
3
#ifndef NO_UNISTD_H
4
#include <sys/unistd.h>
5
#endif
6
 
7
/* A simple glue file for embedded targets so we can get the real exit
8
   status from the program. This assumes we're using GNU ld and can use
9
   the -wrap option, and that write(1, ...) does something useful. */
10
 
11
/* There is a bunch of weird cruft with #ifdef UNDERSCORES. This is needed
12
   because currently GNU ld doesn't deal well with a.out targets and
13
   the -wrap option. When GNU ld is fixed, this should definitely be
14
   removed. Note that we actually wrap __exit, not _exit on a target
15
   that has UNDERSCORES defined. */
16
 
17
#ifdef WRAP_M68K_AOUT
18
#define REAL_EXIT(code) asm ( "trap %0" : : "i" (0) );
19
#define REAL_ABORT() REAL_EXIT(6)
20
#define ORIG_EXIT _exit
21
#define ORIG_ABORT abort
22
#else
23
#ifdef UNDERSCORES
24
#define REAL_EXIT _real___exit
25
#define REAL_MAIN _real__main
26
#define REAL_ABORT _real__abort
27
#define ORIG_EXIT _wrap___exit
28
#define ORIG_ABORT _wrap__abort
29
#define ORIG_MAIN _wrap__main
30
#else
31
#define REAL_EXIT __real_exit
32
#define REAL_MAIN __real_main
33
#define REAL_ABORT __real_abort
34
#define ORIG_EXIT __wrap_exit
35
#define ORIG_ABORT __wrap_abort
36
#define ORIG_MAIN __wrap_main
37
#endif
38
#endif
39
 
40
#ifdef REAL_MAIN
41
extern void REAL_EXIT ();
42
extern void REAL_ABORT ();
43
extern int REAL_MAIN (int argc, char **argv, char **envp);
44
#endif
45
 
46
int ___constval = 1;
47
 
48
#ifdef VXWORKS
49
static void __runexit();
50
#endif
51
 
52
static char *
53
write_int(val, ptr)
54
     int val;
55
     char *ptr;
56
{
57
  char c;
58
  if (val<0) {
59
    *(ptr++) = '-';
60
    val = -val;
61
  }
62
  if (val>9) {
63
    ptr = write_int (val/10, ptr);
64
  }
65
  c = (val%10)+'0';
66
  *(ptr++) = c;
67
  return ptr;
68
}
69
 
70
void
71
ORIG_EXIT (code)
72
     int code;
73
{
74
  char buf[30];
75
  char *ptr;
76
 
77
#ifdef VXWORKS
78
  __runexit ();
79
#endif
80
  strcpy (buf, "\n*** EXIT code ");
81
  ptr = write_int (code, buf + strlen(buf));
82
  *(ptr++) = '\n';
83
  write (1, buf, ptr-buf);
84
  REAL_EXIT (code);
85
  while (___constval);
86
}
87
 
88
void
89
ORIG_ABORT ()
90
{
91
  write (1, "\n*** EXIT code 4242\n", 20);
92
  REAL_ABORT ();
93
  while (___constval);
94
  abort ();
95
}
96
 
97
#ifdef REAL_MAIN
98
int
99
ORIG_MAIN (argc, argv, envp)
100
     int argc;
101
     char **argv;
102
     char **envp;
103
{
104
#ifdef WRAP_FILE_ARGS
105
  extern int __argc;
106
  extern char *__args[];
107
 
108
  exit (REAL_MAIN (__argc,__args,envp));
109
#else
110
  exit (REAL_MAIN (argc, argv, envp));
111
#endif
112
  while (___constval);
113
}
114
#endif
115
 
116
#ifdef VXWORKS
117
void
118
_exit (status)
119
     int status;
120
{
121
  REAL_EXIT (status);
122
}
123
 
124
typedef (*PFV)(void);
125
 
126
static PFV __list[32];
127
static int __listcnt = 0;
128
static int __running = 0;
129
 
130
int
131
atexit (PFV func)
132
{
133
  __list[__listcnt++] = func;
134
}
135
 
136
static void
137
__runexit ()
138
{
139
  int i;
140
  if (__running++)
141
    return;
142
 
143
  for (i = 0; i < __listcnt; i++)
144
    __list[i]();
145
  __running = 0;
146
}
147
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.